test: scaffold msw for integration tests#3537
Conversation
|
Oxygen deployed a preview of your
Learn more about Hydrogen's GitHub integration. |
|
🤖 Code Review · #projects-dev-ai for questions ✅ Complete - 3 findings 📋 History✅ 1 findings → ❌ Failed → ✅ 3 findings |
|
These findings are in files not modified by this PR and cannot be posted as inline comments.
This PR removes Impact:
|
Why: PR review identified a latent bug (localStorage polyfill skipped in workerd), type safety gaps, magic numbers, dead code, and structural inconsistencies with existing fixture patterns. How: Fix hasWorkingLocalStorage null detection by adding an explicit null check before the try/catch — optional chaining silently no-ops when localStorage is undefined, causing the function to return true and skip the polyfill in exactly the environment (workerd) where it's needed. Augment the global Env interface with HYDROGEN_E2E_MSW_SCENARIO to remove the unsafe double cast in getMswScenario. Extract E2E_TUNNEL_HOSTNAME and SESSION_TTL_IN_MS as named constants with "why" comments. Add JSDoc to ensureNodeProcessForMsw explaining the NODE_ENV/versions.node strategy, and a comment on module-level currentMswScenarioMeta explaining the architectural constraint. Convert AccountUtil to a Playwright fixture (matching CartUtil, DiscountUtil, GiftCardUtil patterns), remove the pass-through expectLoggedInState method, and update account.spec.ts to use the fixture. Add explicit MswScenarioMeta return type and defensive throw after Map.get() in getHandlersForScenario. Remove dead code guard in graphql.ts parseOperation (regex only captures 'query'|'mutation'). Remove unused env option from DevServer.
…ation We've agreed to prioritise test utilities that take a `page` arg over Playwright fixtures that override the test function signature. Revert the AccountUtil fixture registration while keeping all other review feedback changes from the prior commit.
Why: PR reviewers (itsjustriley, kdaviduik) identified several improvements to the MSW e2e test scaffolding introduced in #3537. How: - Inline AccountUtil into test; the class was a shallow wrapper adding no behavior beyond direct Playwright assertions - Use MSW_SCENARIOS constant instead of raw strings in handlers.ts and account.spec.ts for a single source of truth on scenario keys - Add "why" JSDoc to ensureLocalStorage and ensureBroadcastChannel explaining what MSW expects and why workerd needs polyfills - Clone request before passing to new Request() to prevent Fetch spec body consumption (future-proofs for POST/mutation scenarios) - Lazy-init createCookieSessionStorage keyed on SESSION_SECRET to avoid re-creating on every request - Add inline comment on cookie stripping logic - Remove unnecessary optional chaining on scenarioMeta (return type guarantees non-undefined) - Replace `as` type cast with runtime narrowing guard in graphql.ts parseOperation for proper TypeScript narrowing
this pr scaffolds msw mocks to the CAAPI so we can mock users, past orders, etc