04c7f6e68a
Tests · UI / test (push) Failing after 7m31s
Native SvelteKit service worker (src/service-worker.ts): a version-keyed cache precaches the app shell + build artefacts (incl. core.wasm) + static files; activate purges old caches; the gateway is never intercepted; navigations fall back to the cached shell offline. Adds static/manifest.webmanifest, a generated placeholder icon set (scripts/gen-pwa-icons.mjs — dependency-free pure-Node PNG encoder), and manifest / theme-color / apple-touch tags in app.html. Gated by Playwright against a production preview (playwright.pwa.config.ts + tests/pwa/pwa.spec.ts via `pnpm test:pwa`, wired into ui-test): manifest + installable icons, SW registration + a single version-keyed cache, and offline shell load. Lighthouse is not used — its PWA category was removed in v12. Docs: ui/docs/pwa-strategy.md (+ index); F5 marked done. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
70 lines
2.3 KiB
TypeScript
70 lines
2.3 KiB
TypeScript
// F5 — PWA behaviour against a production preview build (see
|
|
// playwright.pwa.config.ts). Covers the manifest, service-worker
|
|
// registration, offline-from-cache load, and the version-keyed cache
|
|
// (a new deploy's `version` makes a new cache and `activate` drops the
|
|
// old one — verified here as "exactly one galaxy cache, version-keyed").
|
|
|
|
import { expect, test } from "@playwright/test";
|
|
|
|
test.describe("PWA", () => {
|
|
test("links a web manifest with installable icons", async ({ page }) => {
|
|
await page.goto("/login");
|
|
const href = await page
|
|
.locator('head link[rel="manifest"]')
|
|
.getAttribute("href");
|
|
expect(href).toMatch(/manifest\.webmanifest$/);
|
|
|
|
const manifest = await page.request
|
|
.get(href!)
|
|
.then((r) => r.json());
|
|
expect(manifest.name).toBe("Galaxy");
|
|
expect(manifest.start_url).toBe("/");
|
|
expect(manifest.display).toBe("standalone");
|
|
const sizes = (manifest.icons as { sizes: string }[]).map((i) => i.sizes);
|
|
expect(sizes).toContain("192x192");
|
|
expect(sizes).toContain("512x512");
|
|
const purposes = (manifest.icons as { purpose?: string }[]).map(
|
|
(i) => i.purpose,
|
|
);
|
|
expect(purposes).toContain("maskable");
|
|
});
|
|
|
|
test("registers a service worker that controls the page", async ({ page }) => {
|
|
await page.goto("/login");
|
|
await page.waitForFunction(
|
|
() => navigator.serviceWorker.controller !== null,
|
|
null,
|
|
{ timeout: 20_000 },
|
|
);
|
|
const cacheNames: string[] = await page.evaluate(() => caches.keys());
|
|
const galaxy = cacheNames.filter((n) => n.startsWith("galaxy-cache-"));
|
|
// Exactly one, version-keyed cache (old versions purged on activate).
|
|
expect(galaxy).toHaveLength(1);
|
|
expect(galaxy[0]).toMatch(/^galaxy-cache-.+/);
|
|
});
|
|
|
|
test("serves the app shell offline from the cache", async ({
|
|
page,
|
|
context,
|
|
}) => {
|
|
await page.goto("/login");
|
|
await page.waitForFunction(
|
|
() => navigator.serviceWorker.controller !== null,
|
|
null,
|
|
{ timeout: 20_000 },
|
|
);
|
|
await expect(page.locator("#main-content")).toBeVisible();
|
|
|
|
await context.setOffline(true);
|
|
try {
|
|
await page.reload();
|
|
// The cached shell boots offline — the login main region renders.
|
|
await expect(page.locator("#main-content")).toBeVisible({
|
|
timeout: 15_000,
|
|
});
|
|
} finally {
|
|
await context.setOffline(false);
|
|
}
|
|
});
|
|
});
|