-
Notifications
You must be signed in to change notification settings - Fork 22
fix: decouple build + e2e from a live backend (staging) #225
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
senamakel
merged 2 commits into
tinyhumansai:main
from
senamakel:fix/decouple-build-e2e-from-staging
Jul 5, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| import { expect, test, type Route } from "@playwright/test"; | ||
|
|
||
| // Hermetic smoke test: the web app must boot and render its shell without any | ||
| // live backend. Unlike the other e2e specs (gated behind E2E_LIVE / E2E_X402 / | ||
| // API_URL against a real stack), this one ALWAYS runs in CI — it is the guard | ||
| // that the build + app never depend on staging. Every backend call is | ||
| // intercepted by Playwright before it can reach the network, so no real backend | ||
| // is ever contacted; the assertions cover only static, data-independent shell | ||
| // content that must render regardless. | ||
| // | ||
| // The app resolves its API base from NEXT_PUBLIC_API_BASE_URL (an unreachable | ||
| // sentinel in CI, staging by default locally). We intercept that origin AND | ||
| // staging explicitly, so a real backend is never contacted in any environment. | ||
| const API_BASE = | ||
| process.env["NEXT_PUBLIC_API_BASE_URL"] ?? "https://staging-api.tiny.place"; | ||
|
|
||
| const BACKEND_GLOBS = [ | ||
| `${API_BASE}/**`, | ||
| "**/staging-api.tiny.place/**", | ||
| "**/127.0.0.1:9999/**", | ||
| ]; | ||
|
|
||
| const CORS = { | ||
| "access-control-allow-origin": "*", | ||
| "access-control-allow-headers": "*", | ||
| "access-control-allow-methods": "*", | ||
| }; | ||
|
|
||
| /** | ||
| * Simulate a backend that is simply not there: fulfil CORS preflights, and | ||
| * answer everything else with an empty, well-formed body. TanStack Query hooks | ||
| * degrade to empty/error states; the static shell renders regardless. We never | ||
| * abort (that races page teardown and flakes) — an explicit empty response is | ||
| * deterministic. | ||
| */ | ||
| function emptyBackend(route: Route): Promise<void> { | ||
| const request = route.request(); | ||
| if (request.method() === "OPTIONS") { | ||
| return route.fulfill({ status: 204, headers: CORS }); | ||
| } | ||
| // GraphQL clients expect a { data } envelope; REST callers tolerate {}. | ||
| const body = request.url().includes("/graphql") ? { data: {} } : {}; | ||
| return route.fulfill({ | ||
| status: 200, | ||
| headers: { ...CORS, "content-type": "application/json" }, | ||
| body: JSON.stringify(body), | ||
| }); | ||
| } | ||
|
|
||
| test.describe("mocked-backend smoke", () => { | ||
| test.beforeEach(async ({ page }) => { | ||
| // Intercepting these globs guarantees no request reaches a real backend: | ||
| // Playwright fulfils them before the network layer runs. | ||
| for (const glob of BACKEND_GLOBS) { | ||
| await page.route(glob, emptyBackend); | ||
| } | ||
| }); | ||
|
|
||
| test("home shell renders with no live backend", async ({ page }) => { | ||
| await page.goto("/"); | ||
|
|
||
| // Static hero copy: present regardless of any backend data. Its presence | ||
| // proves the layout + i18n + client bootstrap all work with the backend | ||
| // fully mocked out. | ||
| await expect( | ||
| page.getByText("Enter as a Human", { exact: false }) | ||
| ).toBeVisible(); | ||
| }); | ||
|
|
||
| test("static content route renders offline", async ({ page }) => { | ||
| // /terms is server-rendered static section content — a route with no | ||
| // backend dependency that must always serve. | ||
| const response = await page.goto("/terms"); | ||
| expect(response?.status()).toBeLessThan(400); | ||
| await expect(page.locator("body")).toBeVisible(); | ||
| }); | ||
| }); | ||
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When the
/termssmoke runs, this REST mock makesclient.docs.terms()resolve successfully to{}.Termstreats any truthydataas a realTermsDocumentand callsparseTermsSections(data.text, ...), which throws becausetextis undefined, so the route can client-crash while the test still passes with only<body>visible. Return a non-2xx response for generic REST failures, or a validTermsDocumentfor/terms, so this actually exercises the offline fallback.Useful? React with 👍 / 👎.