Skip to content

Commit

Permalink
test(e2e): add very small pixel tolerance
Browse files Browse the repository at this point in the history
  • Loading branch information
fshovchko committed Jun 20, 2024
1 parent 59caec2 commit 5397fe0
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion e2e/setup/scenarios.screenshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@ cucumber.defineRule('check if the screenshot is exactly equal to the snapshotted
cucumber.defineRule('check if the screenshot is equal to the snapshotted version', async ({screenshots}: TestEnv) => {
if (!screenshots.length) throw new Error('E2E: there is no any screenshot, make sure you have "Take a screenshot" before');
const image = screenshots.pop();
expect(image).toMatchImageSnapshot({threshold: 0.1, alpha: 0.1});
expect(image).toMatchImageSnapshot({threshold: 0.1});
});
3 changes: 2 additions & 1 deletion e2e/setup/serializers/image/snapshot-matcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export class SnapshotMatcher {

protected static readonly defaultOptions: SnapshotMatcherOptions = {
diffMask: false,
alpha: 0,
diffColorAlt: [255, 255, 0],
includeAA: true,
threshold: 0.01
Expand Down Expand Up @@ -65,7 +66,7 @@ export class SnapshotMatcher {
const {width, height} = prevImg.info;
const diffBuffer = Buffer.alloc(width * height * 4);
const numDiffPixel = pixelmatch(prevImg.data, currImg.data, diffBuffer, width, height, this.config);
if (numDiffPixel > 0) diffPath = await this.saveDiff(prevImg, currImg, diffBuffer);
if (numDiffPixel > width * height * 0.0001) diffPath = await this.saveDiff(prevImg, currImg, diffBuffer);
return diffPath;
}

Expand Down

0 comments on commit 5397fe0

Please sign in to comment.