Skip to content

Commit 168fc9c

Browse files
authored
test: run social-ai packages on Vitest (#10954)
## Explanation Moves `@metamask/ai-controllers` and `@metamask/social-controllers` to Vitest. ## References - https://consensyssoftware.atlassian.net/browse/WPC-1478 ## 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 tooling swap with no production code changes; behavior should match prior Jest suites aside from the runner. > > **Overview** > **Migrates `@metamask/ai-controllers` and `@metamask/social-controllers` from Jest to Vitest**, aligning them with the repo’s default test runner for new packages. > > For each package, **Jest config and devDependencies are removed** and replaced with **`vitest.config.ts`** (merged from the shared package base, keeping **100% global coverage thresholds**). **`package.json` test scripts** now invoke `vitest` instead of `NODE_OPTIONS=--experimental-vm-modules jest`. **Test sources** import `describe` / `expect` / `it` / `vi` from Vitest and use **`vi.fn()`** (and Vitest **`Mock`** types) instead of Jest globals. **`tsconfig.json` no longer includes Jest types.** > > **`test-runner-package-map.cjs`** drops both packages from **`PACKAGES_ON_JEST`**. **`oxlint-suppressions.json`** is updated for the removed Jest configs and adds suppressions for **`vitest/no-conditional-in-test`** on `SocialRealtimeService.test.ts`. > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 791bb75. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent 80b821b commit 168fc9c

17 files changed

Lines changed: 145 additions & 170 deletions

‎oxlint-suppressions.json‎

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -448,11 +448,6 @@
448448
"count": 5
449449
}
450450
},
451-
"packages/ai-controllers/jest.config.cjs": {
452-
"import/unambiguous": {
453-
"count": 1
454-
}
455-
},
456451
"packages/analytics-controller/jest.config.cjs": {
457452
"import/unambiguous": {
458453
"count": 1
@@ -5007,14 +5002,9 @@
50075002
"count": 1
50085003
}
50095004
},
5010-
"packages/social-controllers/jest.config.cjs": {
5011-
"import/unambiguous": {
5012-
"count": 1
5013-
}
5014-
},
5015-
"packages/social-controllers/src/SocialService.test.ts": {
5016-
"typescript/no-unsafe-member-access": {
5017-
"count": 8
5005+
"packages/social-controllers/src/SocialRealtimeService.test.ts": {
5006+
"vitest/no-conditional-in-test": {
5007+
"count": 54
50185008
}
50195009
},
50205010
"packages/solana-test-validator-up/jest.config.cjs": {

‎packages/ai-controllers/jest.config.cjs‎

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

‎packages/ai-controllers/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",
@@ -56,15 +56,12 @@
5656
},
5757
"devDependencies": {
5858
"@metamask/auto-changelog": "^6.2.1",
59-
"@types/jest": "^30.0.0",
6059
"@typescript/native": "npm:typescript@^7.0.2",
61-
"deepmerge": "^4.3.1",
62-
"jest": "^30.5.2",
6360
"rimraf": "^6.1.3",
64-
"ts-jest": "^29.4.14",
6561
"typedoc": "^0.28.20",
6662
"typedoc-plugin-missing-exports": "^4.1.4",
67-
"typescript": "npm:@typescript/typescript6@^6.0.2"
63+
"typescript": "npm:@typescript/typescript6@^6.0.2",
64+
"vitest": "^5.0.0"
6865
},
6966
"engines": {
7067
"node": "^22.14.0 || ^24"

‎packages/ai-controllers/src/AiDigestController.test.ts‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Messenger } from '@metamask/messenger';
2+
import { describe, expect, it, vi } from 'vitest';
23

34
import {
45
AiDigestController,
@@ -51,9 +52,9 @@ const createMessenger = (): AiDigestControllerMessenger =>
5152
});
5253

5354
const createService = (overrides?: Partial<DigestService>): DigestService => ({
54-
searchDigest: jest.fn().mockResolvedValue(mockReport),
55-
fetchMarketOverview: jest.fn().mockResolvedValue(mockOverview),
56-
fetchFrontPageItem: jest.fn().mockResolvedValue(mockFrontPage),
55+
searchDigest: vi.fn().mockResolvedValue(mockReport),
56+
fetchMarketOverview: vi.fn().mockResolvedValue(mockOverview),
57+
fetchFrontPageItem: vi.fn().mockResolvedValue(mockFrontPage),
5758
...overrides,
5859
});
5960

@@ -135,7 +136,7 @@ describe('AiDigestController (market insights)', () => {
135136

136137
it('returns null when the service returns null', async () => {
137138
const digestService = createService({
138-
searchDigest: jest.fn().mockResolvedValue(null),
139+
searchDigest: vi.fn().mockResolvedValue(null),
139140
});
140141
const controller = new AiDigestController({
141142
messenger: createMessenger(),
@@ -177,7 +178,7 @@ describe('AiDigestController (market overview)', () => {
177178

178179
it('returns null when the service returns null', async () => {
179180
const digestService = createService({
180-
fetchMarketOverview: jest.fn().mockResolvedValue(null),
181+
fetchMarketOverview: vi.fn().mockResolvedValue(null),
181182
});
182183
const controller = new AiDigestController({
183184
messenger: createMessenger(),
@@ -222,7 +223,7 @@ describe('AiDigestController (front page)', () => {
222223

223224
it('returns null when the service returns null', async () => {
224225
const digestService = createService({
225-
fetchFrontPageItem: jest.fn().mockResolvedValue(null),
226+
fetchFrontPageItem: vi.fn().mockResolvedValue(null),
226227
});
227228
const controller = new AiDigestController({
228229
messenger: createMessenger(),

‎packages/ai-controllers/src/AiDigestService.test.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
import { afterAll, beforeEach, describe, expect, it, vi } from 'vitest';
2+
13
import { AiDigestControllerErrorMessage } from './ai-digest-constants.js';
24
import { AiDigestService } from './index.js';
35

46
describe('AiDigestService', () => {
5-
const mockFetch = jest.fn();
7+
const mockFetch = vi.fn();
68
const originalFetch = global.fetch;
79

810
beforeEach(() => {

‎packages/ai-controllers/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/social-controllers/jest.config.cjs‎

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

‎packages/social-controllers/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",
@@ -60,15 +60,12 @@
6060
},
6161
"devDependencies": {
6262
"@metamask/auto-changelog": "^6.2.1",
63-
"@types/jest": "^30.0.0",
6463
"@typescript/native": "npm:typescript@^7.0.2",
65-
"deepmerge": "^4.3.1",
66-
"jest": "^30.5.2",
6764
"rimraf": "^6.1.3",
68-
"ts-jest": "^29.4.14",
6965
"typedoc": "^0.28.20",
7066
"typedoc-plugin-missing-exports": "^4.1.4",
71-
"typescript": "npm:@typescript/typescript6@^6.0.2"
67+
"typescript": "npm:@typescript/typescript6@^6.0.2",
68+
"vitest": "^5.0.0"
7269
},
7370
"engines": {
7471
"node": "^22.14.0 || ^24"

0 commit comments

Comments
 (0)