Prerequisites
Environment check
Browsers
Firefox
Reproduction repository
https://github.com/hjri/msw-examples/tree/main/examples/with-vitest
Reproduction steps
Following this recipe:
https://mswjs.io/docs/recipes/vitest-browser-mode
In linked repository there are two tests - "Endpoint A" and "Endpoint B", both use extended test that exposes worker. Both tests do worker.use() to set up mocking for the endpoint they're testing. Expectation is that both tests pass, but reality is that one tests passes and other fails with 404. Which one fails depends on test execution order - first one passes, second fails.
My assumption is that setupWorker() should only create and register serviceworker once, but somehow in firefox with isolation it creates it for every test file (because of isolation) and second setupWorker() fails to register new serviceworker.
P.S. in linked repository somehow using headless: true fixes the problem, however in actual project it doesn't. Only real solution is to use chromium instead of firefox.
Current behavior
First test to execute succeeds, second fails.
Expected behavior
Both succeed
Prerequisites
Environment check
mswversionBrowsers
Firefox
Reproduction repository
https://github.com/hjri/msw-examples/tree/main/examples/with-vitest
Reproduction steps
Following this recipe:
https://mswjs.io/docs/recipes/vitest-browser-mode
In linked repository there are two tests - "Endpoint A" and "Endpoint B", both use extended
testthat exposesworker. Both tests doworker.use()to set up mocking for the endpoint they're testing. Expectation is that both tests pass, but reality is that one tests passes and other fails with404. Which one fails depends on test execution order - first one passes, second fails.My assumption is that
setupWorker()should only create and register serviceworker once, but somehow in firefox with isolation it creates it for every test file (because of isolation) and secondsetupWorker()fails to register new serviceworker.P.S. in linked repository somehow using
headless: truefixes the problem, however in actual project it doesn't. Only real solution is to use chromium instead of firefox.Current behavior
First test to execute succeeds, second fails.
Expected behavior
Both succeed