chore: rework msw usage to support more runtimes#151
Conversation
fc9a4a4 to
8e265fe
Compare
8e265fe to
adb1df5
Compare
963fb5e to
d663b5c
Compare
10ba2d3 to
38613e8
Compare
|
Warning Review limit reached
More reviews will be available in 43 minutes and 37 seconds. Learn how PR review limits work. Your organization has run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThis PR establishes a centralized test utilities package ( ChangesTest utilities and MSW migration
🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Warning Review ran into problems🔥 ProblemsStopped waiting for pipeline failures after 30000ms. One of your pipelines takes longer than our 30000ms fetch window to run, so review may not consider pipeline-failure results for inline comments if any failures occurred after the fetch window. Increase the timeout if you want to wait longer or run a Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
- migrate passkey-client and server-mfa-client specs off msw/node so they load under Cloudflare Workers - add in-memory localStorage polyfill to avoid msw cookieStore hitting Deno's SQLite-backed localStorage (database is locked) - correct package name define in server-js workers vitest config
|
@coderabbitai review |
✅ Action performedReview finished.
|
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/test-utils/src/http.ts`:
- Around line 21-23: The listen/close pair currently overwrites originalFetch on
repeated listen() calls and blindly restores globalThis.fetch on close(),
causing corruption; update listen() (the function that assigns originalFetch and
patches globalThis.fetch) to only set originalFetch if it is currently
undefined/null (i.e., preserve the first saved original fetch) and make close()
check that globalThis.fetch is still the patched function before restoring
originalFetch and then clear originalFetch so repeated close()/listen() cycles
are safe; reference the originalFetch variable and the patched globalThis.fetch
assignment in listen() and the restore logic in close().
- Around line 6-7: The MockHttpServer interface wrongly types resetHandlers as
parameterless while the implementation allows replacing handlers; update the
resetHandlers signature in the interface to accept handler arguments like use
does (e.g., resetHandlers: (...handlers: RequestHandler[]) => void or
resetHandlers: (handlers?: RequestHandler[] | RequestHandler) => void) so
callers can pass replacement handlers; adjust both occurrences of resetHandlers
in the interface to match the implementation.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 1da5f806-3ade-4367-8453-a706a9984207
📒 Files selected for processing (27)
.github/workflows/runtime-bun.yml.github/workflows/runtime-deno.yml.github/workflows/runtime-workers.ymlpackages/auth0-api-js/package.jsonpackages/auth0-api-js/src/api-client.spec.tspackages/auth0-api-js/src/dpop-api.scenarios.spec.tspackages/auth0-api-js/src/index.workers.spec.tspackages/auth0-api-js/src/test-utils/workers-polyfills.tspackages/auth0-api-js/vitest.config.tspackages/auth0-api-js/vitest.config.workers.tspackages/auth0-auth-js/package.jsonpackages/auth0-auth-js/src/auth-client.spec.tspackages/auth0-auth-js/src/mfa/mfa-client.spec.tspackages/auth0-auth-js/src/passkey/passkey-client.spec.tspackages/auth0-auth-js/src/test-utils/workers-polyfills.tspackages/auth0-auth-js/vitest.config.tspackages/auth0-auth-js/vitest.config.workers.tspackages/auth0-server-js/package.jsonpackages/auth0-server-js/src/mfa/server-mfa-client.spec.tspackages/auth0-server-js/src/server-client.spec.tspackages/auth0-server-js/src/test-utils/workers-polyfills.tspackages/auth0-server-js/vitest.config.tspackages/auth0-server-js/vitest.config.workers.tspackages/test-utils/package.jsonpackages/test-utils/src/http.tspackages/test-utils/src/localstorage-polyfill.tspackages/test-utils/src/workers-polyfill.ts
💤 Files with no reviewable changes (1)
- packages/auth0-api-js/src/index.workers.spec.ts
- type resetHandlers to accept replacement handlers, matching the impl - make listen/close idempotent so repeated cycles don't corrupt global fetch
Description
msw/nodewith a custommock-http.tsfetch-patching implementation across all packages (auth0-auth-js,auth0-server-js,auth0-api-js) so tests run on Bun, Deno, and Cloudflare Workers without Node.jsHTTP interceptors
BroadcastChannelstub polyfill for the Workers runtime, where MSW imports it unconditionally but it is not available as a globalvitest.config.workers.tsandwrangler.tomlin each package to wire up the new test utilitiesReferences
N/A
Testing
Checklist
Summary by CodeRabbit