Skip to content

test: add Vitest alongside Jest - #10546

Open
cryptodev-2s wants to merge 36 commits into
mainfrom
test/vitest-setup
Open

cryptodev-2s wants to merge 36 commits into
mainfrom
test/vitest-setup

Conversation

@cryptodev-2s

@cryptodev-2s cryptodev-2s commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Explanation

Adds Vitest alongside Jest so packages can migrate one at a time.

References

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
    • Not applicable, test only change. Carries the no-changelog label.
  • I've introduced breaking changes in this PR and have prepared draft pull requests for clients and consumer packages to resolve them
    • None.

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.cjs allowlists 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, shared vitest.config.packages.mjs, and tests/vitest/* setup (custom matchers, nock, node-fetch for interceptable HTTP). oxlint now loads Jest vs Vitest rule sets from workspace-aware globs. yarn constraints assert the correct test / test:watch / test:unit scripts per runner. Root test:packages runs each workspace’s test via yarn workspaces foreach instead of a single Jest invocation.

Jest path: Shared Jest helpers gain explicit @jest/globals imports; oxlint suppressions for those files are dropped. Packages with type tests (messenger, utils) run test:types before test:unit.

Reviewed by Cursor Bugbot for commit 3a2a6d2. Bugbot is set up for automated code reviews on this repo. Configure here.

@cryptodev-2s
cryptodev-2s requested review from a team as code owners September 28, 2026 20:17
@cryptodev-2s
cryptodev-2s deployed to default-branch September 28, 2026 20:18 — with GitHub Actions Active
@socket-security

socket-security Bot commented Sep 28, 2026 •

Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Added@​metamask/​oxlint-config-vitest@​0.1.1691007592100
Added@​vitest/​coverage-istanbul@​5.0.3991007899100
Addedvitest@​5.0.3981007998100
Addedvite@​8.3.4991008296100

View full report

@socket-security

socket-security Bot commented Sep 28, 2026 •

Copy link
Copy Markdown

Warning

MetaMask internal reviewing guidelines:

  • Do not ignore-all
  • Each alert has instructions on how to review if you don't know what it means. If lost, ask your Security Liaison or the supply-chain group
  • Copy-paste ignore lines for specific packages or a group of one kind with a note on what research you did to deem it safe.
    @SocketSecurity ignore npm/PACKAGE@VERSION
Priority Alert  (click "▶" to expand/collapse) Action
Low priority
Potential code anomaly (AI signal): npm es-module-lexer is 74.0% likely to have a medium risk anomaly

Notes: A WebAssembly-backed parser wrapper (package/dist/lexer.js) executes substrings extracted from untrusted input using (0, eval) during parsing, enabling arbitrary JavaScript execution if attacker-controlled data reaches the eval path. The threat also includes potential sensitive data leakage through error messages. Disable parse() on untrusted input or sandbox/replace builds to mitigate this risk.

Confidence: 0.74

Severity: 0.78

From: package.json → npm/@docusaurus/core@3.10.2 → npm/@docusaurus/theme-common@3.10.2 → npm/@docusaurus/types@3.10.2 → npm/@docusaurus/plugin-content-docs@3.10.2 → npm/@docusaurus/preset-classic@3.10.2 → npm/@easyops-cn/docusaurus-search-local@0.55.3 → npm/jest@30.5.2 → npm/vitest@5.0.3 → npm/raw-loader@4.0.2 → npm/es-module-lexer@2.3.2

ℹ Read more on: This package | This alert | What is an AI-detected potential code anomaly?

Next steps: Take a moment to review the security alert above. Review the linked package source code to understand the potential risk. Ensure the package is not malicious before proceeding. If you're unsure how to proceed, reach out to your security team or ask the Socket team for help at support@socket.dev.

Suggestion: An AI system found a low-risk anomaly in this package. It may still be fine to use, but you should check that it is safe before proceeding.

Mark the package as acceptable risk. To ignore this alert only in this pull request, reply with the comment @SocketSecurity ignore npm/es-module-lexer@2.3.2. You can also ignore all packages with @SocketSecurity ignore-all. To ignore an alert for all future pull requests, use Socket's Dashboard to change the triage state of this alert.

Warn
Low priority
Potential code anomaly (AI signal): npm es-module-lexer is 70.0% likely to have a medium risk anomaly

Notes: A WASM-backed parser wrapper copies caller input into WASM memory and conditionally executes eval() on substrings that resemble quoted literals, creating a potential code-execution risk in the calling process. Error messages may include slices of input, increasing the chance of sensitive data exposure; the embedded WASM payload is opaque and could contain additional, unseen behaviors.

Confidence: 0.70

Severity: 0.70

From: package.json → npm/@docusaurus/core@3.10.2 → npm/@docusaurus/theme-common@3.10.2 → npm/@docusaurus/types@3.10.2 → npm/@docusaurus/plugin-content-docs@3.10.2 → npm/@docusaurus/preset-classic@3.10.2 → npm/@easyops-cn/docusaurus-search-local@0.55.3 → npm/jest@30.5.2 → npm/vitest@5.0.3 → npm/raw-loader@4.0.2 → npm/es-module-lexer@2.3.2

ℹ Read more on: This package | This alert | What is an AI-detected potential code anomaly?

Next steps: Take a moment to review the security alert above. Review the linked package source code to understand the potential risk. Ensure the package is not malicious before proceeding. If you're unsure how to proceed, reach out to your security team or ask the Socket team for help at support@socket.dev.

Suggestion: An AI system found a low-risk anomaly in this package. It may still be fine to use, but you should check that it is safe before proceeding.

Mark the package as acceptable risk. To ignore this alert only in this pull request, reply with the comment @SocketSecurity ignore npm/es-module-lexer@2.3.2. You can also ignore all packages with @SocketSecurity ignore-all. To ignore an alert for all future pull requests, use Socket's Dashboard to change the triage state of this alert.

Warn
Low priority
Network access: npm vitest in module globalThis["fetch"]

Module: globalThis["fetch"]

Location: Package overview

From: package.json → npm/vitest@5.0.3

ℹ Read more on: This package | This alert | What is network access?

Next steps: Take a moment to review the security alert above. Review the linked package source code to understand the potential risk. Ensure the package is not malicious before proceeding. If you're unsure how to proceed, reach out to your security team or ask the Socket team for help at support@socket.dev.

Suggestion: Packages should remove all network access that is functionally unnecessary. Consumers should audit network access to ensure legitimate use.

Mark the package as acceptable risk. To ignore this alert only in this pull request, reply with the comment @SocketSecurity ignore npm/vitest@5.0.3. You can also ignore all packages with @SocketSecurity ignore-all. To ignore an alert for all future pull requests, use Socket's Dashboard to change the triage state of this alert.

Warn
Low priority
Environment variable access: npm obug reads DEBUG

Env Vars: DEBUG

Location: Package overview

From: package.json → npm/vitest@5.0.3 → npm/@vitest/coverage-istanbul@5.0.3 → npm/obug@2.2.1

ℹ Read more on: This package | This alert | What is environment variable access?

Next steps: Take a moment to review the security alert above. Review the linked package source code to understand the potential risk. Ensure the package is not malicious before proceeding. If you're unsure how to proceed, reach out to your security team or ask the Socket team for help at support@socket.dev.

Suggestion: Packages should be clear about which environment variables they access, and care should be taken to ensure they only access environment variables they claim to.

Mark the package as acceptable risk. To ignore this alert only in this pull request, reply with the comment @SocketSecurity ignore npm/obug@2.2.1. You can also ignore all packages with @SocketSecurity ignore-all. To ignore an alert for all future pull requests, use Socket's Dashboard to change the triage state of this alert.

Warn
Low priority
Environment variable access: npm obug

Location: Package overview

From: package.json → npm/vitest@5.0.3 → npm/@vitest/coverage-istanbul@5.0.3 → npm/obug@2.2.1

ℹ Read more on: This package | This alert | What is environment variable access?

Next steps: Take a moment to review the security alert above. Review the linked package source code to understand the potential risk. Ensure the package is not malicious before proceeding. If you're unsure how to proceed, reach out to your security team or ask the Socket team for help at support@socket.dev.

Suggestion: Packages should be clear about which environment variables they access, and care should be taken to ensure they only access environment variables they claim to.

Mark the package as acceptable risk. To ignore this alert only in this pull request, reply with the comment @SocketSecurity ignore npm/obug@2.2.1. You can also ignore all packages with @SocketSecurity ignore-all. To ignore an alert for all future pull requests, use Socket's Dashboard to change the triage state of this alert.

Warn
Low priority
Environment variable access: npm rolldown reads NAPI_RS_NATIVE_LIBRARY_PATH

Env Vars: NAPI_RS_NATIVE_LIBRARY_PATH

Location: Package overview

From: package.json → npm/vite@8.3.4 → npm/rolldown@1.2.13

ℹ Read more on: This package | This alert | What is environment variable access?

Next steps: Take a moment to review the security alert above. Review the linked package source code to understand the potential risk. Ensure the package is not malicious before proceeding. If you're unsure how to proceed, reach out to your security team or ask the Socket team for help at support@socket.dev.

Suggestion: Packages should be clear about which environment variables they access, and care should be taken to ensure they only access environment variables they claim to.

Mark the package as acceptable risk. To ignore this alert only in this pull request, reply with the comment @SocketSecurity ignore npm/rolldown@1.2.13. You can also ignore all packages with @SocketSecurity ignore-all. To ignore an alert for all future pull requests, use Socket's Dashboard to change the triage state of this alert.

Warn
Low priority
Environment variable access: npm rolldown

Env Vars: NAPI_RS_ENFORCE_VERSION_CHECK

Location: Package overview

From: package.json → npm/vite@8.3.4 → npm/rolldown@1.2.13

ℹ Read more on: This package | This alert | What is environment variable access?

Next steps: Take a moment to review the security alert above. Review the linked package source code to understand the potential risk. Ensure the package is not malicious before proceeding. If you're unsure how to proceed, reach out to your security team or ask the Socket team for help at support@socket.dev.

Suggestion: Packages should be clear about which environment variables they access, and care should be taken to ensure they only access environment variables they claim to.

Mark the package as acceptable risk. To ignore this alert only in this pull request, reply with the comment @SocketSecurity ignore npm/rolldown@1.2.13. You can also ignore all packages with @SocketSecurity ignore-all. To ignore an alert for all future pull requests, use Socket's Dashboard to change the triage state of this alert.

Warn
Low priority
Environment variable access: npm rolldown reads NAPI_RS_WASI_FLAVOR

Env Vars: NAPI_RS_WASI_FLAVOR

Location: Package overview

From: package.json → npm/vite@8.3.4 → npm/rolldown@1.2.13

ℹ Read more on: This package | This alert | What is environment variable access?

Next steps: Take a moment to review the security alert above. Review the linked package source code to understand the potential risk. Ensure the package is not malicious before proceeding. If you're unsure how to proceed, reach out to your security team or ask the Socket team for help at support@socket.dev.

Suggestion: Packages should be clear about which environment variables they access, and care should be taken to ensure they only access environment variables they claim to.

Mark the package as acceptable risk. To ignore this alert only in this pull request, reply with the comment @SocketSecurity ignore npm/rolldown@1.2.13. You can also ignore all packages with @SocketSecurity ignore-all. To ignore an alert for all future pull requests, use Socket's Dashboard to change the triage state of this alert.

Warn
Low priority
Environment variable access: npm rolldown reads NAPI_RS_FORCE_WASI

Env Vars: NAPI_RS_FORCE_WASI

Location: Package overview

From: package.json → npm/vite@8.3.4 → npm/rolldown@1.2.13

ℹ Read more on: This package | This alert | What is environment variable access?

Next steps: Take a moment to review the security alert above. Review the linked package source code to understand the potential risk. Ensure the package is not malicious before proceeding. If you're unsure how to proceed, reach out to your security team or ask the Socket team for help at support@socket.dev.

Suggestion: Packages should be clear about which environment variables they access, and care should be taken to ensure they only access environment variables they claim to.

Mark the package as acceptable risk. To ignore this alert only in this pull request, reply with the comment @SocketSecurity ignore npm/rolldown@1.2.13. You can also ignore all packages with @SocketSecurity ignore-all. To ignore an alert for all future pull requests, use Socket's Dashboard to change the triage state of this alert.

Warn
Low priority
Environment variable access: npm rolldown

Location: Package overview

From: package.json → npm/vite@8.3.4 → npm/rolldown@1.2.13

ℹ Read more on: This package | This alert | What is environment variable access?

Next steps: Take a moment to review the security alert above. Review the linked package source code to understand the potential risk. Ensure the package is not malicious before proceeding. If you're unsure how to proceed, reach out to your security team or ask the Socket team for help at support@socket.dev.

Suggestion: Packages should be clear about which environment variables they access, and care should be taken to ensure they only access environment variables they claim to.

Mark the package as acceptable risk. To ignore this alert only in this pull request, reply with the comment @SocketSecurity ignore npm/rolldown@1.2.13. You can also ignore all packages with @SocketSecurity ignore-all. To ignore an alert for all future pull requests, use Socket's Dashboard to change the triage state of this alert.

Warn
Low priority
Environment variable access: npm rolldown reads NODE_ENV

Env Vars: NODE_ENV

Location: Package overview

From: package.json → npm/vite@8.3.4 → npm/rolldown@1.2.13

ℹ Read more on: This package | This alert | What is environment variable access?

Next steps: Take a moment to review the security alert above. Review the linked package source code to understand the potential risk. Ensure the package is not malicious before proceeding. If you're unsure how to proceed, reach out to your security team or ask the Socket team for help at support@socket.dev.

Suggestion: Packages should be clear about which environment variables they access, and care should be taken to ensure they only access environment variables they claim to.

Mark the package as acceptable risk. To ignore this alert only in this pull request, reply with the comment @SocketSecurity ignore npm/rolldown@1.2.13. You can also ignore all packages with @SocketSecurity ignore-all. To ignore an alert for all future pull requests, use Socket's Dashboard to change the triage state of this alert.

Warn
Low priority
Environment variable access: npm rolldown reads CONSOLA_LEVEL

Env Vars: CONSOLA_LEVEL

Location: Package overview

From: package.json → npm/vite@8.3.4 → npm/rolldown@1.2.13

ℹ Read more on: This package | This alert | What is environment variable access?

Next steps: Take a moment to review the security alert above. Review the linked package source code to understand the potential risk. Ensure the package is not malicious before proceeding. If you're unsure how to proceed, reach out to your security team or ask the Socket team for help at support@socket.dev.

Suggestion: Packages should be clear about which environment variables they access, and care should be taken to ensure they only access environment variables they claim to.

Mark the package as acceptable risk. To ignore this alert only in this pull request, reply with the comment @SocketSecurity ignore npm/rolldown@1.2.13. You can also ignore all packages with @SocketSecurity ignore-all. To ignore an alert for all future pull requests, use Socket's Dashboard to change the triage state of this alert.

Warn
Low priority
Environment variable access: npm rolldown reads ROLLDOWN_TEST

Env Vars: ROLLDOWN_TEST

Location: Package overview

From: package.json → npm/vite@8.3.4 → npm/rolldown@1.2.13

ℹ Read more on: This package | This alert | What is environment variable access?

Next steps: Take a moment to review the security alert above. Review the linked package source code to understand the potential risk. Ensure the package is not malicious before proceeding. If you're unsure how to proceed, reach out to your security team or ask the Socket team for help at support@socket.dev.

Suggestion: Packages should be clear about which environment variables they access, and care should be taken to ensure they only access environment variables they claim to.

Mark the package as acceptable risk. To ignore this alert only in this pull request, reply with the comment @SocketSecurity ignore npm/rolldown@1.2.13. You can also ignore all packages with @SocketSecurity ignore-all. To ignore an alert for all future pull requests, use Socket's Dashboard to change the triage state of this alert.

Warn
Low priority
Environment variable access: npm vitest reads NODE_ENV

Env Vars: NODE_ENV

Location: Package overview

From: package.json → npm/vitest@5.0.3

ℹ Read more on: This package | This alert | What is environment variable access?

Next steps: Take a moment to review the security alert above. Review the linked package source code to understand the potential risk. Ensure the package is not malicious before proceeding. If you're unsure how to proceed, reach out to your security team or ask the Socket team for help at support@socket.dev.

Suggestion: Packages should be clear about which environment variables they access, and care should be taken to ensure they only access environment variables they claim to.

Mark the package as acceptable risk. To ignore this alert only in this pull request, reply with the comment @SocketSecurity ignore npm/vitest@5.0.3. You can also ignore all packages with @SocketSecurity ignore-all. To ignore an alert for all future pull requests, use Socket's Dashboard to change the triage state of this alert.

Warn

Ignoring alerts on:

  • tinyexec@1.3.1

View full report

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

Comment thread yarn.config.cjs Outdated
@cryptodev-2s
cryptodev-2s force-pushed the test/vitest-setup branch 3 times, most recently from 66adc1a to 7164c57 Compare September 29, 2026 14:38
@cryptodev-2s
cryptodev-2s requested a review from a team as a code owner September 29, 2026 14:38
@cryptodev-2s
cryptodev-2s removed this pull request from stack #10557 September 29, 2026 14:40
@cryptodev-2s
cryptodev-2s changed the base branch from main to test/approval-controller-assert-error-codes September 29, 2026 14:40
@cryptodev-2s
cryptodev-2s added this pull request to stack #10578 September 29, 2026 14:41
@cryptodev-2s
cryptodev-2s force-pushed the test/approval-controller-assert-error-codes branch from c812b32 to bb0a88a Compare September 30, 2026 07:04
@cryptodev-2s cryptodev-2s changed the title test: add Vitest alongside Jest without migrating any package test: add Vitest alongside Jest Oct 15, 2026

@mcmire mcmire left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for doing this, it's a long time coming. Left some comments below.

Comment thread tests/vitest/helpers.ts Outdated
Comment thread tests/helpers.ts

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.)

@cryptodev-2s cryptodev-2s Oct 15, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread types/vitest.d.ts Outdated
Comment thread types/vitest.d.ts Outdated
Comment thread jest.config.packages.cjs Outdated
Comment thread vitest.config.packages.mjs Outdated
Comment thread .gitignore Outdated
Comment thread oxlint-suppressions.json Outdated
Comment thread oxlint.config.ts Outdated
Comment thread test-runner-package-map.cjs
Naz-Ovh pushed a commit to 0x-fork/metamask-core that referenced this pull request Oct 15, 2026
## 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.
@cryptodev-2s
cryptodev-2s requested a review from mcmire October 15, 2026 22:38
@cryptodev-2s cryptodev-2s self-assigned this Oct 15, 2026

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ 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.

Comment thread package.json
"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",

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 3a2a6d2. Configure here.

This branch was successfully deployed

1 active (outdated) deployment
default-branch — f5a4a0b0 Deployed Sep 28, 2026 by cryptodev-2s via Determine whether this PR is a release PR #4821
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants