Repository navigation
test: add Vitest alongside Jest - #10546
cryptodev-2s wants to merge 36 commits into
Conversation
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
|
Warning MetaMask internal reviewing guidelines:
Ignoring alerts on:
|
66adc1a to
7164c57
Compare
7164c57 to
70edc7c
Compare
c812b32 to
bb0a88a
Compare
70edc7c to
83d2d8b
Compare
mcmire
left a comment
There was a problem hiding this comment.
Thanks for doing this, it's a long time coming. Left some comments below.
There was a problem hiding this comment.
Is this file specific to Jest? If so, should we move it to a jest directory to mirror the new vitest directory? Are there any other files we would want to move to jest? (Files that are shared can continue to live directly outside of tests/vitest.)
There was a problem hiding this comment.
I did deliberately not move this file, as otherwise the scope of the PR would grow to touch all test files where its imported. I can do this as a follow up PR only dedicated to this.
## Explanation Groundwork so the Jest to Vitest migration does not have to carry it. Nothing here needs Vitest, each change stands on its own, and the suite still runs on Jest. Deletes slightly more than it adds. * **`buildTestObject` moves to `packages/network-controller/tests/helpers.ts`** and leaves the root `tests/helpers.ts`. That file is its only consumer, and has been since it was written in MetaMask#4286 on 2024-09-03: `git log -S` finds no other package importing it, ever. Its type parameter is `Key` rather than `K` now, which drops an `id-length` suppression instead of carrying it. * **`tests/matchers.ts` holds the matcher implementations**, leaving `tests/setupAfterEnv/matchers.ts` to do only the `expect.extend` registration. That drops two more suppressions. * **`flushPromises` takes `setImmediate` from `node:timers`** instead of `jest.requireActual('timers')`. The same real timer past the fake ones, one fewer unsafe member access on an `any`. * **`types/global.d.ts` is now `types/jest.d.ts`**, since all it holds is `declare namespace jest`. Also drops four suppressions for `packages/seedless-onboarding-controller/src/utils.ts`, a file MetaMask#10568 split into `src/utils/`. They have pointed at nothing since, and oxlint reports them as unused once anything else in the suppressions file moves. ## References * Precedes the Vitest migration stack starting at MetaMask#10546 ## 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.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 3a2a6d2. Configure here.
| "test": "yarn test:scripts --silent --collectCoverage=false --reporters=jest-silent-reporter && yarn test:scripts:shell && yarn test:packages", | ||
| "test:clean": "yarn workspaces foreach --all --parallel --verbose run test:clean && yarn test", | ||
| "test:packages": "yarn test:verbose --silent --collectCoverage=false --reporters=jest-silent-reporter", | ||
| "test:packages": "yarn workspaces foreach --all --parallel --verbose run test --coverage=false", |
There was a problem hiding this comment.
Root test script recurses infinitely
High Severity
test:packages now runs test across every workspace with --all, and the root test script calls test:packages again. Yarn treats the root as a workspace, so yarn test re-enters itself and never finishes.
Reviewed by Cursor Bugbot for commit 3a2a6d2. Configure here.


Explanation
Adds Vitest alongside Jest so packages can migrate one at a time.
References
Checklist
no-changeloglabel.Note
Medium Risk
Changes monorepo-wide test execution, lint targeting, and Yarn constraints; dual-runner drift is possible until all packages leave the Jest allowlist.
Overview
Adds Vitest as a second unit-test runner so workspaces can migrate off Jest incrementally. A new
test-runner-package-map.cjsallowlists existing packages on Jest; everything else is treated as Vitest (new packages are expected to use Vitest only).Tooling: Root adds
vitest,vite, and Istanbul coverage deps, sharedvitest.config.packages.mjs, andtests/vitest/*setup (custom matchers, nock,node-fetchfor interceptable HTTP).oxlintnow loads Jest vs Vitest rule sets from workspace-aware globs.yarn constraintsassert the correcttest/test:watch/test:unitscripts per runner. Roottest:packagesruns each workspace’stestviayarn workspaces foreachinstead of a single Jest invocation.Jest path: Shared Jest helpers gain explicit
@jest/globalsimports; oxlint suppressions for those files are dropped. Packages with type tests (messenger,utils) runtest:typesbeforetest:unit.Reviewed by Cursor Bugbot for commit 3a2a6d2. Bugbot is set up for automated code reviews on this repo. Configure here.