fix: reduce E2E test flakiness by mocking unmocked endpoints#427
Open
fix: reduce E2E test flakiness by mocking unmocked endpoints#427
Conversation
Flaky E2E tests were failing because only auth endpoints were mocked — GET /user/:id (profile fetch) and POST /data-requests (create submit) fell through MSW's onUnhandledRequest: bypass and hit the real backend, whose latency/availability drove the flakes. Also fixes a JWT claim mismatch: the mock access token emitted email, but the auth store reads user_email (src/stores/auth.js:56), so user.email was undefined after sign-in. Closes #425 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
joshuagraber
approved these changes
May 2, 2026
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
Resolves the flaky E2E failures tracked in #425.
Root cause:
e2e/mocks/handlers/index.jsonly registeredauthHandlers. Every other API call (GET /user/:id,POST /data-requests, etc.) fell through MSW'sonUnhandledRequest: 'bypass'and hit the real dev/prod backend, whose latency and availability drove the flakes. Three specs failed repeatedly across recent CI runs for exactly this reason:e2e/auth/sign-in.spec.js— post-login redirecte2e/data-request/create.spec.js—waitForResponseonPOST /data-requestse2e/profile/index.spec.js—[data-test=profile_email]never became visible becauseGET /user/:idwas unmockedThis PR:
GET ${VITE_API_URL_V3}/user/:idandPOST ${VITE_API_URL}/data-requests.USER_BASE_V3_URL,DATA_REQUESTS_BASE_URL, and a sharedTEST_USERconstant frome2e/fixtures/constants.js.emailclaim, butsrc/stores/auth.js:56readsaccessTokenParsed.user_email— souser.emailwas undefined after a mocked sign-in. Now emitsuser_email.Builds on #413, which mocked the login endpoint itself but didn't cover the downstream fetches that auth-dependent tests also need.
Test plan
npx playwright test e2e/profile/index.spec.js e2e/data-request/create.spec.js e2e/auth/sign-in.spec.jsCloses #425