Repository navigation
feat(browser): mock modules through an import map - #11534
Merged
Merged
Conversation
✅ Deploy Preview for vitest-dev ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
sheremet-va
marked this pull request as ready for review
October 9, 2026 13:46
…ap-mocks # Conflicts: # test/browser/specs/mocking.test.ts
6 tasks done
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
vi.mockregisters an import map rule in the tester document that points the module URL at its mocked version (automock, the__mocks__file, or a factory shim whose export names are parsed from the original module), so providers never intercept requests and the HTTP cache stays on. The orchestrator probes whether the browser accepts an import map after a module has loaded;browser.importMapMocksforces it on or off. Firefox needsdom.multiple_import_maps.enabled; the Playwright provider sets it. A rejected mock registration now fails the import instead of being dropped.Measured with https://github.com/ubugeeei-reproductions/js-test-runner-competition (Chromium, 9 workers, 500 files, 962 modules, 1,883 mocks per suite, wall time, median of 3 interleaved rounds):
importMapMocks: falseKnown limits:
vi.unmockandvi.doUnmockcannot remove a rule (this is already the case), a factory cannot add exports the original does not declare (similar toviteModuleRunner: false), and a module imported beforevi.mockfails with an explicit error (which is a good thing).Fixes #11493
Fixes #8246