testServiceWorkerSource
tcmts.cli.web.testServiceWorkerSource · #fld6sgp4 · term
import { buildKey, serviceWorkerSource } from "#codebase/tcmts/cli/web";
import assert from "node:assert/strict";
export const testServiceWorkerSource = () => {
const sw = serviceWorkerSource("k1", ["./", "./_app/assets/app-12345678.js"], true);
assert.match(sw, /const FILES = \["\.\/","\.\/_app\/assets\/app-12345678\.js"\];/);
assert.match(sw, /const OFFLINE_FIRST = true;/);
assert.match(sw, /const BUILD = prefix \+ "k1";/);
assert.match(serviceWorkerSource("k1", [], false), /const OFFLINE_FIRST = false;/);
// it's a script a browser runs: it parses
assert.doesNotThrow(() => new Function(sw));
// a PWA's build is named by the app and its pwa together; an app without one, by the app
assert.equal(buildKey("a".repeat(52), undefined), "a".repeat(52));
const key = buildKey("a".repeat(52), "b".repeat(52));
assert.equal(key.length, 52);
assert.notEqual(key, buildKey("a".repeat(52), "c".repeat(52)));
}
uses