You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
While working with snapshot-tests on a large scale, we resorted to lowering the snapshot resolution in some cases to improve performance. This was achieved by reducing the displayScale of the trait collection passed to the Snapshotting.image() method.
While the results are as expected, when the snapshot-test fails, the attached diff is incorrect.
Example
Notice the plus icon in the corner, which has the correct size while the i icon is scaled up.
Solution
I noticed that the image diffing strategy uses the UIScreen.main.scale constant to load the reference snapshot from disk (Sources/SnapshotTesting/Snapshotting/UIImage.swift#L16).
This causes the reference image being a different size the new snapshot when creating the diff, which results in a pretty much useless XCTestAttachment.
I suggest to resolve this by passing the displayScale from the trait collection through to the image diffing strategy. I prepared the necessary changes and would like to open a PR as soon as possible if nobody finds anything wrong with my approach.
The text was updated successfully, but these errors were encountered:
@moritzsternemann This also appears to be a dupe of #243, right? I'm going to close this, but feel free to reopen if you think the issues are distinct.
Though my solution won't allow snapshot tests to be run on different simulators than when the references were created because of the font rendering difference @kirillsh described in #243 (comment).
While working with snapshot-tests on a large scale, we resorted to lowering the snapshot resolution in some cases to improve performance. This was achieved by reducing the
displayScale
of the trait collection passed to theSnapshotting.image()
method.While the results are as expected, when the snapshot-test fails, the attached diff is incorrect.
Example
Notice the plus icon in the corner, which has the correct size while the i icon is scaled up.

Solution
I noticed that the image diffing strategy uses the
UIScreen.main.scale
constant to load the reference snapshot from disk (Sources/SnapshotTesting/Snapshotting/UIImage.swift#L16).This causes the reference image being a different size the new snapshot when creating the diff, which results in a pretty much useless XCTestAttachment.
I suggest to resolve this by passing the
displayScale
from the trait collection through to the image diffing strategy. I prepared the necessary changes and would like to open a PR as soon as possible if nobody finds anything wrong with my approach.The text was updated successfully, but these errors were encountered: