import { expect, test } from "@playwright/test"; /** * Cluster A Playwright sweep — minimal happy-path proving the * `@suaveplan/packer-browser` Service Worker registers and intercepts a * packed URL. The broader multi-browser sweep + diagnostics + range * scenarios live in Cluster C. * * This spec is intentionally executable as a smoke test only; it depends * on a real HTTP server hosting the SW bundle and a `*.packed` resource, * which is set up out-of-band (Cluster A does not bundle a static * harness — see the package README's "Test plan" footer). */ test.describe("packed-resource SW interception (smoke)", () => { test("registers the SW and intercepts a packed URL", async ({ page }) => { await page.goto("/"); const swSupported = await page.evaluate( () => "serviceWorker" in navigator ); expect(swSupported).toBe(true); // Register the SW from the harness page. const registered = await page.evaluate(async () => { const reg = await navigator.serviceWorker.register("/service-worker.js"); await navigator.serviceWorker.ready; return reg.scope; }); expect(registered).toContain("/"); // Trigger a packed-URL fetch and verify the SW handled it. const response = await page.evaluate(async () => { const r = await fetch("/sample.packed"); return { status: r.status, unpacked: r.headers.get("X-Unpacked"), }; }); expect(response.status).toBe(200); expect(response.unpacked).toBe("true"); }); });