Files
kevinveenbirkenbachandClaude Opus 5.5 787f8d9a6d fix(design): isolate the colour sampler's fillStyle with save and restore
js/useless-assignment-to-property on PR #625 (test-e2e-playwright design.js:163, bluesky test-design.js:178, decidim test-design.js:181): the black reset before each sampled colour was a real guard, since canvas keeps the old fillStyle for a colour it cannot parse. save/restore around the single write keeps that guard; the pixels are identical. One test per sampler against a canvas double; dropping the reset fails all three.

🎯 Fix: 95 %
💥 Break: 2 %
💸 Cost: –
⏱️ Time: –
🛡️ Security: ~100 %
🏆 Score: 93
🚦 Gate: ✅ 90/5, cost and time <= 100, security 100 %

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-05 17:12:53 +00:00

39 lines
1.5 KiB
JavaScript

const test = require("node:test");
const assert = require("node:assert/strict");
const path = require("node:path");
const PROJECT_ROOT = path.resolve(__dirname, "../../../../../..");
const { UNPARSEABLE_COLOUR, browserGlobals, styledElement } = require(
path.join(PROJECT_ROOT, "tests/unit/javascript/utils/canvas.js"),
);
const { loadInternals } = require(path.join(PROJECT_ROOT, "tests/unit/javascript/utils/internals.js"));
const globals = {};
const { measure } = loadInternals(
path.join(PROJECT_ROOT, "roles/test-e2e-playwright/files/design.js"),
["measure"],
{},
globals,
);
const page = { evaluate: async (callback, argument) => callback(argument) };
function sample(css, parentCss) {
const parent = parentCss ? styledElement(parentCss, null) : null;
Object.assign(globals, browserGlobals({}, { "#target": styledElement(css, parent) }));
return measure(page, "#target").then(structuredClone);
}
test("measure reads the text colour against the first opaque background up the tree", async () => {
assert.deepEqual(
await sample({ color: "rgb(10, 20, 30)", "background-color": "rgba(0, 0, 0, 0)" }, { "background-color": "#ffffff" }),
{ background: [255, 255, 255], color: [10, 20, 30] },
);
});
test("measure samples a colour canvas cannot parse as black, not as the background sampled before it", async () => {
assert.deepEqual(await sample({ color: UNPARSEABLE_COLOUR, "background-color": "rgb(255, 255, 255)" }), {
background: [255, 255, 255],
color: [0, 0, 0],
});
});