Skip to content

fix: reduce E2E test flakiness by mocking unmocked endpoints#427

Open
maxachis wants to merge 4 commits intodevfrom
fix/425-e2e-flaky-tests
Open

fix: reduce E2E test flakiness by mocking unmocked endpoints#427
maxachis wants to merge 4 commits intodevfrom
fix/425-e2e-flaky-tests

Conversation

@maxachis
Copy link
Copy Markdown
Contributor

Summary

Resolves the flaky E2E failures tracked in #425.

Root cause: e2e/mocks/handlers/index.js only registered authHandlers. Every other API call (GET /user/:id, POST /data-requests, etc.) fell through MSW's onUnhandledRequest: '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 redirect
  • e2e/data-request/create.spec.jswaitForResponse on POST /data-requests
  • e2e/profile/index.spec.js[data-test=profile_email] never became visible because GET /user/:id was unmocked

This PR:

  • Adds MSW handlers for GET ${VITE_API_URL_V3}/user/:id and POST ${VITE_API_URL}/data-requests.
  • Exports USER_BASE_V3_URL, DATA_REQUESTS_BASE_URL, and a shared TEST_USER constant from e2e/fixtures/constants.js.
  • Fixes a JWT-claim mismatch in the existing auth mock: the access token emitted the email claim, but src/stores/auth.js:56 reads accessTokenParsed.user_email — so user.email was undefined after a mocked sign-in. Now emits user_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

  • CI E2E job green on this PR
  • Re-run the CI a few times to confirm the previously flaky specs stay green
  • Manual: npx playwright test e2e/profile/index.spec.js e2e/data-request/create.spec.js e2e/auth/sign-in.spec.js

Closes #425

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>
@maxachis maxachis requested a review from joshuagraber as a code owner April 13, 2026 19:09
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.

2 participants