Skip to content

Commit

Permalink
build(next): Simplify test setup (#112)
Browse files Browse the repository at this point in the history
* Fix

* Update jest.config.js

* Update babel.config.js

* chore: add default node version

---------

Co-authored-by: David Dragovacz <[email protected]>
  • Loading branch information
thien-remote and dragidavid authored Jan 22, 2025
1 parent 42b2b13 commit 858df6a
Show file tree
Hide file tree
Showing 13 changed files with 276 additions and 553 deletions.
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
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

0 comments on commit 858df6a

Please sign in to comment.