(imgPath1, imgPath2, diffPath, options, expectedMismatch)
| 52 | }); |
| 53 | |
| 54 | function 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 | |
| 77 | function readImage(name) { |
| 78 | return PNG.sync.read(fs.readFileSync(new URL(`fixtures/${name}.png`, import.meta.url))); |
no test coverage detected
searching dependent graphs…