#2757·msw

Vitest isolation breaks setupWorker in firefox

Author: hjriCreated Jun 18, 2026Updated Aug 30, 2026
Labelsbugscope:browserneeds:triage

Prerequisites

Environment check

  • I'm using the latest msw version
  • I'm using Node.js version 20 or higher

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