From c4c1580c236b06ebee96daca1a3e8ead6b89c969 Mon Sep 17 00:00:00 2001 From: Andrew Duthie <1779930+aduth@users.noreply.github.com> Date: Tue, 7 May 2024 16:56:33 -0400 Subject: [PATCH] Remove resize handling in visual regression specs (#438) --- test/screenshot.test.js | 39 +++------------------------------------ 1 file changed, 3 insertions(+), 36 deletions(-) diff --git a/test/screenshot.test.js b/test/screenshot.test.js index 3afaf63a..8ceacaf2 100644 --- a/test/screenshot.test.js +++ b/test/screenshot.test.js @@ -18,37 +18,6 @@ const SNAPSHOT_DIRECTORY = 'tmp/screenshot/branches'; const MAIN_SNAPSHOTS_DIRECTORY = join(SNAPSHOT_DIRECTORY, 'main'); const BRANCH_SNAPSHOTS_DIRECTORY = join(SNAPSHOT_DIRECTORY, branch); -/** - * Resizes an image to the given dimensions. - * - * @param {import('pngjs').PNGWithMetadata} image - * @param {number} width - * @param {number} height - * - * @return {import('pngjs').PNG} - */ -function fillImageToSize(image, width, height) { - if (image.width === width && image.height === height) { - return image; - } - - const resizedImage = new PNG({ width, height, fill: true }); - PNG.bitblt(image, resizedImage, 0, 0, image.width, image.height, 0, 0); - - for (let y = image.height; y < height; y += 1) { - for (let x = image.width; x < width; x += 1) { - // eslint-disable-next-line no-bitwise - const index = (resizedImage.width * y + x) << 2; - resizedImage.data[index] = 255; // Red - resizedImage.data[index + 1] = 255; // Green - resizedImage.data[index + 2] = 255; // Blue - resizedImage.data[index + 3] = 255; // Alpha (Opacity) - } - } - - return resizedImage; -} - const skip = !!process.env.SKIP_VISUAL_REGRESSION_TEST; describe('screenshot visual regression', { skip, concurrency: true }, async () => { @@ -68,18 +37,16 @@ describe('screenshot visual regression', { skip, concurrency: true }, async () = const mainPNG = PNG.sync.read(await readFile(join(MAIN_SNAPSHOTS_DIRECTORY, path))); const width = Math.max(branchPNG.width, mainPNG.width); const height = Math.max(branchPNG.height, mainPNG.height); - const resizedBranchPNG = fillImageToSize(branchPNG, width, height); - const resizedMainPNG = fillImageToSize(mainPNG, width, height); const diff = new PNG({ width, height }); - const diffs = match(resizedBranchPNG.data, resizedMainPNG.data, diff.data, width, height, { + const diffs = match(branchPNG.data, mainPNG.data, diff.data, width, height, { threshold: 0.2, }); if (diffs > 0) { const diffOutputBase = join(DIFF_DIRECTORY, path); await mkdir(DIFF_DIRECTORY, { recursive: true }); await Promise.all([ - writeFile(`${diffOutputBase}-local.png`, PNG.sync.write(resizedBranchPNG)), - writeFile(`${diffOutputBase}-remote.png`, PNG.sync.write(resizedMainPNG)), + writeFile(`${diffOutputBase}-local.png`, PNG.sync.write(branchPNG)), + writeFile(`${diffOutputBase}-remote.png`, PNG.sync.write(mainPNG)), writeFile(`${diffOutputBase}-diff.png`, PNG.sync.write(diff)), ]); }