Skip to content

Commit 858df6a

Browse files
build(next): Simplify test setup (#112)
* Fix * Update jest.config.js * Update babel.config.js * chore: add default node version --------- Co-authored-by: David Dragovacz <[email protected]>
1 parent 42b2b13 commit 858df6a

File tree

13 files changed

+276
-553
lines changed

13 files changed

+276
-553
lines changed

babel.config.js

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,13 @@
11
module.exports = {
22
presets: [
3-
[
4-
'@babel/preset-env',
5-
{
6-
targets: {
7-
node: 'current',
8-
},
9-
},
10-
],
3+
['@babel/preset-env', {
4+
targets: { node: 'current' },
5+
}],
116
],
127
plugins: [
13-
[
14-
'module-resolver',
15-
{
16-
root: ['./src'],
17-
alias: {
18-
'@': './src',
19-
},
20-
},
21-
],
8+
['module-resolver', {
9+
root: ['./src'],
10+
alias: { '@': './src' },
11+
}],
2212
],
2313
};

jest.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@ module.exports = async () => {
22
return {
33
verbose: true,
44
testEnvironment: 'jsdom',
5+
testPathIgnorePatterns: ['/next/test'],
56
};
67
};

next/.nvmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
22.13.1

next/README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,18 @@ This `next/` folder is where the rewriting is happening
99
We expect the main `createHeadlessForm()` API to remain the same,
1010
avoiding any major breaking change.
1111
This is under active development, more info soon!
12+
13+
## Development
14+
15+
Ensure that you isolate your workspace to the "next" folder only.
16+
This means:
17+
1. In your editor, open only the "next" folder.
18+
1. In your terminal, run commands when you are in the "next" folder only.
19+
20+
Otherwise, your editor may fail to set up linting and type checking,
21+
while your terminal may fail to resolve paths.
22+
23+
The limitation of this approach is that
24+
your editor will fail to recognise our git repository here.
25+
This also means you should turn off the editor's suggestion
26+
to open git repository at root.

next/babel.config.mjs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**
2+
* @type {import('@babel/core').TransformOptions}
3+
*/
4+
const options = {
5+
presets: [
6+
['@babel/preset-env', { targets: { node: 'current' } }],
7+
// Type checking is already done in our build,
8+
// so we can use a lightweight preset.
9+
// - https://jestjs.io/docs/getting-started#using-typescript
10+
'@babel/preset-typescript',
11+
],
12+
}
13+
14+
export default options

next/jest.config.js

Lines changed: 0 additions & 30 deletions
This file was deleted.

next/jest.config.mjs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/**
2+
* This next version of JSON Schema Form ("V2")
3+
* must be tested against 2 sets ("root") of tests.
4+
* Note that "rootDir" is the path to this next version.
5+
*
6+
* @type {import('jest').Config['roots']}
7+
*/
8+
const roots = [
9+
// 1. The existing tests from the previous version ("V1")
10+
'<rootDir>/../src/tests',
11+
// 2. The new tests for this version
12+
'<rootDir>/test',
13+
]
14+
15+
/**
16+
* Module aliases to use the same test with different source versions.
17+
* To learn more, see "roots" above.
18+
*
19+
* This is only needed to use V1 tests for V2 source.
20+
* as V2 tests are used to test V2 source only.
21+
*
22+
* @type {import('jest').Config['moduleNameMapper']}
23+
*/
24+
const moduleNameMapper = {
25+
// We use kebab-case in V2
26+
'^@/createHeadlessForm$': '<rootDir>/src/form',
27+
'^@/utils$': '<rootDir>/src/utils',
28+
// Avoid catch all aliases such as "^@/(.*)$".
29+
// Aliases should be added as needed.
30+
// If there are many, we will have a compat barrel file.
31+
}
32+
33+
/**
34+
* Some tests are invalid for V2 testing.
35+
* For example:
36+
* - Buggy behaviours in V1 that are already fixed (and tested) in V2
37+
* - Deprecated or removed APIs
38+
*
39+
* @type {import('jest').Config['testPathIgnorePatterns']}
40+
*/
41+
const testPathIgnorePatterns = [
42+
// Nothing yet
43+
]
44+
45+
/** @type {import('jest').Config} */
46+
const config = {
47+
roots,
48+
moduleNameMapper,
49+
testPathIgnorePatterns,
50+
}
51+
52+
export default config

next/package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
"form"
1818
],
1919
"main": "index.js",
20+
"engines": {
21+
"node": "22.13.1"
22+
},
2023
"scripts": {
2124
"test": "jest",
2225
"test:watch": "jest --watchAll",
@@ -27,11 +30,11 @@
2730
"@antfu/eslint-config": "^3.14.0",
2831
"@babel/core": "^7.23.7",
2932
"@babel/preset-env": "^7.23.7",
33+
"@babel/preset-typescript": "^7.26.0",
34+
"@jest/globals": "^29.7.0",
3035
"babel-jest": "^29.7.0",
3136
"eslint": "^9.18.0",
3237
"jest": "^29.7.0",
33-
"jest-environment-jsdom": "^29.7.0",
34-
"ts-jest": "^29.1.1",
3538
"tsup": "^8.3.5",
3639
"typescript": "^5.7.3"
3740
}

0 commit comments

Comments
 (0)