Replace resemble.js with pixelmatch as the comparison engine#1151
Open
wswebcreation wants to merge 16 commits into
Open
Replace resemble.js with pixelmatch as the comparison engine#1151wswebcreation wants to merge 16 commits into
wswebcreation wants to merge 16 commits into
Conversation
🦋 Changeset detectedLatest commit: 3a8a1f5 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
* refactor: remove resemble engine and make pixelmatch the sole comparison engine * feat: add fast-png dependency and imageUtils pure-JS pixel utility module * chore: linting fix * chore: add missing coverage * feat: overlay diff pixels on actual screenshot and eliminate intermediate PNG encode/decode - fix restore blockout transparency and correct landscape bezel rotation - * chore: add new temp images * chore:now use the pixelmatch not layout testing baseline * tests: fix tests * Merge branch 'main' into ws/replace-jimp * chore: add cron option to enable/disable trigger * chore: fix flow * Merge branch 'main' into ws/replace-jimp * Merge branch 'main' into ws/replace-jimp * Merge branch 'ws/investigate-flakiness' into ws/replace-jimp * fix: fix ocr test * chore: fix OCR test * chore: remove images * chore: revert lt config
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.
What this does
This replaces the whole image stack used for visual comparison.
resemble.jsis removed as the comparison engine and replaced by pixelmatch.jimpis removed as the image manipulation library. PNG decode/encode now goes throughfast-png, and the few operations we still need (crop, composite, canvas creation, opacity, rotate, resize) live in a small internalutils/imageUtils.ts.resemble.jimp.cjsfile (~1200 lines) is deleted.Why
People kept hitting flaky visual tests caused by rendering noise that no human can see: sub-pixel font hinting, 1px anti-aliasing at element edges, tiny shadow changes between runs. None of these are real regressions, but they made tests fail at random and that kills trust in the suite.
The root cause sat in resemble.js:
Pixelmatch compares in the YIQ colour space, which is weighted by how sensitive the human eye actually is (luminance first, then orange-blue, then purple-green). Its anti-aliasing detection cross-checks both images, so a pixel is only treated as anti-aliasing if both the baseline and the actual look like an anti-aliased edge there. The result: invisible noise passes, real regressions still fail.
On top of removing Jimp we drop a large dependency with native-ish baggage in favour of two small, focused libraries.
Behaviour and compatibility
checkScreen,checkElement,checkFullPageScreen, the matchers and the report output all work the same way.ignorecompare options (nothing,less,antialiasing,colors,alpha) are still supported. They are mapped onto pixelmatch thresholds.diffPixelsbounding boxes and mismatch percentages keep the same shape.Fixes included in this PR
contain()centred the image, shifting content by 1px and creating a false diff across the top row. Replaced with buffer-level padding that anchors content at (0,0).Math.floor, which could drop a pixel whencssSize * DPRhad a fractional part. Width and height now useMath.ceilso the full element is always covered. Position still usesMath.floor.ignoreRegionPaddingto better cover elements.