Skip to content

Commit 7ed9355

Browse files
authoredNov 15, 2021
fix: improve output for very small visual diff percentage (#1779)

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed
 

Diff for: ‎.changeset/curly-cameras-deliver.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@web/test-runner-visual-regression': patch
3+
---
4+
5+
improve output in visual regression tests when very small differences from baseline

Diff for: ‎packages/test-runner-visual-regression/src/visualDiffCommand.ts

+6-3
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,14 @@ export async function visualDiffCommand(
104104
await saveFailed();
105105
}
106106

107+
// if diff is suitably small, output raw value, otherwise to two decimal points.
108+
// this avoids outputting a message like "New screenshot is 0.00% different"
109+
const diffPercentageToDisplay =
110+
diffPercentage < 0.005 ? diffPercentage : diffPercentage.toFixed(2);
111+
107112
return {
108113
errorMessage: !passed
109-
? `Visual diff failed. New screenshot is ${diffPercentage.toFixed(
110-
2,
111-
)}% different.\nSee diff for details: ${diffFilePath}`
114+
? `Visual diff failed. New screenshot is ${diffPercentageToDisplay}% different.\nSee diff for details: ${diffFilePath}`
112115
: undefined,
113116
diffPercentage: -1,
114117
passed,

0 commit comments

Comments
 (0)
Please sign in to comment.