Skip to content

fix: honor screenshot pixel tolerances - #251

Open
lazerg wants to merge 2 commits into
pestphp:5.xfrom
lazerg:fix/screenshot-pixel-tolerance
Open

fix: honor screenshot pixel tolerances#251
lazerg wants to merge 2 commits into
pestphp:5.xfrom
lazerg:fix/screenshot-pixel-tolerance

Conversation

@lazerg

@lazerg lazerg commented Aug 20, 2026

Copy link
Copy Markdown

expectScreenshot() compares the raw PNG bytes with toMatchSnapshot() first, and only asks Playwright for a pixel comparison once those differ. But both paths out of the catch throw, so a screenshot Playwright reports as a match still fails the test, and maxDiffPixels, threshold and detectAntialiasing never get to decide anything. Chromium's PNG output is not byte-reproducible, so a handful of antialiased pixels is enough to fail a run at random.

Playwright signals a real mismatch by erroring on the expectScreenshot call, which the websocket client already turns into a failed expectation before the loop below it runs. Dropping the trailing throw therefore keeps genuine regressions failing and lets the tolerances apply.

To reproduce, take a screenshot assertion with a committed baseline and re-encode the stored snapshot so the pixels stay identical but the bytes change (appending a PNG tEXt chunk does it). The test fails today and passes with this change.

Fixes pestphp/pest#1881

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Browser plugin] assertScreenshotMatches() fails on byte differences, making the pixel tolerances unreachable

1 participant