mirror of
https://github.com/microsoft/playwright.git
synced 2025-06-26 21:40:17 +00:00
fix(to-have-screenshot): show number of bad pixels in mismatched error (#12502)
Drive-by: do not show empty call log. References #12441
This commit is contained in:
parent
f96a1a3ccd
commit
1f5cfcaeec
@ -66,7 +66,11 @@ function compareImages(mimeType: string, actualBuffer: Buffer | string, expected
|
||||
maxDiffPixels = Math.min(maxDiffPixels1, maxDiffPixels2);
|
||||
else
|
||||
maxDiffPixels = maxDiffPixels1 ?? maxDiffPixels2 ?? 0;
|
||||
return count > maxDiffPixels ? { diff: PNG.sync.write(diff) } : null;
|
||||
const ratio = count / (expected.width * expected.height);
|
||||
return count > maxDiffPixels ? {
|
||||
errorMessage: `${count} pixels (ratio ${ratio.toFixed(2)} of all image pixels) are different`,
|
||||
diff: PNG.sync.write(diff),
|
||||
} : null;
|
||||
}
|
||||
|
||||
function compareText(actual: Buffer | string, expectedBuffer: Buffer): ComparatorResult {
|
||||
|
||||
@ -179,7 +179,7 @@ class SnapshotHelper<T extends ImageComparatorOptions> {
|
||||
'',
|
||||
]);
|
||||
}
|
||||
if (log)
|
||||
if (log?.length)
|
||||
output.push(callLogText(log));
|
||||
|
||||
if (expected !== undefined) {
|
||||
|
||||
@ -254,8 +254,10 @@ test('should fail when screenshot is different pixels', async ({ runInlineTest }
|
||||
`
|
||||
});
|
||||
expect(result.exitCode).toBe(1);
|
||||
expect(result.output).toContain('Timeout 2000ms exceeded');
|
||||
expect(result.output).toContain('Screenshot comparison failed');
|
||||
expect(result.output).toContain('921600 pixels');
|
||||
expect(result.output).not.toContain('Call log');
|
||||
expect(result.output).toContain('ratio 1.00');
|
||||
expect(result.output).toContain('Expected:');
|
||||
expect(result.output).toContain('Received:');
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user