[vitest-pool-workers] Adopt @msw/cloudflare and remove MSW workarounds - #13830
[vitest-pool-workers] Adopt @msw/cloudflare and remove MSW workarounds#13830penalosa wants to merge 8 commits into
Conversation
🦋 Changeset detectedLatest commit: 6a678d1 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
✅ All changesets look good |
|
UnknownError: ProviderInitError |
|
@penalosa Bonk workflow failed. Check the logs for details. View workflow run · To retry, trigger Bonk again. |
@cloudflare/autoconfig
@cloudflare/build-output-utils
@cloudflare/config
create-cloudflare
@cloudflare/deploy-helpers
@cloudflare/kv-asset-handler
miniflare
@cloudflare/pages-functions
@cloudflare/pages-shared
@cloudflare/unenv-preset
@cloudflare/vite-plugin
@cloudflare/vitest-pool-workers
@cloudflare/workers-auth
@cloudflare/workers-editor-shared
@cloudflare/workers-utils
wrangler
commit: |
29932c6 to
8555c1a
Compare
|
/bonk Please merge in origin/main and resolve the conflicts in this PR. Also update to the latest version of @msw/cloudflare |
|
To https://github.com/cloudflare/workers-sdk.git |
|
@penalosa Bonk workflow failed. Check the logs for details. View workflow run · To retry, trigger Bonk again. |
8555c1a to
300d0c9
Compare
Remove the internal msw/node → msw/native remap and globalThis.fetch
rebinding hacks from vitest-pool-workers. Recent MSW versions (2.14+)
no longer need either workaround.
The request-mocking fixture now uses the official @msw/cloudflare
integration via setupNetwork() and covers three call patterns: direct
fetch from the runner DO, exports.default.fetch (which dispatches into
a fresh request I/O context), and WebSocket interception.
Dependencies:
- msw bumped to ^2.14.6 (stable npm release; the cross-context
AbortSignal fix landed in 2.14.4)
- @msw/cloudflare tracks the pkg.pr.new @beta tag, which adds
exports.default.fetch support
…tion
Vitest 4.1's bundled type chunks broke the previous `declare module "vitest" { interface ProvidedContext {} }` pattern when the file only contained the augmentation block. Adding an explicit `import "vitest"` makes the augmentation reach the chunk's interface declaration.
300d0c9 to
8f04aba
Compare
|
Codeowners approval required for this PR:
Show detailed file reviewers
|
petebacondarwin
left a comment
There was a problem hiding this comment.
The Devin issue appears to be valid? Do you just need to update the README if they bug is resolved?
# Conflicts: # pnpm-lock.yaml
|
Codeowners approval required for this PR:
Show detailed file reviewers |
workers-devprod
left a comment
There was a problem hiding this comment.
Codeowners reviews satisfied
Migrates the
request-mockingexample fixture to use the new official@msw/cloudflareintegration, and drops two longstanding workarounds that were only there to make MSW work inside workerd:msw/lib/node/index.mjs→msw/nativeremap inpackages/vitest-pool-workers/src/pool/plugin.ts(added back whensetupServer()frommsw/nodecouldn't run in workerd).globalThis.fetch = (...) => originalFetch.call(...)self-rebinding inpackages/vitest-pool-workers/src/worker/fetch-mock.ts(added so MSW'sFetchInterceptorcould replace a configurablefetchglobal).With MSW >= 2.14 and
@mswjs/interceptors>= 0.41, neither workaround is required: the interceptor'sapplyPatchhandles non-configurable-but-writable globals via theowner[key] = ...fallback, and the MSW Cloudflare integration provides asetupNetwork()API designed to run directly inside workerd.Other changes:
mswversion from2.12.4to^2.14.3to satisfy@msw/cloudflare's>=2.14.1peer dep.@msw/cloudflareas a dev dep on the fixtures workspace (installed frompkg.pr.newsince the package isn't yet on the npm registry).request-mocking/test/imperative.test.ts(which usedvi.spyOn(globalThis, "fetch")to mock GET/POST/WebSocket) withrequest-mocking/test/websocket.test.ts, which demonstrates declarative outbound-WebSocket mocking using MSW'sws.linkAPI. The GET/POST cases are already covered by the updateddeclarative.test.ts.The new
request-mockingfixture exercises the full@msw/cloudflaresurface area used in workerd:declarative.test.tshttp.get/http.posthandlers viasetupNetwork().use(...)websocket.test.tsnew WebSocket(url)intercepted viaws.link(...)+addEventListener("connection", ...)@msw/cloudflareintegration itself is documented at https://github.com/mswjs/cloudflare.