Skip to content

Commit

Permalink
Create Jest project for turbopack
Browse files Browse the repository at this point in the history
This allows running a tests for both bundlers via
`pnpm test-dev test/e2e/app --projects jest.config.*`.

Ideally, we'd have a `test-dev-all` shortcut.
However, we can't add the test files after the `--projects`
flag since it's now ambigious whether you specified
a test or project config. So the `--projects` flag
must come after the specified test making an NPM script
using `--projects` impossible.
  • Loading branch information
eps1lon committed Dec 10, 2024
1 parent 09aa303 commit 8160e56
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 0 deletions.
6 changes: 6 additions & 0 deletions contributing/core/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,12 @@ To run the test suite using Turbopack, you can use the `TURBOPACK=1` environment
TURBOPACK=1 pnpm test-dev test/e2e/app-dir/app/
```

If you want to run a test again both Turbopack and Webpack, use Jest's `--projects` flag:

```sh
pnpm test-dev test/e2e/app-dir/app/ --projects jest.config.*
```

## Integration testing outside the repository with local builds

You can locally generate tarballs for each package in this repository with:
Expand Down
1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const createJestConfig = nextJest()
// Any custom config you want to pass to Jest
/** @type {import('jest').Config} */
const customJestConfig = {
displayName: 'default',
testMatch: ['**/*.test.js', '**/*.test.ts', '**/*.test.jsx', '**/*.test.tsx'],
setupFilesAfterEnv: ['<rootDir>/jest-setup-after-env.ts'],
verbose: true,
Expand Down
16 changes: 16 additions & 0 deletions jest.config.turbopack.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const createJestDefaultConfig = require('./jest.config.js')

module.exports = async function createConfig() {
const jestDefaultConfig = await createJestDefaultConfig()
/** @type {import('jest').Config} */
const customConfig = {
...jestDefaultConfig,
displayName: 'Turbopack',
setupFiles: [
...(jestDefaultConfig.setupFiles ?? []),
'<rootDir>/jest-setup-files.turbopack.js',
],
}

return customConfig
}
1 change: 1 addition & 0 deletions test/jest-setup-files.turbopack.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
process.env.TURBOPACK = '1'

0 comments on commit 8160e56

Please sign in to comment.