-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Closed
Labels
feat: browserIssues and PRs related to the browser runnerIssues and PRs related to the browser runnerp3-minor-bugAn edge case that only affects very specific usage (priority)An edge case that only affects very specific usage (priority)
Description
Describe the bug
Whenever you mock a module in browser mode and rerun the tests, mocks are non longer effective (the original module is used instead).
EDIT: this issue only occurrs when the MSW worker is active... so I'm not sure if it's a bug or if there is an explanation for the behaviour.
Reproduction
- Configure Vitest with browser mode (playwright + chromium)
- Add
mswas dependency and initialize the worker script withpnpm exec init public --save - In
vitest-setup.ts, start the worker withbeforeAll(async () => await worker.start()); - Create a
mock-me.tsfile withexport default "original";for instance - In
vitest-setup.ts, mock the module withvi.mock("./mock-me", () => ({ default: "mocked" })); - Import and log the variable in the tested component
- Run
vitest - console prints
"mocked" - Rerun the test by pressing
rorain the terminal - console prints
"original"
Repo: https://github.com/foxaltus/vitest-browser-mode-repro
System Info
System:
OS: Windows 11 10.0.22631
CPU: (8) x64 11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz
Memory: 6.77 GB / 31.73 GB
Binaries:
Node: 18.20.2 - C:\Program Files\nodejs\node.EXE
Yarn: 1.22.19 - ~\AppData\Roaming\npm\yarn.CMD
npm: 10.5.0 - C:\Program Files\nodejs\npm.CMD
pnpm: 9.9.0 - ~\AppData\Local\pnpm\pnpm.EXE
Browsers:
Edge: Chromium (127.0.2651.105)
Internet Explorer: 11.0.22621.3527
npmPackages:
@vitejs/plugin-react: ^4.3.1 => 4.3.1
@vitest/browser: ^2.1.1 => 2.1.1
@vitest/coverage-v8: ^2.1.1 => 2.1.1
vite: ^5.4.8 => 5.4.8
vitest: ^2.1.1 => 2.1.1Used Package Manager
pnpm
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
feat: browserIssues and PRs related to the browser runnerIssues and PRs related to the browser runnerp3-minor-bugAn edge case that only affects very specific usage (priority)An edge case that only affects very specific usage (priority)