Skip to content

test: scaffold msw for integration tests#3537

Merged
fredericoo merged 15 commits intomainfrom
fb-msw
Mar 20, 2026
Merged

test: scaffold msw for integration tests#3537
fredericoo merged 15 commits intomainfrom
fb-msw

Conversation

@fredericoo
Copy link
Contributor

@fredericoo fredericoo commented Mar 5, 2026

this pr scaffolds msw mocks to the CAAPI so we can mock users, past orders, etc

@shopify
Copy link
Contributor

shopify bot commented Mar 5, 2026

Oxygen deployed a preview of your fb-msw branch. Details:

Storefront Status Preview link Deployment details Last update (UTC)
Skeleton (skeleton.hydrogen.shop) ✅ Successful (Logs) Preview deployment Inspect deployment March 20, 2026 1:17 PM

Learn more about Hydrogen's GitHub integration.

@fredericoo fredericoo changed the title fb msw test: scaffold msw for integration tests Mar 6, 2026
@fredericoo fredericoo marked this pull request as ready for review March 6, 2026 14:57
@fredericoo fredericoo requested a review from a team as a code owner March 6, 2026 14:57
@binks-code-reviewer
Copy link

binks-code-reviewer bot commented Mar 6, 2026

🤖 Code Review · #projects-dev-ai for questions
React with 👍/👎 or reply — all feedback helps improve the agent.

Complete - 3 findings

📋 History

✅ 1 findings → ❌ Failed → ✅ 3 findings

@binks-code-reviewer
Copy link

⚠️ Findings outside the diff

These findings are in files not modified by this PR and cannot be posted as inline comments.


templates/skeleton/storefrontapi.generated.d.ts:714Unrelated deletion from generated types can break TS consumers (StoreRobotsQuery removed)

This PR removes StoreRobotsQuery and its variables type and deletes its entry from GeneratedQueryTypes. This is unrelated to MSW scaffolding and can cause compilation failures anywhere that imports/uses that generated query type (or uses that document string key).

Impact:

  • TypeScript builds/tests can fail, or code that relied on the types becomes any/breaks.
  • Impacts any consumer of the skeleton types in the monorepo.

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.
@itsjustriley itsjustriley marked this pull request as draft March 17, 2026 17:22
@fredericoo fredericoo marked this pull request as ready for review March 17, 2026 19:30
…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
@fredericoo fredericoo marked this pull request as draft March 19, 2026 19:34
@fredericoo fredericoo marked this pull request as ready for review March 19, 2026 19:37
@itsjustriley itsjustriley self-requested a review March 20, 2026 10:59
@fredericoo fredericoo requested a review from kdaviduik March 20, 2026 12:31
@fredericoo fredericoo merged commit bce3933 into main Mar 20, 2026
18 of 19 checks passed
@fredericoo fredericoo deleted the fb-msw branch March 20, 2026 14:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants