Skip to content

test: upgrade msw to 2.13 and drop worker.stop() from test fixture#228

Merged
Amund211 merged 1 commit into
mainfrom
amund/msw-2.13-worker-fix
Apr 22, 2026
Merged

test: upgrade msw to 2.13 and drop worker.stop() from test fixture#228
Amund211 merged 1 commit into
mainfrom
amund/msw-2.13-worker-fix

Conversation

@Amund211
Copy link
Copy Markdown
Owner

Summary

  • Bump msw from ^2.12.14 to ^2.13.3.
  • Drop worker.stop() from the per-test MSW fixture.

Why

msw 2.13.0 shipped a network-source-architecture refactor (mswjs/msw#2650) that altered the worker lifecycle. Our fixture called worker.start() before each test and worker.stop() after, which on 2.13 creates a race — the next test's start() can't take over before requests are issued, so they bypass the worker and hit Vite directly. Symptom: Failed to fetch and 20s expect.poll timeouts on every test that triggers a fetch (~13 UI tests).

The upstream fix is simply to not call worker.stop(). This matches the official vitest-browser-mode recipe:

We recommend skipping worker.stop() at the end of the fixture because there's no practical reason for it.

Upstream issue: mswjs/msw#2706.

Test plan

  • pnpm run test:ui → 196/196 pass, ~18s (baseline is ~25s)
  • pnpm run test:unit runs via pre-commit hook
  • CI green

🤖 Generated with Claude Code

Copilot AI review requested due to automatic review settings April 22, 2026 13:43
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates the UI testing stack to accommodate MSW’s worker lifecycle changes introduced in msw@2.13.x, preventing flaky fetch behavior in Vitest browser-mode tests.

Changes:

  • Upgraded msw to 2.13.3.
  • Updated the MSW Vitest fixture to stop calling worker.stop() after each test.
  • Refreshed pnpm-lock.yaml to reflect the new dependency graph.

Reviewed changes

Copilot reviewed 2 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/test/msw-test.ts Removes per-test worker.stop() teardown to avoid MSW 2.13 lifecycle race.
package.json Bumps msw devDependency range to ^2.13.3.
pnpm-lock.yaml Updates lock entries for msw@2.13.3 and related transitive deps.
Files not reviewed (1)
  • pnpm-lock.yaml: Language not supported

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread pnpm-lock.yaml Outdated
@Amund211 Amund211 force-pushed the amund/msw-2.13-worker-fix branch from e5c8ea0 to 3d4c10e Compare April 22, 2026 13:47
@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages Bot commented Apr 22, 2026

Deploying rainbow with  Cloudflare Pages  Cloudflare Pages

Latest commit: ba791c9
Status: ✅  Deploy successful!
Preview URL: https://bfd5c009.rainbow-ctx.pages.dev
Branch Preview URL: https://amund-msw-2-13-worker-fix.rainbow-ctx.pages.dev

View logs

@Amund211 Amund211 requested a review from Copilot April 22, 2026 13:47
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 3 changed files in this pull request and generated no new comments.

Files not reviewed (1)
  • pnpm-lock.yaml: Language not supported

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

msw 2.13 shipped a "network source architecture" refactor (mswjs/msw#2650)
that altered the worker lifecycle. Our fixture called worker.start() before
each test and worker.stop() after, which on 2.13 creates a race: the next
test's start() can't take over before requests are made, so they bypass the
worker and hit Vite directly — surfacing as "Failed to fetch" and 20s
timeouts on every test that makes a request.

The upstream fix is to simply not call worker.stop(). This matches the
official vitest-browser-mode recipe
(https://mswjs.io/docs/recipes/vitest-browser-mode).

Tracked upstream at mswjs/msw#2706.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@Amund211 Amund211 force-pushed the amund/msw-2.13-worker-fix branch from 3d4c10e to ba791c9 Compare April 22, 2026 13:59
@Amund211 Amund211 merged commit 1553bfb into main Apr 22, 2026
8 checks passed
@Amund211 Amund211 deleted the amund/msw-2.13-worker-fix branch April 22, 2026 14:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants