Describe the bug
Hi ππ½
When running tests in browser mode, module mocks work as expected on the first run. However, when rerunning the tests, the mocks are no longer applied β the original module code is used instead, causing test failures.
This looks like the same issue reported in #6633, which had been previously resolved.
Reproduction
Steps:
- Run tests in browser mode
- Confirm mocks work on first run
- Rerun tests (f / a in terminal or save file) β mocks no longer apply
Working reproduction: https://github.com/nizans/vitest-browser-mode-repro-puyhr8hs
https://stackblitz.com/~/github.com/nizans/vitest-browser-mode-repro-puyhr8hs?file=vitest-example/test-extend.ts:L1&initialPath=/__vitest_test__/?sessionId=60796f4e-5fa1-4a7c-a87d-505c77a1f05b
Version notes:
- Last working version I found: 3.0.9
- Reproduces on 3.2.4
- Also reproduces on 4.0.0-beta.6
System Info
System:
OS: macOS 15.6
CPU: (12) arm64 Apple M3 Pro
Memory: 7.48 GB / 36.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 22.13.0 - ~/.nvm/versions/node/v22.13.0/bin/node
npm: 10.9.2 - ~/.nvm/versions/node/v22.13.0/bin/npm
pnpm: 10.13.1 - ~/.nvm/versions/node/v22.13.0/bin/pnpm
bun: 1.2.2 - /opt/homebrew/bin/bun
Browsers:
Chrome: 138.0.7204.184
Safari: 18.6
npmPackages:
@vitejs/plugin-react: 5.0.0 => 5.0.0
@vitest/browser: ^3.2.4 => 3.2.4
@vitest/coverage-v8: 3.2.4 => 3.2.4
@vitest/ui: 3.2.4 => 3.2.4
playwright: ^1.54.2 => 1.54.2
vite: 7.1.0 => 7.1.0
vitest: ^3.2.4 => 3.2.4
vitest-browser-react: ^1.0.1 => 1.0.1
vitest-plugin-vis: ^3.4.1 => 3.4.1
Used Package Manager
pnpm
Validations
Describe the bug
Hi ππ½
When running tests in browser mode, module mocks work as expected on the first run. However, when rerunning the tests, the mocks are no longer applied β the original module code is used instead, causing test failures.
This looks like the same issue reported in #6633, which had been previously resolved.
Reproduction
Steps:
Working reproduction: https://github.com/nizans/vitest-browser-mode-repro-puyhr8hs
https://stackblitz.com/~/github.com/nizans/vitest-browser-mode-repro-puyhr8hs?file=vitest-example/test-extend.ts:L1&initialPath=/__vitest_test__/?sessionId=60796f4e-5fa1-4a7c-a87d-505c77a1f05b
Version notes:
System Info
System: OS: macOS 15.6 CPU: (12) arm64 Apple M3 Pro Memory: 7.48 GB / 36.00 GB Shell: 5.9 - /bin/zsh Binaries: Node: 22.13.0 - ~/.nvm/versions/node/v22.13.0/bin/node npm: 10.9.2 - ~/.nvm/versions/node/v22.13.0/bin/npm pnpm: 10.13.1 - ~/.nvm/versions/node/v22.13.0/bin/pnpm bun: 1.2.2 - /opt/homebrew/bin/bun Browsers: Chrome: 138.0.7204.184 Safari: 18.6 npmPackages: @vitejs/plugin-react: 5.0.0 => 5.0.0 @vitest/browser: ^3.2.4 => 3.2.4 @vitest/coverage-v8: 3.2.4 => 3.2.4 @vitest/ui: 3.2.4 => 3.2.4 playwright: ^1.54.2 => 1.54.2 vite: 7.1.0 => 7.1.0 vitest: ^3.2.4 => 3.2.4 vitest-browser-react: ^1.0.1 => 1.0.1 vitest-plugin-vis: ^3.4.1 => 3.4.1Used Package Manager
pnpm
Validations