fix(toHaveScreenshot): round ratio up (#12540)

This way the ratio value could be used right away in configuation.
This commit is contained in:
Andrey Lushnikov 2022-03-04 19:55:48 -07:00 committed by GitHub
parent a3dff45974
commit d7648d390c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 4 deletions

View File

@ -66,7 +66,7 @@ function compareImages(mimeType: string, actualBuffer: Buffer | string, expected
maxDiffPixels = Math.min(maxDiffPixels1, maxDiffPixels2);
else
maxDiffPixels = maxDiffPixels1 ?? maxDiffPixels2 ?? 0;
const ratio = count / (expected.width * expected.height);
const ratio = Math.ceil(count / (expected.width * expected.height) * 100) / 100;
return count > maxDiffPixels ? {
errorMessage: `${count} pixels (ratio ${ratio.toFixed(2)} of all image pixels) are different`,
diff: PNG.sync.write(diff),

View File

@ -245,7 +245,7 @@ test('should fail when screenshot is different size', async ({ runInlineTest })
test('should fail when screenshot is different pixels', async ({ runInlineTest }) => {
const result = await runInlineTest({
...files,
'a.spec.js-snapshots/snapshot.png': blueImage,
'a.spec.js-snapshots/snapshot.png': paintBlackPixels(whiteImage, 12345),
'a.spec.js': `
const { test } = require('./helper');
test('is a test', async ({ page }) => {
@ -255,9 +255,9 @@ test('should fail when screenshot is different pixels', async ({ runInlineTest }
});
expect(result.exitCode).toBe(1);
expect(result.output).toContain('Screenshot comparison failed');
expect(result.output).toContain('921600 pixels');
expect(result.output).toContain('12345 pixels');
expect(result.output).not.toContain('Call log');
expect(result.output).toContain('ratio 1.00');
expect(result.output).toContain('ratio 0.02');
expect(result.output).toContain('Expected:');
expect(result.output).toContain('Received:');
});