test: Start MSW worker once per file instead of per test#229
Open
Amund211 wants to merge 1 commit into
Open
Conversation
Previously the mswTest fixture called worker.start() before every test. Each call re-registers the service worker and round-trips through the browser — cheap, but it runs once per test × ~175 UI tests × 2 browsers, and adds measurable overhead on the critical path (webkit, which runs serially in CI). Move the start() call to a beforeAll hook in the existing per-file vitest setup file. resetHandlers() in afterEach still isolates tests from each other. Matches the pattern in the official MSW recipe for vitest browser mode (https://mswjs.io/docs/recipes/vitest-browser-mode). The mswTest fixture is kept so existing test imports still work and so tests can still receive `worker` as a context param if they need it. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Deploying rainbow with
|
| Latest commit: |
2ed936c
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://af4c93c3.rainbow-ctx.pages.dev |
| Branch Preview URL: | https://amund-msw-start-once-per-fil.rainbow-ctx.pages.dev |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR optimizes the UI (Vitest browser/Playwright) test runtime by avoiding repeated MSW service worker startup per test, while keeping per-test handler isolation.
Changes:
- Start the MSW
workerinbeforeAllvia the UI test setup file (setupFiles) instead of inside the per-testmswTestfixture. - Reset MSW handlers in
afterEachto preserve test isolation. - Simplify the
mswTestfixture to only expose the sharedworkerin test context.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/test/setup.ts | Starts MSW worker once via beforeAll and resets handlers via afterEach for UI tests. |
| src/test/msw-test.ts | Removes per-test worker startup/teardown and keeps only the context fixture exposure. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Expected to shave noticeable time off the UI test run, most visibly on webkit (which runs with `--no-file-parallelism` in CI and sits on the critical path).
Test plan
🤖 Generated with Claude Code