32 lines
1.2 KiB
TypeScript
32 lines
1.2 KiB
TypeScript
import { expect, test } from "@playwright/test";
|
|
|
|
/**
|
|
* Cluster C Playwright sweep — content-addressed URL invalidation.
|
|
* Registering a SW configured with `contentAddressed: true` MUST delete
|
|
* every previously-installed cache whose name starts with the
|
|
* configured prefix and is not in the `keep` list. The page-side
|
|
* harness exposes `/sw-cache-names` to read the live cache names.
|
|
*/
|
|
test.describe("content-addressed cache invalidation (cluster C)", () => {
|
|
test("activate handler drops outdated caches", async ({ page }) => {
|
|
await page.goto("/");
|
|
await page.evaluate(async () => {
|
|
const win = window as unknown as {
|
|
seedStaleCache?: () => Promise<void>;
|
|
};
|
|
if (typeof win.seedStaleCache === "function") {
|
|
await win.seedStaleCache();
|
|
}
|
|
await navigator.serviceWorker.register("/service-worker.js");
|
|
await navigator.serviceWorker.ready;
|
|
});
|
|
const names = await page.evaluate(async () => {
|
|
return await caches.keys();
|
|
});
|
|
// After activate, no stale cache name should remain.
|
|
expect(names.some((n) => n.startsWith("packed-resources-stale"))).toBe(
|
|
false
|
|
);
|
|
});
|
|
});
|