diff --git a/.circleci/config.yml b/.circleci/config.yml index 5b9b607671..68277b9a89 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -352,6 +352,7 @@ jobs: spm-revenuecat-ui-ios-15: <<: *base-job + resource_class: macos.m1.medium.gen1 steps: - checkout - update-spm-installation-commit @@ -376,6 +377,7 @@ jobs: spm-revenuecat-ui-ios-16: <<: *base-job + resource_class: macos.m1.medium.gen1 steps: - checkout - update-spm-installation-commit @@ -407,6 +409,7 @@ jobs: spm-revenuecat-ui-ios-17: <<: *base-job + resource_class: macos.m1.medium.gen1 steps: - checkout - update-spm-installation-commit diff --git a/Package.swift b/Package.swift index fcf5ce9e25..082d1134ef 100644 --- a/Package.swift +++ b/Package.swift @@ -11,7 +11,8 @@ let shouldIncludeDocCPlugin = environmentVariables["INCLUDE_DOCC_PLUGIN"] == "tr var dependencies: [Package.Dependency] = [ .package(url: "git@github.com:Quick/Nimble.git", from: "10.0.0"), - .package(url: "git@github.com:pointfreeco/swift-snapshot-testing.git", from: "1.11.0") + // SST requires iOS 13 starting from version 1.13.0 + .package(url: "git@github.com:pointfreeco/swift-snapshot-testing.git", .upToNextMinor(from: "1.12.0")) ] if shouldIncludeDocCPlugin { dependencies.append(.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0")) diff --git a/RevenueCatUI/Data/UserInterfaceIdiom.swift b/RevenueCatUI/Data/UserInterfaceIdiom.swift index d231fc7ddc..f4127c1ef6 100644 --- a/RevenueCatUI/Data/UserInterfaceIdiom.swift +++ b/RevenueCatUI/Data/UserInterfaceIdiom.swift @@ -34,21 +34,39 @@ extension UserInterfaceIdiom { } @available(iOS 13.0, tvOS 13.0, macOS 10.15, watchOS 6.2, *) -struct UserInterfaceIdiomEnvironmentKey: EnvironmentKey { +extension EnvironmentValues { + + var userInterfaceIdiom: UserInterfaceIdiom { + get { self[UserInterfaceIdiomEnvironmentKey.self] } + set { self[UserInterfaceIdiomEnvironmentKey.self] = newValue } + } + + #if DEBUG + var isRunningSnapshots: Bool { + get { self[RunningSnapshotsEnvironmentKey.self] } + set { self[RunningSnapshotsEnvironmentKey.self] = newValue } + } + #endif + +} + +// MARK: - + +@available(iOS 13.0, tvOS 13.0, macOS 10.15, watchOS 6.2, *) +private struct UserInterfaceIdiomEnvironmentKey: EnvironmentKey { static var defaultValue: UserInterfaceIdiom = .default } +#if DEBUG @available(iOS 13.0, tvOS 13.0, macOS 10.15, watchOS 6.2, *) -extension EnvironmentValues { +private struct RunningSnapshotsEnvironmentKey: EnvironmentKey { - var userInterfaceIdiom: UserInterfaceIdiom { - get { self[UserInterfaceIdiomEnvironmentKey.self] } - set { self[UserInterfaceIdiomEnvironmentKey.self] = newValue } - } + static var defaultValue: Bool = false } +#endif // MARK: - UIKit diff --git a/RevenueCatUI/Views/ProgressView.swift b/RevenueCatUI/Views/ProgressView.swift new file mode 100644 index 0000000000..4fb12fc9a8 --- /dev/null +++ b/RevenueCatUI/Views/ProgressView.swift @@ -0,0 +1,32 @@ +// +// ProgressView.swift +// +// +// Created by Nacho Soto on 12/20/23. +// + +import Foundation +import SwiftUI + +/// `SwiftUI.ProgressView` overload that becomes non-animated during snapshots. +@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *) +struct ProgressView: View { + + #if DEBUG + @Environment(\.isRunningSnapshots) + private var isRunningSnapshots + #endif + + var body: some View { + #if DEBUG + if self.isRunningSnapshots { + SwiftUI.ProgressView(value: 0.5) + } else { + SwiftUI.ProgressView() + } + #else + SwiftUI.ProgressView() + #endif + } + +} diff --git a/Tests/RevenueCatUITests/BaseSnapshotTest.swift b/Tests/RevenueCatUITests/BaseSnapshotTest.swift index 864d4d52c7..98b628a108 100644 --- a/Tests/RevenueCatUITests/BaseSnapshotTest.swift +++ b/Tests/RevenueCatUITests/BaseSnapshotTest.swift @@ -33,10 +33,16 @@ import XCTest @MainActor class BaseSnapshotTest: TestCase { - // swiftlint:disable:next unneeded_override override class func setUp() { super.setUp() + // See https://github.com/pointfreeco/swift-snapshot-testing/pull/702 and + // https://github.com/pointfreeco/swift-snapshot-testing/pull/666 + expect(MTLCreateSystemDefaultDevice()).toNot( + beNil(), + description: "Metal is required for perceptuallyCompare, but not available on this machine." + ) + // Uncomment this line to manually record snapshots: // isRecording = true } @@ -60,6 +66,7 @@ class BaseSnapshotTest: TestCase { fonts: fonts, introEligibility: introEligibility, purchaseHandler: purchaseHandler) + .environment(\.isRunningSnapshots, true) } private static func skipTestIfNeeded() throws { diff --git a/Tests/TestingApps/PaywallsTester/PaywallsTester.xcworkspace/xcshareddata/swiftpm/Package.resolved b/Tests/TestingApps/PaywallsTester/PaywallsTester.xcworkspace/xcshareddata/swiftpm/Package.resolved index ba7b815e30..f64d2a1fed 100644 --- a/Tests/TestingApps/PaywallsTester/PaywallsTester.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/Tests/TestingApps/PaywallsTester/PaywallsTester.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -32,8 +32,8 @@ "kind" : "remoteSourceControl", "location" : "git@github.com:pointfreeco/swift-snapshot-testing.git", "state" : { - "revision" : "dc46eeb3928a75390651fac6c1ef7f93ad59a73b", - "version" : "1.11.1" + "revision" : "26ed3a2b4a2df47917ca9b790a57f91285b923fb", + "version" : "1.12.0" } } ], diff --git a/Tests/UnitTests/TestHelpers/SnapshotTesting+Extensions.swift b/Tests/UnitTests/TestHelpers/SnapshotTesting+Extensions.swift index fa3cb908b6..82b8683ec8 100644 --- a/Tests/UnitTests/TestHelpers/SnapshotTesting+Extensions.swift +++ b/Tests/UnitTests/TestHelpers/SnapshotTesting+Extensions.swift @@ -155,8 +155,8 @@ private let traits: UITraitCollection = .init(displayScale: 1) #endif -private let perceptualPrecision: Float = 0.97 -private let timeout: DispatchTimeInterval = .seconds(5) +private let perceptualPrecision: Float = 0.94 +private let timeout: DispatchTimeInterval = .seconds(3) private let pollInterval: DispatchTimeInterval = .milliseconds(100) // MARK: - Private diff --git a/Tests/purchases-ios-snapshots-commit b/Tests/purchases-ios-snapshots-commit index 16d7068f16..d10b66a2d5 100644 --- a/Tests/purchases-ios-snapshots-commit +++ b/Tests/purchases-ios-snapshots-commit @@ -1 +1 @@ -38eb67f4697144bb842c1e7ac45f71329887526a +70a3aed03c02fb2a3d2c47cee3377fe0c097ec48