Skip to content

Commit

Permalink
Fix snapshot tests on M1 (#1000)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidme-stripe authored Apr 14, 2022
1 parent 82f43a1 commit aa87c49
Show file tree
Hide file tree
Showing 63 changed files with 206 additions and 173 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ class PaymentSheetSnapshotTests: FBSnapshotTestCase {
file: StaticString = #filePath,
line: UInt = #line
) {
FBSnapshotVerifyView(view,
STPSnapshotVerifyView(view,
identifier: identifier,
suffixes: FBSnapshotTestCaseDefaultSuffixes(),
file: file,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ - (void)testVerifyTextChallengeDesign {

[self waitForChallengeResponseTimer];

FBSnapshotVerifyView(challengeResponseViewController.view, @"TextChallengeResponse");
STPSnapshotVerifyView(challengeResponseViewController.view, @"TextChallengeResponse");
}

- (void)testVerifySingleSelectDesign {
Expand All @@ -40,7 +40,7 @@ - (void)testVerifySingleSelectDesign {

[self waitForChallengeResponseTimer];

FBSnapshotVerifyView(challengeResponseViewController.view, @"SingleSelectResponse");
STPSnapshotVerifyView(challengeResponseViewController.view, @"SingleSelectResponse");
}

- (void)testVerifyMultiSelectDesign {
Expand All @@ -49,7 +49,7 @@ - (void)testVerifyMultiSelectDesign {

[self waitForChallengeResponseTimer];

FBSnapshotVerifyView(challengeResponseViewController.view, @"MultiSelectResponse");
STPSnapshotVerifyView(challengeResponseViewController.view, @"MultiSelectResponse");
}

- (void)testVerifyOOBDesign {
Expand All @@ -58,39 +58,39 @@ - (void)testVerifyOOBDesign {

[self waitForChallengeResponseTimer];

FBSnapshotVerifyView(challengeResponseViewController.view, @"OOBResponse");
STPSnapshotVerifyView(challengeResponseViewController.view, @"OOBResponse");
}

- (void)testLoadingAmex {
STDSChallengeResponseViewController *challengeResponseViewController = [self challengeResponseViewControllerForResponse:nil directoryServer:STDSDirectoryServerAmex];
[challengeResponseViewController view];
[challengeResponseViewController setLoading];

FBSnapshotVerifyView(challengeResponseViewController.view, @"LoadingAmex");
STPSnapshotVerifyView(challengeResponseViewController.view, @"LoadingAmex");
}

- (void)testLoadingDiscover {
STDSChallengeResponseViewController *challengeResponseViewController = [self challengeResponseViewControllerForResponse:nil directoryServer:STDSDirectoryServerDiscover];
[challengeResponseViewController view];
[challengeResponseViewController setLoading];

FBSnapshotVerifyView(challengeResponseViewController.view, @"LoadingDiscover");
STPSnapshotVerifyView(challengeResponseViewController.view, @"LoadingDiscover");
}

- (void)testLoadingMastercard {
STDSChallengeResponseViewController *challengeResponseViewController = [self challengeResponseViewControllerForResponse:nil directoryServer:STDSDirectoryServerMastercard];
[challengeResponseViewController view];
[challengeResponseViewController setLoading];

FBSnapshotVerifyView(challengeResponseViewController.view, @"LoadingMastercard");
STPSnapshotVerifyView(challengeResponseViewController.view, @"LoadingMastercard");
}

- (void)testLoadingVisa {
STDSChallengeResponseViewController *challengeResponseViewController = [self challengeResponseViewControllerForResponse:nil directoryServer:STDSDirectoryServerVisa];
[challengeResponseViewController view];
[challengeResponseViewController setLoading];

FBSnapshotVerifyView(challengeResponseViewController.view, @"LoadingVisa");
STPSnapshotVerifyView(challengeResponseViewController.view, @"LoadingVisa");
}

- (STDSChallengeResponseViewController *)challengeResponseViewControllerForResponse:(id<STDSChallengeResponse>)response directoryServer:(STDSDirectoryServer)directoryServer {
Expand Down
6 changes: 6 additions & 0 deletions StripeCore/StripeCore.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
31337A4926E04B6A005C7E02 /* URLSession+Retry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 31337A4826E04B6A005C7E02 /* URLSession+Retry.swift */; };
315BDBDF2788E2B4007BD11F /* STPDispatchFunctions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 315BDBDE2788E2B4007BD11F /* STPDispatchFunctions.swift */; };
3160673F2804DA6C0082B148 /* StripeJSONShared.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3160673E2804DA6C0082B148 /* StripeJSONShared.swift */; };
31606743280768EB0082B148 /* STPSnapshotVerifyView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 31606742280768EB0082B148 /* STPSnapshotVerifyView.swift */; };
31606744280769070082B148 /* FBSnapshotTestCase.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = E61ADAA3270B9299004ED998 /* FBSnapshotTestCase.xcframework */; };
31606741280609840082B148 /* UnknownFields.swift in Sources */ = {isa = PBXBuildFile; fileRef = 31606740280609840082B148 /* UnknownFields.swift */; };
317C4FE0275FF44D003771D7 /* InstallMethod.swift in Sources */ = {isa = PBXBuildFile; fileRef = 317C4FDF275FF44D003771D7 /* InstallMethod.swift */; };
319E36582719EBF700460867 /* ServerErrorMapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 319E36572719EBF700460867 /* ServerErrorMapper.swift */; };
Expand Down Expand Up @@ -121,6 +123,7 @@
31337A4826E04B6A005C7E02 /* URLSession+Retry.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "URLSession+Retry.swift"; sourceTree = "<group>"; };
315BDBDE2788E2B4007BD11F /* STPDispatchFunctions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = STPDispatchFunctions.swift; sourceTree = "<group>"; };
3160673E2804DA6C0082B148 /* StripeJSONShared.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StripeJSONShared.swift; sourceTree = "<group>"; };
31606742280768EB0082B148 /* STPSnapshotVerifyView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = STPSnapshotVerifyView.swift; sourceTree = "<group>"; };
31606740280609840082B148 /* UnknownFields.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UnknownFields.swift; sourceTree = "<group>"; };
317C4FDF275FF44D003771D7 /* InstallMethod.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstallMethod.swift; sourceTree = "<group>"; };
319E36572719EBF700460867 /* ServerErrorMapper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ServerErrorMapper.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -276,6 +279,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
31606744280769070082B148 /* FBSnapshotTestCase.xcframework in Frameworks */,
E6548EE42728AF0900F399B2 /* OHHTTPStubs.xcframework in Frameworks */,
E6548EDA2728AE6B00F399B2 /* XCTest.framework in Frameworks */,
);
Expand Down Expand Up @@ -571,6 +575,7 @@
E6FB9BBA268EA95F000FDB4F /* StripeCoreTestUtils.h */,
E6548EE52728AFB400F399B2 /* TestConstants.swift */,
3126570227B4852600D2F8A8 /* URLRequest+StripeTest.swift */,
31606742280768EB0082B148 /* STPSnapshotVerifyView.swift */,
E6548F7E27339FB100F399B2 /* XCTestCase+Stripe.swift */,
);
path = StripeCoreTestUtils;
Expand Down Expand Up @@ -882,6 +887,7 @@
D0494A70273AF44900FEA715 /* UIImage+StripeCoreTestingUtils.swift in Sources */,
E61ADAA6270B92BD004ED998 /* UIView+StripeCoreTestingUtils.swift in Sources */,
E6CDC469269E81CD0020A962 /* MockAnalyticsClient.swift in Sources */,
31606743280768EB0082B148 /* STPSnapshotVerifyView.swift in Sources */,
E6548EDF2728AEBE00F399B2 /* APIStubbedTestCase.swift in Sources */,
E6548F7F27339FB100F399B2 /* XCTestCase+Stripe.swift in Sources */,
D0CA3DA5279BE0CE00143B1C /* KeyPathExpectation.swift in Sources */,
Expand Down
17 changes: 17 additions & 0 deletions StripeCore/StripeCoreTestUtils/STPSnapshotVerifyView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// STPSnapshotVerifyView.swift
// StripeCoreTestUtils
//
// Created by David Estes on 4/13/22.
//

import Foundation

import FBSnapshotTestCase

public extension FBSnapshotTestCase {
// Calls FBSnapshotVerifyView with a default 2% per-pixel color differentiation, as M1 and Intel machines render shadows differently.
func STPSnapshotVerifyView(_ 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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,6 @@ private extension AnimatedBorderViewSnapshotTest {
line: UInt = #line
) {
view.configure(with: viewModel)
FBSnapshotVerifyView(view, file: file, line: line)
STPSnapshotVerifyView(view, file: file, line: line)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ final class BiometricConsentViewControllerSnapshotTest: FBSnapshotTestCase {
sheetController: VerificationSheetControllerMock()
)

FBSnapshotVerifyView(vc.view)
STPSnapshotVerifyView(vc.view)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ final class CGImage_StripeIdentitySnapshotTest: FBSnapshotTestCase {
}

private extension CGImage_StripeIdentitySnapshotTest {
/// Uses `FBSnapshotVerifyView` to verify image by creating a `UIImageView`
/// Uses `STPSnapshotVerifyView` to verify image by creating a `UIImageView`
func snapshotVerifyImage(
_ image: CGImage?,
file: StaticString = #filePath,
Expand All @@ -153,8 +153,7 @@ private extension CGImage_StripeIdentitySnapshotTest {
return XCTFail("Image was nil", file: file, line: line)
}
let view = UIImageView(image: UIImage(cgImage: image))
// NOTE: Small tolerance to account for discrepancies between CI vs. running locally
FBSnapshotVerifyView(view, perPixelTolerance: 0.01, file: file, line: line)
STPSnapshotVerifyView(view, file: file, line: line)
}

/// Helper method to normalize rects into image coordinates
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,6 @@ private extension CameraScanningViewSnapshotTest {
) {
scanningView.configure(with: viewModel)
scanningView.autosizeHeight(width: SnapshotTestMockData.mockDeviceWidth)
FBSnapshotVerifyView(scanningView, file: file, line: line)
STPSnapshotVerifyView(scanningView, file: file, line: line)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,6 @@ private extension ErrorViewSnapshotTest {
) {
errorView.configure(with: viewModel)
errorView.autosizeHeight(width: SnapshotTestMockData.mockDeviceWidth)
FBSnapshotVerifyView(errorView, file: file, line: line)
STPSnapshotVerifyView(errorView, file: file, line: line)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class HeaderIconViewSnapshotTest: FBSnapshotTestCase {

// Change the tint color and verify it updates
iconView.tintColor = .systemPink
FBSnapshotVerifyView(iconView, identifier: "change_tint")
STPSnapshotVerifyView(iconView, identifier: "change_tint")
}
}

Expand All @@ -64,6 +64,6 @@ private extension HeaderIconViewSnapshotTest {
) {
iconView.configure(with: viewModel)
iconView.autosizeHeight(width: SnapshotTestMockData.mockDeviceWidth)
FBSnapshotVerifyView(iconView, file: file, line: line)
STPSnapshotVerifyView(iconView, file: file, line: line)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,6 @@ private extension HeaderViewSnapshotTest {
) {
headerView.configure(with: viewModel)
headerView.autosizeHeight(width: SnapshotTestMockData.mockDeviceWidth)
FBSnapshotVerifyView(headerView, file: file, line: line)
STPSnapshotVerifyView(headerView, file: file, line: line)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,6 @@ class IdentityFlowViewSnapshotTest: FBSnapshotTestCase {
let view = UIView(frame: CGRect(x: 0, y: 0, width: 350, height: 400))
idFlowView.configure(with: viewModel)
view.addAndPinSubview(idFlowView)
FBSnapshotVerifyView(view, file: file, line: line)
STPSnapshotVerifyView(view, file: file, line: line)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ private extension IdentityHTMLViewSnapshotTest {
) throws {
try view.configure(with: viewModel)
view.autosizeHeight(width: SnapshotTestMockData.mockDeviceWidth)
FBSnapshotVerifyView(view, file: file, line: line)
STPSnapshotVerifyView(view, file: file, line: line)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,6 @@ private extension InstructionListViewSnapshotTest {
) {
view.configure(with: viewModel)
view.autosizeHeight(width: SnapshotTestMockData.mockDeviceWidth)
FBSnapshotVerifyView(view, file: file, line: line)
STPSnapshotVerifyView(view, file: file, line: line)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ private extension InstructionalCameraScanningViewSnapshotTest {
) {
view.configure(with: viewModel)
view.autosizeHeight(width: SnapshotTestMockData.mockDeviceWidth)
FBSnapshotVerifyView(view, file: file, line: line)
STPSnapshotVerifyView(view, file: file, line: line)
}

func makeText(withNumberOfLines numberOfLines: Int) -> String {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,6 @@ private extension ListItemViewSnapshotTest {
listItemView.tintColor = tintColor
listItemView.configure(with: viewModel)
listItemView.autosizeHeight(width: SnapshotTestMockData.mockDeviceWidth)
FBSnapshotVerifyView(listItemView, file: file, line: line)
STPSnapshotVerifyView(listItemView, file: file, line: line)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,6 @@ private extension ListViewSnapshotTest {
) {
listView.configure(with: viewModel)
listView.autosizeHeight(width: SnapshotTestMockData.mockDeviceWidth)
FBSnapshotVerifyView(listView, file: file, line: line)
STPSnapshotVerifyView(listView, file: file, line: line)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,6 @@ private extension NSAttributedString_HTMLSnapshotTest {
let attributedText = try NSAttributedString(htmlText: htmlString, style: style)
textView.attributedText = attributedText
textView.autosizeHeight(width: SnapshotTestMockData.mockDeviceWidth)
FBSnapshotVerifyView(textView, file: file, line: line)
STPSnapshotVerifyView(textView, file: file, line: line)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ final class SuccessViewControllerSnapshotTest: FBSnapshotTestCase {
sheetController: VerificationSheetControllerMock()
)

FBSnapshotVerifyView(vc.view)
STPSnapshotVerifyView(vc.view)

// Verify tint color updates icon background
vc.view.tintColor = .systemPink
FBSnapshotVerifyView(vc.view, identifier: "change_tint")
STPSnapshotVerifyView(vc.view, identifier: "change_tint")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ final class VerificationFlowWebViewSnapshotTests: FBSnapshotTestCase {

func testLoading() {
verificationWebView.load()
FBSnapshotVerifyView(verificationWebView)
STPSnapshotVerifyView(verificationWebView)
}

func testLoaded() {
Expand All @@ -64,12 +64,12 @@ final class VerificationFlowWebViewSnapshotTests: FBSnapshotTestCase {
*/
verificationWebView.webView.backgroundColor = .purple

FBSnapshotVerifyView(verificationWebView)
STPSnapshotVerifyView(verificationWebView)
}

func testError() {
verificationWebView.displayRetryMessage()
FBSnapshotVerifyView(verificationWebView)
STPSnapshotVerifyView(verificationWebView)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,6 @@ final class ButtonSnapshotTest: FBSnapshotTestCase {
line: UInt = #line
) {
button.autosizeHeight(width: 300)
FBSnapshotVerifyView(button, identifier: identifier, file: file, line: line)
STPSnapshotVerifyView(button, identifier: identifier, file: file, line: line)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,6 @@ private extension DateFieldElementSnapshotTest {
line: UInt = #line) {
let view = dateFieldElement.view
view.autosizeHeight(width: 200)
FBSnapshotVerifyView(view, file: file, line: line)
STPSnapshotVerifyView(view, file: file, line: line)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,6 @@ private extension DropdownFieldElementSnapshotTest {
line: UInt = #line) {
let view = dropdownFieldElement.view
view.autosizeHeight(width: 200)
FBSnapshotVerifyView(view, file: file, line: line)
STPSnapshotVerifyView(view, file: file, line: line)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class PhoneNumberElementSnapshotTests: FBSnapshotTestCase {
line: UInt = #line) {
let view = phoneElement.view
view.autosizeHeight(width: 200)
FBSnapshotVerifyView(view, file: file, line: line)
STPSnapshotVerifyView(view, file: file, line: line)
}

override func setUp() {
Expand Down
Binary file modified ...entViewControllerSnapshotTest/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions Tests/Tests/AfterpayPriceBreakdownViewSnapshotTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ class AfterpayPriceBreakdownViewSnapshotTests: FBSnapshotTestCase {
let priceBreakdownView = AfterpayPriceBreakdownView(amount: 1000, currency: "GBP")
let containingView = embedInRenderableView(priceBreakdownView, width: 320, height: 50)

FBSnapshotVerifyView(containingView)
STPSnapshotVerifyView(containingView)
}
}

func testAfterpayInSingleRow() {
let priceBreakdownView = AfterpayPriceBreakdownView(amount: 1000, currency: "USD")
let containingView = embedInRenderableView(priceBreakdownView, width: 500, height: 30)

FBSnapshotVerifyView(containingView)
STPSnapshotVerifyView(containingView)
}
}
8 changes: 4 additions & 4 deletions Tests/Tests/ButtonLinkSnapshotTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,19 @@ class ButtonLinkSnapshotTests: FBSnapshotTestCase {
) {
let size = sut.systemLayoutSizeFitting(UIView.layoutFittingCompressedSize)
sut.bounds = CGRect(origin: .zero, size: size)
FBSnapshotVerifyView(sut, file: file, line: line)
STPSnapshotVerifyView(sut, file: file, line: line)

sut.isHighlighted = true
FBSnapshotVerifyView(sut, identifier: "Highlighted", file: file, line: line)
STPSnapshotVerifyView(sut, identifier: "Highlighted", file: file, line: line)

sut.isHighlighted = false
sut.isEnabled = false
FBSnapshotVerifyView(sut, identifier: "Disabled", file: file, line: line)
STPSnapshotVerifyView(sut, identifier: "Disabled", file: file, line: line)

sut.isHighlighted = false
sut.isEnabled = true
sut.isLoading = true
FBSnapshotVerifyView(sut, identifier: "Loading", file: file, line: line)
STPSnapshotVerifyView(sut, identifier: "Loading", file: file, line: line)
}

}
Expand Down
2 changes: 1 addition & 1 deletion Tests/Tests/CheckboxButtonSnapshotTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class CheckboxButtonSnapshotTests: FBSnapshotTestCase {
) {
view.autosizeHeight(width: 340)
view.backgroundColor = .white
FBSnapshotVerifyView(view, identifier: identifier, file: file, line: line)
STPSnapshotVerifyView(view, identifier: identifier, file: file, line: line)
}

}
Loading

0 comments on commit aa87c49

Please sign in to comment.