From bbe2ddfe2f7fec5e94db9d746f3c470da8272103 Mon Sep 17 00:00:00 2001 From: Felix Mau Date: Thu, 10 Mar 2022 14:08:39 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=85=20::=20Fix=20flaky=20snapshot=20test?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../GradientLoadingBarViewTestCase.swift | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Example/ExampleSnapshotTests/GradientLoadingBarView/GradientLoadingBarViewTestCase.swift b/Example/ExampleSnapshotTests/GradientLoadingBarView/GradientLoadingBarViewTestCase.swift index 5a8049f..dbe028a 100644 --- a/Example/ExampleSnapshotTests/GradientLoadingBarView/GradientLoadingBarViewTestCase.swift +++ b/Example/ExampleSnapshotTests/GradientLoadingBarView/GradientLoadingBarViewTestCase.swift @@ -25,6 +25,10 @@ final class GradientLoadingBarViewTestCase: XCTestCase { static let gradientColors = [ #colorLiteral(red: 0.9490196078, green: 0.3215686275, blue: 0.431372549, alpha: 1), #colorLiteral(red: 0.9450980392, green: 0.4784313725, blue: 0.5921568627, alpha: 1), #colorLiteral(red: 0.9529411765, green: 0.737254902, blue: 0.7843137255, alpha: 1), #colorLiteral(red: 0.4274509804, green: 0.8666666667, blue: 0.9490196078, alpha: 1), #colorLiteral(red: 0.7568627451, green: 0.9411764706, blue: 0.9568627451, alpha: 1), ].map(Color.init) + + /// The percentage of pixels that must match. + /// We explicitly reduce the precision for the custom colors test case here, to avoid flaky tests. + static let customColorsPrecision: Float = 0.99 } // MARK: - Test cases @@ -44,6 +48,6 @@ final class GradientLoadingBarViewTestCase: XCTestCase { .frame(width: Config.frame.width, height: Config.frame.height) // Then - assertSnapshot(matching: gradientLoadingBarView, as: .image) + assertSnapshot(matching: gradientLoadingBarView, as: .image(precision: Config.customColorsPrecision)) } }