43 lines
1.4 KiB
TypeScript
43 lines
1.4 KiB
TypeScript
import type { Page } from "@playwright/test";
|
|
import { expect, test } from "@playwright/test";
|
|
|
|
/** Abort the first request for a module once, then let every later request through. */
|
|
async function abortFirstRequest(page: Page, pattern: string) {
|
|
const counter = { aborted: 0 };
|
|
await page.route(pattern, async (route) => {
|
|
if (counter.aborted === 0) {
|
|
counter.aborted += 1;
|
|
await route.abort("failed");
|
|
return;
|
|
}
|
|
await route.continue();
|
|
});
|
|
return counter;
|
|
}
|
|
|
|
test("the app reloads itself once when a module request aborts while booting", async ({ page }) => {
|
|
const counter = await abortFirstRequest(page, "**/src/App.tsx");
|
|
|
|
await page.goto("/sign-in", { waitUntil: "commit" });
|
|
|
|
await expect(page.getByRole("heading", { name: "Sign in to evOo" })).toBeVisible({
|
|
timeout: 60_000,
|
|
});
|
|
expect(counter.aborted).toBe(1);
|
|
expect(await page.evaluate(() => sessionStorage.getItem("rakazo:boot-reload"))).toBeNull();
|
|
});
|
|
|
|
test("a lazy route recovers when its module request aborts", async ({ page }) => {
|
|
const counter = await abortFirstRequest(page, "**/src/pages/Auth.tsx");
|
|
|
|
await page.goto("/sign-in");
|
|
|
|
await expect(page.getByRole("heading", { name: "Sign in to evOo" })).toBeVisible({
|
|
timeout: 60_000,
|
|
});
|
|
expect(counter.aborted).toBe(1);
|
|
expect(
|
|
await page.evaluate(() => sessionStorage.getItem("rakazo:module-reload:pages/Auth")),
|
|
).toBeNull();
|
|
});
|