ios-snapshot-test-case icon indicating copy to clipboard operation
ios-snapshot-test-case copied to clipboard

different images on Intel and Apple M1

Open kikeenrique opened this issue 3 years ago • 5 comments

I'm seeing some tests with different binary image results on a Mac with Intel and a Mac with Apple M1. The diff image is all grey, so I guess it's just some bits.

Has anyone also seen this problem?

kikeenrique avatar Feb 01 '22 12:02 kikeenrique

I've seen the same issue. I have to use Rosetta on the project to keep compatibility with CI and other team members.

tahirmt avatar Feb 05 '22 04:02 tahirmt

The issue is well known and tracked here

acecilia avatar Feb 09 '22 00:02 acecilia

This project already supports a perPixelTolerance parameter, which behaves similarly to the swift-snapshot-testing PR linked in the above thread. I've found that setting this to 0.02 (2%) allows my snapshot tests to pass on both M1 and Intel.

Here's a convenience wrapper in Swift:

public extension FBSnapshotTestCase {
    func FBSnapshotTolerantlyVerifyView(_ view: UIView, identifier: String? = nil, suffixes: NSOrderedSet = FBSnapshotTestCaseDefaultSuffixes(), perPixelTolerance: CGFloat = 0.02, overallTolerance: CGFloat = 0, file: StaticString = #file, line: UInt = #line) {
        FBSnapshotVerifyView(view, identifier: identifier, suffixes: suffixes, perPixelTolerance: perPixelTolerance, overallTolerance: overallTolerance, file: file, line: line)
  }
}

And in Objective-C:

#define FBSnapshotTolerantlyVerifyView(view__, identifier__) \
FBSnapshotVerifyViewWithPixelOptions(view__, identifier__, FBSnapshotTestCaseDefaultSuffixes(), 0.02, 0)

Hope this helps!

davidme-stripe avatar Apr 13 '22 22:04 davidme-stripe

This project already supports a perPixelTolerance parameter, which behaves similarly to the swift-snapshot-testing PR linked in the above thread. I've found that setting this to 0.02 (2%) allows my snapshot tests to pass on both M1 and Intel.

This works for me, when the snapshot was created on an M1 I need to add 0.002 (0.2%) overallTolerance as well.

Deco354 avatar Apr 22 '22 13:04 Deco354

We record screenshots in the same environment we verify them (i.e. we never record on developer devices). That solves the problem quite well.

tdrhq avatar May 04 '23 01:05 tdrhq