sokko-g/e2e/production/asset-recovery.spec.js
Shinuwa 0acf5ecf21
All checks were successful
Deploy Sokko G / deploy (push) Successful in 18s
Add toolbox spaces and recover from stale asset bundles
2026-09-29 21:31:49 +02:00

37 lines
1.3 KiB
JavaScript

// Rôle : vérifie qu'un ancien HTML rétablit l'application quand son bundle Vite a disparu.
import { test, expect } from "@playwright/test";
import { readFile } from "node:fs/promises";
const site = JSON.parse(await readFile("website/public/data/site.json", "utf8"));
test("a stale entry bundle triggers one fresh document load", async ({ page }) => {
let staleDocumentServed = false;
let documentRequestCount = 0;
await page.route("**/*", async (route) => {
const request = route.request();
const requestUrl = new globalThis.URL(request.url());
const isRootDocument = request.resourceType() === "document" && requestUrl.pathname === "/";
if (isRootDocument) documentRequestCount += 1;
if (staleDocumentServed || !isRootDocument) {
await route.continue();
return;
}
staleDocumentServed = true;
const response = await route.fetch();
const html = await response.text();
await route.fulfill({
response,
body: html.replace(/(<script type="module"[^>]*src=")[^"]+/, "$1/assets/index-stale.js")
});
});
await page.goto("/").catch(() => {});
await expect(page.getByRole("heading", { name: site.home.hero.title, exact: true })).toBeVisible();
await expect(page).toHaveURL(/\/$|\/#\/$/);
expect(staleDocumentServed).toBe(true);
expect(documentRequestCount).toBe(2);
});