Skip to content

Fix applyChange tests to pass at all screen scales#3391

Merged
JiuqingSong merged 2 commits into
masterfrom
u/jisong/fixtest
Jul 2, 2026
Merged

Fix applyChange tests to pass at all screen scales#3391
JiuqingSong merged 2 commits into
masterfrom
u/jisong/fixtest

Conversation

@JiuqingSong

Copy link
Copy Markdown
Collaborator

Summary

The applyChange image-edit tests in applyChangeTest.ts (rotate/crop/resize cases) failed on any host whose screen scale was not 100%. generateDataURL.ts sizes the output canvas as targetWidth/Height * window.devicePixelRatio, but the hardcoded expected newSrc images were captured at 100% scale (devicePixelRatio === 1). At other scales the generated PNG was larger, so the IHDR dimension assertions failed.

This pins window.devicePixelRatio to 1 for the duration of these tests (set in beforeEach, original descriptor restored in afterEach), making the canvas output deterministic regardless of the host screen scale. Only the test file changes; production code is untouched.

How to test

  1. Run the tests: yarn test:fast --testPathPattern=applyChange — all 11 should pass.
  2. To verify scale-independence, force a non-100% scale by launching Chrome with --force-device-scale-factor=2:
    • Before this fix: 8 tests fail (canvas dimensions doubled, e.g. width 20 vs expected 10).
    • After this fix: all 11 pass at both 200% and 100% scale.

generateDataURL sizes the output canvas by window.devicePixelRatio, but the expected newSrc images were captured at 100% scale, so the IHDR dimension assertions failed on hosts at other scales. Pin devicePixelRatio to 1 for these tests so canvas output is deterministic regardless of screen scale.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@JiuqingSong JiuqingSong marked this pull request as ready for review June 30, 2026 23:57
@github-actions

github-actions Bot commented Jun 30, 2026

Copy link
Copy Markdown
PR Preview Action v1.8.1
Preview removed because the pull request was closed.
2026-07-02 17:21 UTC

@JiuqingSong JiuqingSong merged commit 76063fb into master Jul 2, 2026
8 checks passed
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.

2 participants