import test from "node:test"; import assert from "node:assert/strict"; import { existsSync, readFileSync } from "node:fs"; import { fileURLToPath } from "node:url"; const root = (path) => fileURLToPath(new URL(`../${path}`, import.meta.url)); const manifest = JSON.parse(readFileSync(root("manifest.json"), "utf8")); const PNG_SIGNATURE = Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]); test("the manifest declares icons and the action icon, and every file is a PNG of its declared size", () => { assert.deepEqual(Object.keys(manifest.icons), ["16", "32", "48", "128"]); for (const [size, path] of Object.entries(manifest.icons)) { assert.ok(existsSync(root(path)), path); const data = readFileSync(root(path)); assert.equal(data.subarray(0, 8).equals(PNG_SIGNATURE), true, path); assert.equal(data.subarray(12, 16).toString(), "IHDR", path); assert.equal(data.readUInt32BE(16), Number(size), `${path} width`); assert.equal(data.readUInt32BE(20), Number(size), `${path} height`); } for (const [size, path] of Object.entries(manifest.action.default_icon)) { assert.equal(manifest.icons[size], path); } }); test("build.sh ships the icons", () => { const script = readFileSync(root("build.sh"), "utf8"); assert.match(script, /manifest\.json src ui icons README\.md/); assert.match(script, /\("src", "ui", "icons"\)/); });