// The toolbar icons in icons/ are drawn by script/lib/icons.js (`make icons`). // Each committed file must hold exactly the image it draws, the same IHDR and // every pixel, so the drawing and the files cannot drift apart. The compressed // bytes are not compared: the committed files were compressed by stock zlib, // and node's bundled zlib compresses the same pixels differently. const fs = require("fs"); const path = require("path"); const { icons } = require("../manifest/chrome.json"); const { drawIcon, decodePng } = require("../script/lib/icons"); describe("toolbar icons", () => { test.each(Object.entries(icons))( "the %spx icon %s holds the image script/lib/icons.js draws", (size, file) => { const side = Number(size); const committed = decodePng( fs.readFileSync(path.join(__dirname, "..", file)), ); const drawn = decodePng(drawIcon(side)); expect(committed.header).toEqual(drawn.header); // Each row is its filter type byte, then 4 bytes per pixel. expect(drawn.rows.length).toBe(side * (side * 4 + 1)); expect(committed.rows.length).toBe(drawn.rows.length); // The offset of the first byte that differs, not a diff of all. expect( committed.rows.findIndex((byte, i) => byte !== drawn.rows[i]), ).toBe(-1); }, ); });