Repository navigation
test: run utils on Vitest - #10871
Merged
Merged
Conversation
cryptodev-2s
force-pushed
the
test/vitest-utils
branch
from
October 19, 2026 19:51
4e5140a to
7e2d768
Compare
cryptodev-2s
force-pushed
the
test/vitest-utils
branch
from
October 20, 2026 09:03
7e2d768 to
8202304
Compare
cryptodev-2s
commented
Oct 20, 2026
cryptodev-2s
commented
Oct 20, 2026
| jest.spyOn(Object, 'getPrototypeOf').mockImplementationOnce(() => { | ||
| throw new Error(); | ||
| }); | ||
| const someObject = new Proxy( |
Contributor
Author
There was a problem hiding this comment.
Vitest reads Object.getPrototypeOf itself while installing a mock implementation, so a throwing proxy trap stands in for a spy here.
cryptodev-2s
enabled auto-merge
October 20, 2026 09:18
cryptodev-2s
commented
Oct 20, 2026
|
|
||
| it.each(JSON_VALIDATION_FIXTURES)( | ||
| 'works on complex object %o', | ||
| 'works on complex object %#', |
Contributor
Author
There was a problem hiding this comment.
Some fixtures throw when formatted, so use their indices
Mrtenz
requested changes
Oct 20, 2026
Mrtenz
approved these changes
Oct 20, 2026
This was referenced Oct 20, 2026
Naz-Ovh
pushed a commit
to 0x-fork/metamask-core
that referenced
this pull request
Oct 21, 2026
## Explanation Use Vitest's module-promise overload for the remaining partial mock factories in keyring-controller, phishing-controller, and user-operation-controller. Partial factories receive the inferred `importOriginal` helper, removing the repeated module path and explicit `typeof import(...)` generic. ## References - Follow-up to MetaMask#10871. - [Vitest's typed module mock API](https://vitest.dev/api/vi.html#vi-mock). ## 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] > **Low Risk** > Test-only mock setup refactors with no production code or runtime behavior changes. > > **Overview** > This PR **refactors partial `vi.mock` factories** in controller test files to Vitest’s **typed module-promise overload**: `vi.mock(import('…'), async (importOriginal) => ({ ...(await importOriginal()), … }))`. > > Affected tests: **`uuid` `v4`** stub in keyring-controller, and **`@metamask/controller-utils`** partial mocks (`safelyExecuteWithTimeout` or `query`) in phishing-controller and user-operation-controller. Behavior is unchanged—still spreads the real module and overrides specific exports—but **drops duplicate module path strings and explicit `typeof import(...)` generics** in favor of inferred `importOriginal`. Follow-up to the same pattern used in MetaMask#10871. > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit a5b1baa. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup> <!-- /CURSOR_SUMMARY -->
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Explanation
Moves
@metamask/utilsto Vitest.References
Checklist
no-changeloglabel.Note
Low Risk
Test and dev-tooling only; production
@metamask/utilsAPIs are unchanged.Overview
Migrates
@metamask/utilsfrom Jest + tstyche to Vitest, aligning it with other Vitest packages in the monorepo.Tooling: Removes
jest.config.cjsand Jest-related scripts/deps; addsvitest.config.jswith 100% coverage thresholds andyarn test→vitest.@metamask/utilsis dropped from the Jest workspace map. Sharedvitest.config.packages.jsnow enablestypecheckglobally (duplicate config removed frommessenger).Tests: Unit suites switch to Vitest (
vi.mock,vi.spyOn,vi.useFakeTimers, etc.), including replacements forjest-whenand globalErrorstubbing. Formertstychefiles become*.test-d.tsusingexpectTypeOf.tsconfigdrops Jest types and usesskipLibCheckfor web3; build excludes*.test-d.tsinstead of*.tst.ts.No changes to published library runtime code.
Reviewed by Cursor Bugbot for commit 2642d57. Bugbot is set up for automated code reviews on this repo. Configure here.