mirror of
https://github.com/tiennm99/vngeoguessr.git
synced 2026-10-14 22:17:48 +00:00
Adds coverage for this branch's behaviour: the homoglyph 404 through a real percent-encoded request, href assertions on both not-found exits (a visible link to nowhere is still a dead end), and the two halves of InlineScript's contract -- no console error where React renders the script on the client, and an executable type in the served markup everywhere else. That second one is asserted on raw HTML, with no browser, because in a browser the regression is invisible: ThemeToggle re-applies the theme on mount, so <html> ends up correct whether or not the script ran -- just a flash later. Mutating the helper to always emit text/plain previously failed nothing. global-setup fixes a real flake. next dev compiles a route on first request, and 8 workers demanded the same cold compile at once, so every test navigating to a /game URL failed together at the 60s timeout -- reproducible by touching any source file. One serial warm-up pays the compile once: 28 passed in 14s. The fetch is bounded and its failure logged, because a skipped warm-up otherwise looks exactly like the flake it prevents. eslint ignores Playwright's artifact dirs, which are gitignored but were still walked, crashing a lint run concurrent with a test run.
39 lines
1.8 KiB
JavaScript
39 lines
1.8 KiB
JavaScript
// Warms the dev server's heavy routes before any worker runs.
|
|
//
|
|
// `next dev` compiles a route on its first request. The game routes are the
|
|
// expensive ones, and 8 parallel workers otherwise all demand that same cold
|
|
// compile at once, each waiting behind it -- every test that navigates to a
|
|
// /game URL then fails together at the 60s timeout. Reproducible on demand:
|
|
// touch a source file (invalidating the compile cache) and run the suite.
|
|
//
|
|
// One serial pass over the three route shapes pays the compile once. A warm
|
|
// server, or a production one, makes these near-instant no-ops.
|
|
export default async function globalSetup(config) {
|
|
const { baseURL } = config.projects[0].use;
|
|
|
|
// One per compiled route: the prerendered region page, the dynamic legacy
|
|
// redirect, and the not-found path through the [region] segment.
|
|
const routes = ['/', '/game/tphcm', '/game?region=TPHCM', '/game/notaregion'];
|
|
|
|
for (const route of routes) {
|
|
try {
|
|
// Bounded: a wedged compile would otherwise hang here forever, and
|
|
// Playwright's globalTimeout is 0, so the run would stall with no output.
|
|
await fetch(new URL(route, baseURL), {
|
|
redirect: 'follow',
|
|
signal: AbortSignal.timeout(60_000),
|
|
});
|
|
} catch (error) {
|
|
// A warm-up is an optimisation, never a gate: if the server is not
|
|
// answering, the specs' own waits and retries still apply, and their
|
|
// failure messages say far more than one thrown here would. Only a
|
|
// network-level failure lands here -- fetch resolves on any HTTP status,
|
|
// so a 404 or a 500 is a successful warm-up, not a miss.
|
|
//
|
|
// Said out loud, because a skipped warm-up looks exactly like the flake
|
|
// it exists to prevent: 8 game-route tests timing out together.
|
|
console.warn(`[global-setup] warm-up of ${route} failed: ${error.message}`);
|
|
}
|
|
}
|
|
}
|