Add toolbox spaces and recover from stale asset bundles
All checks were successful
Deploy Sokko G / deploy (push) Successful in 18s
All checks were successful
Deploy Sokko G / deploy (push) Successful in 18s
This commit is contained in:
parent
0959c6740b
commit
0acf5ecf21
30 changed files with 1252 additions and 179 deletions
37
e2e/production/asset-recovery.spec.js
Normal file
37
e2e/production/asset-recovery.spec.js
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
// 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);
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue