Skip to content

Commit ded7a32

Browse files
Merge pull request #1222 from nhsuk/es-modules-tests
Migrate to ES modules: Tests
2 parents 4a098ba + 05646d9 commit ded7a32

13 files changed

Lines changed: 30 additions & 6 deletions

jest.config.js

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,27 @@ const jestPuppeteerConfig = require('./jest-puppeteer.config.js')
44
const { headless = true } = jestPuppeteerConfig.launch
55

66
/**
7+
* Jest project config defaults
8+
*
9+
* @type {ProjectConfig}
10+
*/
11+
const config = {
12+
cacheDirectory: '<rootDir>/.cache/jest',
13+
14+
// Enable Babel transforms until Jest supports ESM and `import()`
15+
// See: https://jestjs.io/docs/ecmascript-modules
16+
transform: {
17+
'^.+\\.(js|mjs)$': ['babel-jest', { rootMode: 'upward' }]
18+
}
19+
}
20+
21+
/**
22+
* Jest config
23+
*
724
* @type {Config}
825
*/
926
module.exports = {
10-
collectCoverageFrom: ['packages/**/*.js'],
27+
collectCoverageFrom: ['packages/**/*.{js,mjs}'],
1128

1229
// Reduce CPU usage during project test runs
1330
maxWorkers: headless
@@ -16,17 +33,21 @@ module.exports = {
1633

1734
projects: [
1835
{
36+
...config,
1937
displayName: 'JSDom',
2038
testEnvironment: 'jsdom',
21-
testMatch: ['<rootDir>/tests/integration/jsdom/**/*.test.js']
39+
testMatch: ['<rootDir>/tests/integration/jsdom/**/*.test.{js,mjs}']
2240
},
2341
{
42+
...config,
2443
displayName: 'Pupppeteer',
44+
testEnvironment: 'jest-environment-puppeteer',
45+
testMatch: ['<rootDir>/tests/integration/puppeteer/**/*.test.{js,mjs}'],
46+
47+
// Web server and browser required
2548
globalSetup: 'jest-environment-puppeteer/setup',
2649
globalTeardown:
27-
'<rootDir>/tests/integration/puppeteer/environment/teardown.mjs',
28-
testEnvironment: 'jest-environment-puppeteer',
29-
testMatch: ['<rootDir>/tests/integration/puppeteer/**/*.test.js']
50+
'<rootDir>/tests/integration/puppeteer/environment/teardown.mjs'
3051
}
3152
],
3253

@@ -38,5 +59,5 @@ module.exports = {
3859
}
3960

4061
/**
41-
* @import { Config } from 'jest'
62+
* @import { Config, ProjectConfig } from 'jest'
4263
*/

package-lock.json

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
"@babel/eslint-parser": "^7.27.0",
3535
"@babel/preset-env": "^7.26.9",
3636
"autoprefixer": "^10.4.21",
37+
"babel-jest": "^29.7.0",
3738
"babel-loader": "^10.0.0",
3839
"backstopjs": "^6.3.25",
3940
"browser-sync": "^3.0.4",
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)