feat: allow-browser-screenshot-config#210
Open
Perturbatio wants to merge 1 commit intopestphp:4.xfrom
Open
Conversation
* added ability to control the screenshot diffing via `screenshotThreshold`, `screenshotMaxDiffPixels` and `screenshotMaxDiffPixelRatio` * fixed issue with Pest assuming that if a screenshot does not precisely match (via base64 string comparison) that it has failed testing
Author
|
Note that other configuration options would be nice to have but I'm focussing on the ones which are most likely to affect most users atm. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Currently Pest browser snapshot testing is a boolean check, it either precisely matches or it doesn't (via
expect($actualImageBlob)->toMatchSnapshot();)This PR adds the ability to control the granularity of screenshot diffing and only fail if it exceeds the settings.
You can retain existing functionality with:
The above will fail the test even if a single pixel is off (within Playwright's own internal tolerances).
If you want a little tolerance to account for some pixels not rendering consistently, you can do something like:
Larger numbers = more tolerance, the ratio is in the range of 0 to 1 and internally is a formula that determines the number of pixels allowed to vary by multiplying the expected width * height * maxDiffPixelRatio (which can result in very large tolerances)
Playwright will prefer the lower of the
maxDiffPixelRatioor themaxDiffPixelsscreenshotThreshold,screenshotMaxDiffPixelsandscreenshotMaxDiffPixelRatio