Repository navigation
chore: migrate tests to vitest 4 and the Cloudflare vitest plugin - #8
Merged
Merged
Conversation
@cloudflare/vitest-pool-workers is replaced by @cloudflare/vitest-plugin (claimed by its upstream codemod path). The plugin drops fetchMock from cloudflare:test, so outbound mocks move to MSW (msw 3 + @msw/cloudflare). helpers.js is the only place the mocking mechanics lived, so rewrite tests stayed minimal; Semantics preserved via one-shot `once: true` handlers and a setup-level guard that fails tests on unmocked outbound requests. Two behavioural adaptations the new runtime requires: - Static assets are no longer routed in front of the Worker under SELF; the static test now asserts the content through the ASSETS binding, matching what production serves. - Transport-level failure simulation moved from HttpResponse.error to an unparseable 599 upstream body, because HttpResponse.error leaves unhandled rejections (red CI) and throwing handlers surface as 500 responses instead of rejected fetches. Both drive the same before-JSON branches the worker handles, and the affected test names now say so.
- Rewritten webhook-failure test now asserts the delivery attempt (one call,
token-failure text kept) instead of passing with zero assertions; the test
name matches the non-2xx branch it exercises, and the fetch-rejection
branch is documented as not representable under MSW.
- GET / routing is pinned again at config level (vitest.node.config.js +
test/config-pin.test.js): wrangler.jsonc must keep the join page on the
asset router (directory -> public, no run_worker_first) and the files must
exist, so a production routing regression cannot pass the suite.
- Unmatched outbound requests are refused by the network itself via
network.configure({ onUnhandledFrame: 'error' }) instead of passing
through to the real upstreams mid-test; afterEach stays as a backstop and
the tracked list resets per test.
- mockUsersList reads the expected Authorization value from the same shared
constant the configs bind as SLACK_TOKEN (test/tokens.js); the dead
'headers' argument is gone from the call site.
- The 599 'fails before a JSON answer' cases duplicated existing non-JSON
mocks under MSW; removed with their now-unused helpers.
mroderick
marked this pull request as ready for review
November 1, 2026 20:48
Deploy.yml only tests pushes to main, so PRs had no check at all. This adds a test-only CI workflow for pull requests that mirrors the deploy job's steps (node 22, npm ci, npm test). Main keeps its gate from the deploy workflow, so there is no duplicated main-branch run.
The migration lockfile was written by npm from the local Node 26 install; npm ci under the CI's node 22 reported missing transitive entries. The lock is now generated and verified under node 22 (npm 10.9.9), the same pair the workflows pin.
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
Migrates the test suite from vitest 3 +
@cloudflare/vitest-pool-workersto vitest 4 +@cloudflare/vitest-pluginplus MSW for outbound request mocking, ahead of theinvite_outcomelogging work (#1 in the stack, this is the dependency).cloudflare:testlosesfetchMockunder the plugin; the mocking mechanics lived only intest/helpers.js, so the per-test files keep calling the same helpers.fetchMock.disableNetConnect()loudness.Review notes
Mechanics to check
{ once: true }MSW handlers (first-in/first-out) intest/helpers.js.HttpResponse.error()leaked unhandled rejections andthrowin handlers surfaced as 500 responses instead of rejected fetches, so unreachable-upstream mocks use an unparseable 599 reply; the two affected test names now say "fails before a JSON answer".SELF/exports.defaultstraight to the Worker, with no asset router in front.test/static.test.jsasserts the join page through theASSETSbinding instead.package-lock.jsondominates the diff; dependency lines inpackage.jsontell the story.Not done here
invite_outcomelogging needs this stack first (next PR in the stack).