Skip to content

Commit 01dadec

Browse files
committed
feat(scripts/test): upgrade Jest to 29.x
BREAKING CHANGE: upgrades Jest a major version (28 to 29) BREAKING CHANGE: Node 12 is no longer supported
1 parent 9e87c79 commit 01dadec

File tree

5 files changed

+503
-365
lines changed

5 files changed

+503
-365
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929
if: ${{ needs.deduplicate.outputs.should_skip != 'true' }}
3030
strategy:
3131
matrix:
32-
node: ['12', '14', '16']
32+
node: ['14', '16', '18']
3333

3434
steps:
3535
- name: Get Yarn cache path

jest.config.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const {
22
globals,
3+
transform,
34
transformIgnorePatterns,
45
...config
56
} = require('./src/config/jest.config')
@@ -10,14 +11,13 @@ module.exports = {
1011
roots: ['<rootDir>/src'],
1112
coverageThreshold: null,
1213
transformIgnorePatterns: [...transformIgnorePatterns, '.prettierrc.js'],
13-
globals: {
14-
'ts-jest': {
15-
...globals['ts-jest'],
16-
tsconfig: './src/tsconfig.json',
17-
diagnostics: {
18-
warnOnly: true,
19-
exclude: ['**/*'],
20-
},
21-
},
22-
},
14+
// Specifying ts-jest options via `global` in Jest configuration has been
15+
// deprecated so we have to do this in order to add the `exclude` option to
16+
// the transform in our Jest configuration that already has `transform` ☹
17+
transform: Object.fromEntries(
18+
Object.entries(transform).map(([glob, [transformer, options]]) => [
19+
glob,
20+
[transformer, {...options, exclude: '**/*'}],
21+
]),
22+
),
2323
}

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
"@commitlint/cli": "^16.1.0",
5454
"@commitlint/config-conventional": "^16.2.1",
5555
"@commitlint/prompt": "^16.1.0",
56-
"@types/jest": "^28.1.4",
56+
"@types/jest": "^29.0.0",
5757
"@types/lodash.has": "^4.5.6",
5858
"@types/mkdirp": "^1.0.2",
5959
"@types/node": ">=17.x",
@@ -80,16 +80,16 @@
8080
"eslint-plugin-react-hooks": "^4.3.0",
8181
"glob": "^8.0.3",
8282
"is-ci": "^3.0.1",
83-
"jest": "^28.1.2",
83+
"jest": "^29.0.2",
8484
"jest-github-actions-reporter": "^1.0.3",
85-
"jest-watch-typeahead": "^1.1.0",
85+
"jest-watch-typeahead": "^2.1.1",
8686
"lint-staged": "^12.3.4",
8787
"lodash.has": "^4.5.2",
8888
"mkdirp": "^1.0.3",
8989
"prettier": "^2.5.1",
9090
"read-pkg-up": "^7.0.1",
9191
"rimraf": "^3.0.2",
92-
"ts-jest": "^28.0.5",
92+
"ts-jest": "^29.0.0-next.1",
9393
"tslib": "^2.4.0",
9494
"typescript": "^4",
9595
"which": "^2.0.2",

src/config/jest.config.js

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ const ignores = [
2222
/** @type JestConfig */
2323
const jestConfig = {
2424
roots: [fromRoot('.')],
25+
// Here we're preserving Jest <= 28 snapshot format to prevent the need
26+
// to update snapshots when upgrading Jest via @hover/javascript, see:
27+
// https://jestjs.io/docs/upgrading-to-jest29#snapshot-format
28+
snapshotFormat: {escapeString: true, printBasicPrototype: true},
2529
testEnvironment: ifAnyDep(['webpack', 'rollup', 'react'], 'jsdom', 'node'),
2630
testEnvironmentOptions: {url: 'http://localhost'},
2731
moduleFileExtensions: testMatchExtensions.concat('json'),
@@ -32,9 +36,9 @@ const jestConfig = {
3236
transform: Object.fromEntries(
3337
// Ensure we can resolve the preset even when
3438
// it's in a nested `node_modules` installation
35-
Object.entries(preset.transform).map(([key, value]) => [
36-
key,
37-
require.resolve(value),
39+
Object.entries(preset.transform).map(([glob, transformer]) => [
40+
glob,
41+
[require.resolve(transformer), {diagnostics: {warnOnly: true}}],
3842
]),
3943
),
4044
coveragePathIgnorePatterns: [
@@ -59,13 +63,6 @@ const jestConfig = {
5963
require.resolve('jest-watch-typeahead/filename'),
6064
require.resolve('jest-watch-typeahead/testname'),
6165
],
62-
globals: {
63-
'ts-jest': {
64-
diagnostics: {
65-
warnOnly: true,
66-
},
67-
},
68-
},
6966
}
7067

7168
if (hasFile('tests/setup-env.js')) {

0 commit comments

Comments
 (0)