Skip to content

build(next): Simplify test setup #112

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 7 additions & 17 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,13 @@
module.exports = {
presets: [
[
'@babel/preset-env',
{
targets: {
node: 'current',
},
},
],
['@babel/preset-env', {
targets: { node: 'current' },
}],
],
plugins: [
[
'module-resolver',
{
root: ['./src'],
alias: {
'@': './src',
},
},
],
['module-resolver', {
root: ['./src'],
alias: { '@': './src' },
}],
],
};
1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ module.exports = async () => {
return {
verbose: true,
testEnvironment: 'jsdom',
testPathIgnorePatterns: ['/next/test'],
};
};
1 change: 1 addition & 0 deletions next/.nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
22.13.1
Copy link
Collaborator Author

@thien-remote thien-remote Jan 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you want to keep this @dragidavid ? It's a really long story, but usually I'd suggest to just have one reference, to reduce the risk of out-of-sync in the future 🤔

Not big enough to be a change request though. Could be convenient for folks with NVM, which at the moment is Remote's default setup.

15 changes: 15 additions & 0 deletions next/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,18 @@ This `next/` folder is where the rewriting is happening
We expect the main `createHeadlessForm()` API to remain the same,
avoiding any major breaking change.
This is under active development, more info soon!

## Development

Ensure that you isolate your workspace to the "next" folder only.
This means:
1. In your editor, open only the "next" folder.
1. In your terminal, run commands when you are in the "next" folder only.

Otherwise, your editor may fail to set up linting and type checking,
while your terminal may fail to resolve paths.

The limitation of this approach is that
your editor will fail to recognise our git repository here.
This also means you should turn off the editor's suggestion
to open git repository at root.
14 changes: 14 additions & 0 deletions next/babel.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* @type {import('@babel/core').TransformOptions}
*/
const options = {
presets: [
['@babel/preset-env', { targets: { node: 'current' } }],
// Type checking is already done in our build,
// so we can use a lightweight preset.
// - https://jestjs.io/docs/getting-started#using-typescript
'@babel/preset-typescript',
],
}

export default options
30 changes: 0 additions & 30 deletions next/jest.config.js

This file was deleted.

52 changes: 52 additions & 0 deletions next/jest.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/**
* This next version of JSON Schema Form ("V2")
* must be tested against 2 sets ("root") of tests.
* Note that "rootDir" is the path to this next version.
*
* @type {import('jest').Config['roots']}
*/
const roots = [
// 1. The existing tests from the previous version ("V1")
'<rootDir>/../src/tests',
// 2. The new tests for this version
'<rootDir>/test',
]

/**
* Module aliases to use the same test with different source versions.
* To learn more, see "roots" above.
*
* This is only needed to use V1 tests for V2 source.
* as V2 tests are used to test V2 source only.
*
* @type {import('jest').Config['moduleNameMapper']}
*/
const moduleNameMapper = {
// We use kebab-case in V2
'^@/createHeadlessForm$': '<rootDir>/src/form',
'^@/utils$': '<rootDir>/src/utils',
// Avoid catch all aliases such as "^@/(.*)$".
// Aliases should be added as needed.
// If there are many, we will have a compat barrel file.
}

/**
* Some tests are invalid for V2 testing.
* For example:
* - Buggy behaviours in V1 that are already fixed (and tested) in V2
* - Deprecated or removed APIs
*
* @type {import('jest').Config['testPathIgnorePatterns']}
*/
const testPathIgnorePatterns = [
// Nothing yet
]

/** @type {import('jest').Config} */
const config = {
roots,
moduleNameMapper,
testPathIgnorePatterns,
}

export default config
7 changes: 5 additions & 2 deletions next/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
"form"
],
"main": "index.js",
"engines": {
"node": "22.13.1"
},
"scripts": {
"test": "jest",
"test:watch": "jest --watchAll",
Expand All @@ -27,11 +30,11 @@
"@antfu/eslint-config": "^3.14.0",
"@babel/core": "^7.23.7",
"@babel/preset-env": "^7.23.7",
"@babel/preset-typescript": "^7.26.0",
"@jest/globals": "^29.7.0",
"babel-jest": "^29.7.0",
"eslint": "^9.18.0",
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.7.0",
"ts-jest": "^29.1.1",
"tsup": "^8.3.5",
"typescript": "^5.7.3"
}
Expand Down
Loading
Loading