chore: draw the toolbar icons in-tree with make icons (closes #378)
script/lib/icons.js draws the mark from geometry read back out of the committed PNGs, since the coordinates were never recorded, and writes each PNG with node's own zlib. `make icons` runs it and leaves alone a file that already holds the drawn image. tests/icons.test.js requires each committed file to hold exactly that image: the same IHDR and every pixel. The compressed bytes are not compared, because node's bundled zlib does not compress as the stock zlib that made the committed files did; the decision is recorded on the issue. build.js copies the manifests from MANIFEST_SOURCES instead of naming the two paths a second time. Model: opus-5-5
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
// 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);
|
||||
},
|
||||
);
|
||||
});
|
||||
Reference in New Issue
Block a user