pointfreeco / swift-snapshot-testing

📸 Delightful Swift snapshot testing.
https://www.pointfree.co/episodes/ep41-a-tour-of-snapshot-testing
MIT License
3.79k stars 581 forks source link

Issue with UITableViewCell layoutMargins depending on device #194

Open kremizask opened 5 years ago

kremizask commented 5 years ago

Thank you for your work on this library and the awesome video series!

I am snapshotting a UITableViewController using assertSnapshot(matching: sut, as: .image(on: .iPhoneX)). When running on a iPhone XS Max, the test fails.

What seems to be the cause of this is that the cell's (and contentView's) layout margins vary depending on the device:

You can reproduce the issue by running the following project's tests in iPhone XS Max: SnapshotMarginsIIssue.zip

Any ideas on how I can make the tests device agnostic?

stephencelis commented 5 years ago

Hi @kremizask! While you can use .iPhoneX, etc., configurations to emulate the traits and layout of specific devices, you still must use a consistent simulator. From the README:

⚠️ Warning: Snapshots must be compared using a simulator with the same OS, device gamut, and scale as the simulator that originally took the reference to avoid discrepancies between images.

It's unfortunately just not possible to render screen shots of UIKit across simulators that differ in any of these three ways. We reported the discrepancy to Apple but they closed as "won't fix." As long as you run things on a consistent device or encode the device in the screen shot name, you should be fine, though!

183 should eventually make this a lil easier.

kremizask commented 5 years ago

Hi @stephencelis! If I understand correctly, these 2 Simulators I am using for recording the snapshot (iPhone X) and actually run the tests on (iPhone XS Max) should be compatible. They both have gamut: P3, scale: 3 and I recorded/ran the tests on iOS 12.2 Simulators (I had the same results with 12.1). Am I missing something?