Skip to content

Commit a551dfc

Browse files
authored
test: run delegation packages on Vitest (#10953)
## Explanation Moves `@metamask/delegation-controller` and `@metamask/gator-permissions-controller` to Vitest. ## References - https://consensyssoftware.atlassian.net/browse/WPC-1482 ## Checklist - [x] I've updated the test suite for new or updated code as appropriate - [x] 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) * Not applicable, test only change. Carries the `no-changelog` label. - [ ] 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 * None. <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Low Risk** > Test-only and tooling changes; production controller code is unchanged. > > **Overview** > **Migrates `@metamask/delegation-controller` and `@metamask/gator-permissions-controller` from Jest to Vitest**, following the same package-level pattern used elsewhere in the repo (shared `vitest.config.packages.js`, per-package `vitest.config.ts` with prior coverage thresholds). > > For each package, **test scripts and devDependencies** switch to Vitest; **Jest config and `jest` TypeScript types** are removed. Test sources are updated mechanically (`jest` → `vi`, Vitest imports, `vi.mock` with dynamic import in gator-permissions, `flushPromises` from `tests/vitest/helpers.js`). > > **Repo wiring:** both packages are dropped from the Jest runner map in `test-runner-package-map.cjs`, and `oxlint-suppressions.json` is adjusted (including `vitest/no-conditional-in-test` entries for gator-permissions tests). > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 0267231. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent 168fc9c commit a551dfc

21 files changed

Lines changed: 239 additions & 261 deletions

‎oxlint-suppressions.json‎

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2151,11 +2151,6 @@
21512151
"count": 1
21522152
}
21532153
},
2154-
"packages/delegation-controller/jest.config.cjs": {
2155-
"import/unambiguous": {
2156-
"count": 1
2157-
}
2158-
},
21592154
"packages/delegation-controller/src/DelegationController.test.ts": {
21602155
"typescript/explicit-function-return-type": {
21612156
"count": 3
@@ -2531,11 +2526,6 @@
25312526
"count": 19
25322527
}
25332528
},
2534-
"packages/gator-permissions-controller/jest.config.cjs": {
2535-
"import/unambiguous": {
2536-
"count": 1
2537-
}
2538-
},
25392529
"packages/gator-permissions-controller/src/GatorPermissionsController.test.ts": {
25402530
"typescript/no-unsafe-argument": {
25412531
"count": 10
@@ -2546,7 +2536,7 @@
25462536
"typescript/no-unsafe-member-access": {
25472537
"count": 3
25482538
},
2549-
"typescript/no-unsafe-return": {
2539+
"vitest/no-conditional-in-test": {
25502540
"count": 1
25512541
}
25522542
},
@@ -2558,14 +2548,22 @@
25582548
"count": 2
25592549
}
25602550
},
2551+
"packages/gator-permissions-controller/src/decodePermission/utils.test.ts": {
2552+
"vitest/no-conditional-in-test": {
2553+
"count": 1
2554+
}
2555+
},
25612556
"packages/gator-permissions-controller/src/permissionOnChainStatus.test.ts": {
25622557
"typescript/no-unsafe-member-access": {
25632558
"count": 13
2559+
},
2560+
"vitest/no-conditional-in-test": {
2561+
"count": 8
25642562
}
25652563
},
25662564
"packages/gator-permissions-controller/src/utils.test.ts": {
25672565
"typescript/no-unsafe-member-access": {
2568-
"count": 2
2566+
"count": 1
25692567
}
25702568
},
25712569
"packages/geolocation-controller/jest.config.cjs": {

‎packages/delegation-controller/jest.config.cjs‎

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

‎packages/delegation-controller/package.json‎

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@
4444
"messenger-action-types:check": "node --import ../../scripts/resolver/register.ts --experimental-transform-types ../../packages/messenger-cli/src/cli.ts --formatter oxfmt --esm --check",
4545
"messenger-action-types:generate": "node --import ../../scripts/resolver/register.ts --experimental-transform-types ../../packages/messenger-cli/src/cli.ts --formatter oxfmt --esm --generate",
4646
"since-latest-release": "../../scripts/since-latest-release.sh",
47-
"test": "NODE_OPTIONS=--experimental-vm-modules jest --reporters=jest-silent-reporter",
48-
"test:clean": "NODE_OPTIONS=--experimental-vm-modules jest --clearCache",
49-
"test:verbose": "NODE_OPTIONS=--experimental-vm-modules jest --verbose",
50-
"test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch"
47+
"test": "vitest",
48+
"test:clean": "vitest --clearCache",
49+
"test:verbose": "vitest --reporter=verbose",
50+
"test:watch": "vitest --watch"
5151
},
5252
"dependencies": {
5353
"@metamask/base-controller": "^10.1.0",
@@ -57,15 +57,12 @@
5757
},
5858
"devDependencies": {
5959
"@metamask/auto-changelog": "^6.2.1",
60-
"@types/jest": "^30.0.0",
6160
"@typescript/native": "npm:typescript@^7.0.2",
62-
"deepmerge": "^4.3.1",
63-
"jest": "^30.5.2",
6461
"rimraf": "^6.1.3",
65-
"ts-jest": "^29.4.14",
6662
"typedoc": "^0.28.20",
6763
"typedoc-plugin-missing-exports": "^4.1.4",
68-
"typescript": "npm:@typescript/typescript6@^6.0.2"
64+
"typescript": "npm:@typescript/typescript6@^6.0.2",
65+
"vitest": "^5.0.0"
6966
},
7067
"engines": {
7168
"node": "^22.14.0 || ^24"

‎packages/delegation-controller/src/DelegationController.test.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import type {
77
MockAnyNamespace,
88
} from '@metamask/messenger';
99
import { hexToNumber } from '@metamask/utils';
10+
import { beforeEach, describe, expect, it, vi } from 'vitest';
1011

1112
import { ROOT_AUTHORITY } from './constants.js';
1213
import {
@@ -74,7 +75,7 @@ function createMessengerMock() {
7475
namespace: MOCK_ANY_NAMESPACE,
7576
});
7677

77-
const keyringControllerSignTypedMessageMock = jest.fn();
78+
const keyringControllerSignTypedMessageMock = vi.fn();
7879

7980
keyringControllerSignTypedMessageMock.mockResolvedValue(SIGNATURE_HASH_MOCK);
8081

@@ -143,7 +144,7 @@ function createController(state?: DelegationControllerState) {
143144

144145
describe(`${controllerName}`, () => {
145146
beforeEach(() => {
146-
jest.resetAllMocks();
147+
vi.resetAllMocks();
147148
});
148149

149150
describe('constructor', () => {

‎packages/delegation-controller/tsconfig.json‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
{
22
"extends": "../../tsconfig.packages.json",
3-
"compilerOptions": {
4-
"types": ["jest"]
5-
},
63
"references": [
74
{
85
"path": "../base-controller"
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { basename, dirname } from 'node:path';
2+
import { fileURLToPath } from 'node:url';
3+
import { defineConfig, mergeConfig } from 'vitest/config';
4+
5+
import baseConfig from '../../vitest.config.packages.js';
6+
7+
export default mergeConfig(
8+
baseConfig,
9+
defineConfig({
10+
test: {
11+
name: basename(dirname(fileURLToPath(import.meta.url))),
12+
13+
coverage: {
14+
thresholds: {
15+
branches: 100,
16+
functions: 100,
17+
lines: 100,
18+
statements: 100,
19+
},
20+
},
21+
},
22+
}),
23+
);

‎packages/gator-permissions-controller/jest.config.cjs‎

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

‎packages/gator-permissions-controller/package.json‎

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@
4444
"messenger-action-types:check": "node --import ../../scripts/resolver/register.ts --experimental-transform-types ../../packages/messenger-cli/src/cli.ts --formatter oxfmt --esm --check",
4545
"messenger-action-types:generate": "node --import ../../scripts/resolver/register.ts --experimental-transform-types ../../packages/messenger-cli/src/cli.ts --formatter oxfmt --esm --generate",
4646
"since-latest-release": "../../scripts/since-latest-release.sh",
47-
"test": "NODE_OPTIONS=--experimental-vm-modules jest --reporters=jest-silent-reporter",
48-
"test:clean": "NODE_OPTIONS=--experimental-vm-modules jest --clearCache",
49-
"test:verbose": "NODE_OPTIONS=--experimental-vm-modules jest --verbose",
50-
"test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch"
47+
"test": "vitest",
48+
"test:clean": "vitest --clearCache",
49+
"test:verbose": "vitest --reporter=verbose",
50+
"test:watch": "vitest --watch"
5151
},
5252
"dependencies": {
5353
"@metamask/7715-permission-types": "^1.0.0",
@@ -67,15 +67,12 @@
6767
"@lavamoat/allow-scripts": "^5.1.0",
6868
"@lavamoat/preinstall-always-fail": "^3.0.0",
6969
"@metamask/auto-changelog": "^6.2.1",
70-
"@types/jest": "^30.0.0",
7170
"@typescript/native": "npm:typescript@^7.0.2",
72-
"deepmerge": "^4.3.1",
73-
"jest": "^30.5.2",
7471
"rimraf": "^6.1.3",
75-
"ts-jest": "^29.4.14",
7672
"typedoc": "^0.28.20",
7773
"typedoc-plugin-missing-exports": "^4.1.4",
78-
"typescript": "npm:@typescript/typescript6@^6.0.2"
74+
"typescript": "npm:@typescript/typescript6@^6.0.2",
75+
"vitest": "^5.0.0"
7976
},
8077
"engines": {
8178
"node": "^22.14.0 || ^24"

0 commit comments

Comments
 (0)