18 lines
812 B
JavaScript
18 lines
812 B
JavaScript
import test from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import { readFile } from "node:fs/promises";
|
|
import vm from "node:vm";
|
|
|
|
test("shell updates retain unrelated caches and the current app cache", async () => {
|
|
const handlers = new Map();
|
|
const deleted = [];
|
|
let activation;
|
|
vm.runInNewContext(await readFile(new URL("../sw.js", import.meta.url), "utf8"), {
|
|
self: { addEventListener: (type, handler) => handlers.set(type, handler), clients: { claim: async () => {} } },
|
|
caches: { keys: async () => ["pipelines-shell-v7", "pipelines-shell-v8", "unrelated-user-cache"], delete: async (key) => deleted.push(key) },
|
|
});
|
|
handlers.get("activate")({ waitUntil: (promise) => { activation = promise; } });
|
|
await activation;
|
|
assert.deepEqual(deleted, ["pipelines-shell-v7"]);
|
|
});
|