Skip to content

Commit 00517c1

Browse files
chore: migrate Jest from v27 to v29 (#7894)
## Explanation <!-- Thanks for your contribution! Take a moment to answer these questions so that reviewers have the information they need to properly understand your changes: * What is the current state of things and why does it need to change? * What is the solution your changes offer and how does it work? * Are there any changes whose purpose might not obvious to those unfamiliar with the domain? * If your primary goal was to update one package but you found you had to update another one along the way, why did you do so? * If you had to upgrade a dependency, why did you do so? --> ## References <!-- Are there any issues that this pull request is tied to? Are there other links that reviewers should consult to understand these changes better? Are there client or consumer pull requests to adopt any breaking changes? For example: * Fixes #12345 * Related to #67890 --> ## Checklist - [ ] I've updated the test suite for new or updated code as appropriate - [ ] I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate - [ ] I've communicated my changes to consumers by [updating changelogs for packages I've changed](https://github.com/MetaMask/core/tree/main/docs/processes/updating-changelogs.md) - [ ] I've introduced [breaking changes](https://github.com/MetaMask/core/tree/main/docs/processes/breaking-changes.md) in this PR and have prepared draft pull requests for clients and consumer packages to resolve them <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Medium Risk** > Moderate risk because it upgrades core test runner dependencies and changes transforms/environments, which can cause widespread CI failures or subtle test behavior differences despite being mostly config/snapshot churn. > > **Overview** > Upgrades the monorepo’s test tooling from **Jest v27 to v29** (and aligns `@types/jest`, `ts-jest`, and `jest-environment-jsdom` versions across packages), removing now-unneeded Babel test plumbing (drops `babel.config.js` and `babel-jest`). > > Updates Jest configuration to run TypeScript tests via **`ts-jest`** (including scripts) and adds targeted `moduleNameMapper` fixes like resolving `uuid` explicitly; also updates the custom JSDOM environment to use the v29 `TestEnvironment` export. > > Regenerates/updates numerous inline snapshots and `.snap` files to match Jest v29’s snapshot formatting output changes. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 9082f5a. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY --> --------- Co-authored-by: Mark Stacey <markjstacey@gmail.com>
1 parent 8d570c5 commit 00517c1

171 files changed

Lines changed: 3809 additions & 4139 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.depcheckrc.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,14 @@ ignores:
1818
- 'typedoc'
1919
# Ignore plugins for tools
2020
- '@typescript-eslint/*'
21-
- 'babel-jest'
2221
- 'eslint-config-*'
2322
- 'eslint-plugin-*'
2423
- 'jest-silent-reporter'
2524
- 'prettier-plugin-packagejson'
2625
- 'typescript-eslint'
26+
# Jest environment referenced in `jest.config.scripts.js`
27+
- 'jest-environment-node'
28+
- 'jest-environment-jsdom'
2729
# Ignore dependencies imported implicitly by tools
2830
- 'eslint-import-resolver-typescript'
2931
# Ignore dependencies which plug into the NPM lifecycle

babel.config.js

Lines changed: 0 additions & 9 deletions
This file was deleted.

jest.config.packages.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ module.exports = {
8989
// so in that case use their published versions
9090
'<rootDir>/../../node_modules/@metamask/$1',
9191
],
92+
'^uuid$': require.resolve('uuid'),
9293
},
9394

9495
// An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader
@@ -188,9 +189,6 @@ module.exports = {
188189
// This option sets the URL for the jsdom environment. It is reflected in properties such as location.href
189190
// testURL: "http://localhost",
190191

191-
// Setting this value to "fake" allows the use of fake timers for functions such as "setTimeout"
192-
// timers: "real",
193-
194192
// A map from regular expressions to paths to transformers
195193
// transform: undefined,
196194

jest.config.scripts.js

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
/*
22
* For a detailed explanation regarding each configuration property and type check, visit:
33
* https://jestjs.io/docs/configuration
4-
*
5-
* NOTE:
6-
* This config uses `babel-jest` due to ESM- / TypeScript-related incompatibilities with our
7-
* current version (`^27`) of `jest` and `ts-jest`. We can switch to `ts-jest` once we have
8-
* migrated our Jest dependencies to version `>=29`.
94
*/
105

116
module.exports = {
@@ -38,17 +33,11 @@ module.exports = {
3833
},
3934
},
4035

41-
// A map from regular expressions to module names or to arrays of module names that allow to stub out resources with a single module
42-
// This ensures that Babel can resolve subpath exports correctly.
4336
moduleNameMapper: {
44-
'^@metamask/utils/(.+)$': [
45-
'<rootDir>/node_modules/@metamask/utils/dist/$1.cjs',
46-
],
37+
'^uuid$': require.resolve('uuid'),
4738
},
4839

49-
// Disabled due to use of 'transform' below.
50-
// // A preset that is used as a base for Jest's configuration
51-
// preset: 'ts-jest',
40+
preset: 'ts-jest',
5241

5342
// The path to the Prettier executable used to format snapshots
5443
// Jest doesn't support Prettier 3 yet, so we use Prettier 2
@@ -84,9 +73,4 @@ module.exports = {
8473

8574
// Default timeout of a test in milliseconds.
8675
testTimeout: 5000,
87-
88-
// A map from regular expressions to paths to transformers
89-
transform: {
90-
'\\.[jt]sx?$': 'babel-jest',
91-
},
9276
};

package.json

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,6 @@
5050
"ws@7.4.6": "^7.5.10"
5151
},
5252
"devDependencies": {
53-
"@babel/core": "^7.23.5",
54-
"@babel/plugin-transform-modules-commonjs": "^7.23.3",
55-
"@babel/preset-typescript": "^7.23.3",
5653
"@lavamoat/allow-scripts": "^3.0.4",
5754
"@lavamoat/preinstall-always-fail": "^2.1.0",
5855
"@metamask/create-release-branch": "^4.1.4",
@@ -66,14 +63,13 @@
6663
"@metamask/network-controller": "^29.0.0",
6764
"@metamask/utils": "^11.9.0",
6865
"@ts-bridge/cli": "^0.6.4",
69-
"@types/jest": "^27.5.2",
66+
"@types/jest": "^29.5.14",
7067
"@types/lodash": "^4.14.191",
7168
"@types/node": "^16.18.54",
7269
"@types/semver": "^7",
7370
"@typescript-eslint/eslint-plugin": "^8.48.0",
7471
"@typescript-eslint/parser": "^8.48.0",
7572
"@yarnpkg/types": "^4.0.0",
76-
"babel-jest": "^29.7.0",
7773
"comment-json": "^4.5.1",
7874
"depcheck": "^1.4.7",
7975
"eslint": "^9.39.1",
@@ -87,7 +83,7 @@
8783
"eslint-plugin-promise": "^7.1.0",
8884
"execa": "^5.0.0",
8985
"isomorphic-fetch": "^3.0.0",
90-
"jest": "^27.5.1",
86+
"jest": "^29.7.0",
9187
"jest-silent-reporter": "^0.5.0",
9288
"lodash": "^4.17.21",
9389
"nock": "^13.3.1",
@@ -100,6 +96,7 @@
10096
"tsx": "^4.20.5",
10197
"typescript": "~5.3.3",
10298
"typescript-eslint": "^8.48.0",
99+
"uuid": "^8.3.2",
103100
"yargs": "^17.7.2"
104101
},
105102
"packageManager": "yarn@4.10.3",

packages/account-tree-controller/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,10 @@
6868
"@metamask/keyring-api": "^21.5.0",
6969
"@metamask/providers": "^22.1.0",
7070
"@ts-bridge/cli": "^0.6.4",
71-
"@types/jest": "^27.5.2",
71+
"@types/jest": "^29.5.14",
7272
"deepmerge": "^4.2.2",
73-
"jest": "^27.5.1",
74-
"ts-jest": "^27.1.5",
73+
"jest": "^29.7.0",
74+
"ts-jest": "^29.2.5",
7575
"typedoc": "^0.24.8",
7676
"typedoc-plugin-missing-exports": "^2.0.0",
7777
"typescript": "~5.3.3",

packages/account-tree-controller/src/AccountTreeController.test.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4359,7 +4359,7 @@ describe('AccountTreeController', () => {
43594359
controller.metadata,
43604360
'includeInDebugSnapshot',
43614361
),
4362-
).toMatchInlineSnapshot(`Object {}`);
4362+
).toMatchInlineSnapshot(`{}`);
43634363
});
43644364

43654365
it('includes expected state in state logs', () => {
@@ -4372,13 +4372,13 @@ describe('AccountTreeController', () => {
43724372
'includeInStateLogs',
43734373
),
43744374
).toMatchInlineSnapshot(`
4375-
Object {
4376-
"accountGroupsMetadata": Object {},
4377-
"accountTree": Object {
4375+
{
4376+
"accountGroupsMetadata": {},
4377+
"accountTree": {
43784378
"selectedAccountGroup": "",
4379-
"wallets": Object {},
4379+
"wallets": {},
43804380
},
4381-
"accountWalletsMetadata": Object {},
4381+
"accountWalletsMetadata": {},
43824382
"hasAccountTreeSyncingSyncedAtLeastOnce": false,
43834383
}
43844384
`);
@@ -4394,9 +4394,9 @@ describe('AccountTreeController', () => {
43944394
'persist',
43954395
),
43964396
).toMatchInlineSnapshot(`
4397-
Object {
4398-
"accountGroupsMetadata": Object {},
4399-
"accountWalletsMetadata": Object {},
4397+
{
4398+
"accountGroupsMetadata": {},
4399+
"accountWalletsMetadata": {},
44004400
"hasAccountTreeSyncingSyncedAtLeastOnce": false,
44014401
}
44024402
`);
@@ -4412,13 +4412,13 @@ describe('AccountTreeController', () => {
44124412
'usedInUi',
44134413
),
44144414
).toMatchInlineSnapshot(`
4415-
Object {
4416-
"accountGroupsMetadata": Object {},
4417-
"accountTree": Object {
4415+
{
4416+
"accountGroupsMetadata": {},
4417+
"accountTree": {
44184418
"selectedAccountGroup": "",
4419-
"wallets": Object {},
4419+
"wallets": {},
44204420
},
4421-
"accountWalletsMetadata": Object {},
4421+
"accountWalletsMetadata": {},
44224422
"hasAccountTreeSyncingSyncedAtLeastOnce": false,
44234423
"isAccountTreeSyncingInProgress": false,
44244424
}

packages/accounts-controller/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,10 @@
7373
"@metamask/controller-utils": "^11.18.0",
7474
"@metamask/providers": "^22.1.0",
7575
"@ts-bridge/cli": "^0.6.4",
76-
"@types/jest": "^27.5.2",
76+
"@types/jest": "^29.5.14",
7777
"@types/readable-stream": "^2.3.0",
78-
"jest": "^27.5.1",
79-
"ts-jest": "^27.1.5",
78+
"jest": "^29.7.0",
79+
"ts-jest": "^29.2.5",
8080
"typedoc": "^0.24.8",
8181
"typedoc-plugin-missing-exports": "^2.0.0",
8282
"typescript": "~5.3.3",

packages/accounts-controller/src/AccountsController.test.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3901,7 +3901,7 @@ describe('AccountsController', () => {
39013901
controller.metadata,
39023902
'includeInDebugSnapshot',
39033903
),
3904-
).toMatchInlineSnapshot(`Object {}`);
3904+
).toMatchInlineSnapshot(`{}`);
39053905
});
39063906

39073907
it('includes expected state in state logs', () => {
@@ -3914,9 +3914,9 @@ describe('AccountsController', () => {
39143914
'includeInStateLogs',
39153915
),
39163916
).toMatchInlineSnapshot(`
3917-
Object {
3918-
"internalAccounts": Object {
3919-
"accounts": Object {},
3917+
{
3918+
"internalAccounts": {
3919+
"accounts": {},
39203920
"selectedAccount": "",
39213921
},
39223922
}
@@ -3933,9 +3933,9 @@ describe('AccountsController', () => {
39333933
'persist',
39343934
),
39353935
).toMatchInlineSnapshot(`
3936-
Object {
3937-
"internalAccounts": Object {
3938-
"accounts": Object {},
3936+
{
3937+
"internalAccounts": {
3938+
"accounts": {},
39393939
"selectedAccount": "",
39403940
},
39413941
}
@@ -3952,9 +3952,9 @@ describe('AccountsController', () => {
39523952
'usedInUi',
39533953
),
39543954
).toMatchInlineSnapshot(`
3955-
Object {
3956-
"internalAccounts": Object {
3957-
"accounts": Object {},
3955+
{
3956+
"internalAccounts": {
3957+
"accounts": {},
39583958
"selectedAccount": "",
39593959
},
39603960
}

packages/address-book-controller/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@
5656
"devDependencies": {
5757
"@metamask/auto-changelog": "^3.4.4",
5858
"@ts-bridge/cli": "^0.6.4",
59-
"@types/jest": "^27.5.2",
59+
"@types/jest": "^29.5.14",
6060
"deepmerge": "^4.2.2",
61-
"jest": "^27.5.1",
62-
"ts-jest": "^27.1.5",
61+
"jest": "^29.7.0",
62+
"ts-jest": "^29.2.5",
6363
"typedoc": "^0.24.8",
6464
"typedoc-plugin-missing-exports": "^2.0.0",
6565
"typescript": "~5.3.3"

0 commit comments

Comments
 (0)