-
Notifications
You must be signed in to change notification settings - Fork 215
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
On failure, the reference image uses the wrong DPI, resulting in bizarre diff image #190
Comments
Similar thing (but not the same) reported in #99 (comment) |
Yeah, same for me. |
The problem is that the captured test image has The quick solution looks like: // Copied '[UIImage fb_diffWithImage:]' method with a fix for image scale.
// https://github.com/facebookarchive/ios-snapshot-test-case/blob/master/FBSnapshotTestCase/Categories/UIImage%2BDiff.m#L35
@objc dynamic private func swizzled_fb_diff(
with image: UIImage?
) -> UIImage? {
guard let image = image else { return nil }
let scaleFactor = scale / (max(scale, image.scale))
let imageScaleFactor = image.scale / (max(scale, image.scale))
let scaledSize = size.applying(.identity.scaledBy(x: scaleFactor, y: scaleFactor))
let imageScaledSize = image.size.applying(.identity.scaledBy(x: imageScaleFactor, y: imageScaleFactor))
let imageSize = CGSize(
width: max(scaledSize.width, imageScaledSize.width),
height: max(scaledSize.height, imageScaledSize.height)
)
UIGraphicsBeginImageContextWithOptions(imageSize, true, 0)
guard let context = UIGraphicsGetCurrentContext() else { return nil }
draw(in: CGRect(origin: .zero, size: scaledSize))
context.setAlpha(0.5)
context.beginTransparencyLayer(auxiliaryInfo: nil)
image.draw(in: CGRect(origin: .zero, size: imageScaledSize))
context.setBlendMode(.difference)
context.setFillColor(UIColor.white.cgColor)
context.fill(CGRect(origin: .zero, size: scaledSize))
context.endTransparencyLayer()
let returnImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return returnImage
} |
I opened a PR with the fix #198 |
👋
I am using latest version 8.0. I have configured the following:
When recording, the framework generates the image correctly. The generated image is:
test_iconWithLabel.png
, 600 × 200 pixels, 144 pixels/inchWhen having a test failure in the same image, these are the generated failure diff images:
diff_test_iconWithLabel.png
, 1200 × 400 pixels, 144 pixels/inchfailed_test_iconWithLabel.png
, 600 × 200 pixels, 144 pixels/inchreference_test_iconWithLabel.png
, 600 × 200 pixels, 72 pixels/inchAs you can see:
reference_test_iconWithLabel.png
image does not match the DPI of thetest_iconWithLabel.png
recorded imagediff_test_iconWithLabel.png
contains the following very unexpected content:Find all images attached here: Images.zip
The text was updated successfully, but these errors were encountered: