MCPcopy Index your code
hub / github.com/mapbox/pixelmatch / diffTest

Function diffTest

test/test.js:54–75  ·  view source on GitHub ↗
(imgPath1, imgPath2, diffPath, options, expectedMismatch)

Source from the content-addressed store, hash-verified

52});
53
54function diffTest(imgPath1, imgPath2, diffPath, options, expectedMismatch) {
55 const name = `comparing ${imgPath1} to ${imgPath2}, ${JSON.stringify(options)}`;
56
57 test(name, () => {
58 const img1 = readImage(imgPath1);
59 const img2 = readImage(imgPath2);
60 const {width, height} = img1;
61 const diff = new PNG({width, height});
62
63 const mismatch = match(img1.data, img2.data, diff.data, width, height, options);
64 const mismatch2 = match(img1.data, img2.data, null, width, height, options);
65
66 if (process.env.UPDATE) {
67 writeImage(diffPath, diff);
68 } else {
69 const expectedDiff = readImage(diffPath);
70 assert.ok(diff.data.equals(expectedDiff.data), 'diff image');
71 }
72 assert.equal(mismatch, expectedMismatch, 'number of mismatched pixels');
73 assert.equal(mismatch, mismatch2, 'number of mismatched pixels without diff');
74 });
75}
76
77function readImage(name) {
78 return PNG.sync.read(fs.readFileSync(new URL(`fixtures/${name}.png`, import.meta.url)));

Callers 1

test.jsFile · 0.85

Calls 2

writeImageFunction · 0.85
readImageFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…