Skip to content
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
12 changes: 11 additions & 1 deletion babel.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
module.exports = {
presets: [['@babel/preset-env', { targets: { node: 'current' } }]],
presets: [
['@babel/preset-env', {
targets: { node: 'current' },
}],
],
plugins: [
['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
30 changes: 30 additions & 0 deletions next/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,33 @@ 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.

## Node.js Version

This project requires Node.js LTS v22.13.1.
We recommend using the exact version specified in `.nvmrc`:

Navigate to the "next" folder and run:

```bash
nvm use
```

Without the correct Node.js version,
tests and other development tasks will likely fail.
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
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,
Copy link
Collaborator

Choose a reason for hiding this comment

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

praise: This entire PR is very smart, TIL about this for moduleNameMapper 💡 💡 💡

}

export default config
12 changes: 12 additions & 0 deletions next/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,25 @@
"form"
],
"main": "index.js",
"engines": {
"node": "22.13.1"
},
"scripts": {
"test": "jest",
"test:watch": "jest --watchAll",
"test:file": "jest --runTestsByPath",
"lint": "eslint --max-warnings 0 .",
"build": "tsup"
},
"devDependencies": {
"@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",
"tsup": "^8.3.5",
"typescript": "^5.7.3"
}
Expand Down
Loading
Loading