Disable record on regular snapshot tests to prevent from passing after retry (#6303)

* update snapshot testing

* use version 1.17.7
This commit is contained in:
Cesar de la Vega authored and GitHub committed 2026-02-23 10:39:11 +01:00
1 parent 8ef77105d0
commit ae65e3f6e4
20 files changed
+122 -169

No files matched your search

+24 -32
View File
@@ -18,15 +18,6 @@
"version" : "2.2.2"
}
},
{
"identity" : "flyingfox",
"kind" : "remoteSourceControl",
"location" : "https://github.com/swhitty/FlyingFox.git",
"state" : {
"revision" : "f7829d4aca8cbfecb410a1cce872b1b045224aa1",
"version" : "0.16.0"
}
},
{
"identity" : "nimble",
"kind" : "remoteSourceControl",
@@ -37,30 +28,12 @@
}
},
{
"identity" : "ohhttpstubs",
"identity" : "swift-custom-dump",
"kind" : "remoteSourceControl",
"location" : "https://github.com/AliSoftware/OHHTTPStubs.git",
"location" : "https://github.com/pointfreeco/swift-custom-dump",
"state" : {
"revision" : "12f19662426d0434d6c330c6974d53e2eb10ecd9",
"version" : "9.1.0"
}
},
{
"identity" : "simpledebugger",
"kind" : "remoteSourceControl",
"location" : "https://github.com/EmergeTools/SimpleDebugger.git",
"state" : {
"revision" : "f065263eb5db95874b690408d136b573c939db9e",
"version" : "1.0.0"
}
},
{
"identity" : "snapshotpreviews",
"kind" : "remoteSourceControl",
"location" : "https://github.com/EmergeTools/SnapshotPreviews.git",
"state" : {
"revision" : "6dfb281493e48e7c09ae9717593ae0b8eb47b15c",
"version" : "0.11.0"
"revision" : "2a2a938798236b8fa0bc57c453ee9de9f9ec3ab0",
"version" : "1.4.1"
}
},
{
@@ -68,7 +41,26 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-snapshot-testing",
"state" : {
"revision" : "26ed3a2b4a2df47917ca9b790a57f91285b923fb"
"revision" : "bf8d8c27f0f0c6d5e77bff0db76ab68f2050d15d",
"version" : "1.18.9"
}
},
{
"identity" : "swift-syntax",
"kind" : "remoteSourceControl",
"location" : "https://github.com/swiftlang/swift-syntax",
"state" : {
"revision" : "4799286537280063c85a32f09884cfbca301b1a1",
"version" : "602.0.0"
}
},
{
"identity" : "xctest-dynamic-overlay",
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/xctest-dynamic-overlay",
"state" : {
"revision" : "dfd70507def84cb5fb821278448a262c6ff2bbad",
"version" : "1.9.0"
}
}
],
+1 -2
View File
@@ -47,10 +47,9 @@ let shouldIncludeDocCPlugin = environmentVariables["INCLUDE_DOCC_PLUGIN"] == "tr
var dependencies: [Package.Dependency] = [
.package(url: "https://github.com/quick/nimble", exact: "13.7.1"),
// SST requires iOS 13 starting from version 1.13.0
.package(
url: "https://github.com/pointfreeco/swift-snapshot-testing",
revision: "26ed3a2b4a2df47917ca9b790a57f91285b923fb"
exact: "1.18.9"
)
]
if shouldIncludeDocCPlugin {
+3 -2
View File
@@ -11,10 +11,11 @@ let shouldIncludeDocCPlugin = environmentVariables["INCLUDE_DOCC_PLUGIN"] == "tr
var dependencies: [Package.Dependency] = [
.package(url: "https://github.com/quick/nimble", exact: "13.7.1"),
// SST requires iOS 13 starting from version 1.13.0
// Uses SST 1.17.7, the last version with swift-tools-version 5.7, which includes the
// `withSnapshotTesting` API needed to prevent auto-recording in CI.
.package(
url: "https://github.com/pointfreeco/swift-snapshot-testing",
revision: "26ed3a2b4a2df47917ca9b790a57f91285b923fb"
exact: "1.17.7"
)
]
if shouldIncludeDocCPlugin {
@@ -1,14 +1,5 @@
{
"pins" : [
{
"identity" : "accessibilitysnapshot",
"kind" : "remoteSourceControl",
"location" : "https://github.com/EmergeTools/AccessibilitySnapshot.git",
"state" : {
"revision" : "54046d8fa44b9fa9f0e2229526f6ed89cb5e0ec2",
"version" : "1.0.2"
}
},
{
"identity" : "cwlcatchexception",
"kind" : "remoteSourceControl",
@@ -68,8 +59,17 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/EmergeTools/SnapshotPreviews.git",
"state" : {
"revision" : "0d1c6c282a83e5350899046efd3493558dc2d3c8",
"version" : "0.10.24"
"revision" : "6dfb281493e48e7c09ae9717593ae0b8eb47b15c",
"version" : "0.11.0"
}
},
{
"identity" : "swift-custom-dump",
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-custom-dump",
"state" : {
"revision" : "2a2a938798236b8fa0bc57c453ee9de9f9ec3ab0",
"version" : "1.4.1"
}
},
{
@@ -77,7 +77,26 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-snapshot-testing",
"state" : {
"revision" : "26ed3a2b4a2df47917ca9b790a57f91285b923fb"
"revision" : "bf8d8c27f0f0c6d5e77bff0db76ab68f2050d15d",
"version" : "1.18.9"
}
},
{
"identity" : "swift-syntax",
"kind" : "remoteSourceControl",
"location" : "https://github.com/swiftlang/swift-syntax",
"state" : {
"revision" : "4799286537280063c85a32f09884cfbca301b1a1",
"version" : "602.0.0"
}
},
{
"identity" : "xctest-dynamic-overlay",
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/xctest-dynamic-overlay",
"state" : {
"revision" : "dfd70507def84cb5fb821278448a262c6ff2bbad",
"version" : "1.9.0"
}
}
],
@@ -55,7 +55,7 @@ class FallbackURLSignedBackendStoreKit2IntegrationTests: BaseStoreKitIntegration
let receivedOfferings = try await self.purchases.offerings()
expect(receivedOfferings.all).toNot(beEmpty())
assertSnapshot(matching: receivedOfferings.response, as: .formattedJson)
assertSnapshot(of: receivedOfferings.response, as: .formattedJson)
expect(receivedOfferings.contents.originalSource) == .fallbackUrl
}
@@ -63,7 +63,7 @@ class FallbackURLSignedBackendStoreKit2IntegrationTests: BaseStoreKitIntegration
let productEntitlementMapping = try await self.purchases.productEntitlementMapping()
expect(productEntitlementMapping.entitlementsByProduct).toNot(beEmpty())
assertSnapshot(matching: productEntitlementMapping, as: .formattedJson)
assertSnapshot(of: productEntitlementMapping, as: .formattedJson)
}
}
@@ -98,7 +98,7 @@ class BaseLoadShedderStoreKitIntegrationTests: BaseStoreKitIntegrationTests {
expect(receivedOfferings.all).toNot(beEmpty())
assertSnapshot(matching: receivedOfferings.response, as: .formattedJson)
assertSnapshot(of: receivedOfferings.response, as: .formattedJson)
self.logger.verifyMessageWasLogged(
Strings.network.request_handled_by_load_shedder(
@@ -174,7 +174,7 @@ class StoreKit1IntegrationTests: BaseStoreKitIntegrationTests {
let receivedOfferings = try await self.purchases.offerings()
expect(receivedOfferings.all).toNot(beEmpty())
assertSnapshot(matching: receivedOfferings.response, as: .formattedJson)
assertSnapshot(of: receivedOfferings.response, as: .formattedJson)
self.logger.verifyMessageWasLogged(Strings.offering.vending_offerings_cache_from_memory,
level: .debug)
@@ -293,7 +293,7 @@ private extension PaywallDataValidationTests {
#endif
assertSnapshot(
matching: paywall.withTestAssetBaseURL,
of: paywall.withTestAssetBaseURL,
as: .formattedJson,
file: file,
testName: test,
+15 -12
View File
@@ -33,8 +33,6 @@ class TestCase: XCTestCase {
@MainActor
override class func setUp() {
XCTestObservationCenter.shared.addTestObserver(CurrentTestCaseTracker.shared)
SnapshotTests.updateSnapshotsIfNeeded()
}
@MainActor
@@ -49,6 +47,18 @@ class TestCase: XCTestCase {
self.initializeLogger()
}
override func invokeTest() {
if SnapshotTests.shouldRecordSnapshots {
withSnapshotTesting(record: .all) {
super.invokeTest()
}
} else {
withSnapshotTesting(record: .never) {
super.invokeTest()
}
}
}
@MainActor
override func tearDown() {
self.logger = nil
@@ -61,15 +71,8 @@ class TestCase: XCTestCase {
}
private enum SnapshotTests {
private static var environmentVariableChecked = false
static func updateSnapshotsIfNeeded() {
guard !Self.environmentVariableChecked else { return }
if ProcessInfo.processInfo.environment["CIRCLECI_TESTS_GENERATE_REVENUECAT_UI_SNAPSHOTS"] == "1" {
isRecording = true
}
static var shouldRecordSnapshots: Bool {
return ProcessInfo.processInfo
.environment["CIRCLECI_TESTS_GENERATE_REVENUECAT_UI_SNAPSHOTS"] == "true"
}
}
@@ -32,7 +32,7 @@ func haveValidSnapshot<Value>(
}
guard let errorMessage = verifySnapshot(
matching: value,
of: value,
as: strategy,
named: name,
record: recording,
@@ -35,7 +35,7 @@ class AdFeatureEventsRequestTests: TestCase {
let storedEvent = try Self.createStoredAdEvent(from: event)
let requestEvent: AdEventsRequest.AdEventRequest = try XCTUnwrap(.init(storedEvent: storedEvent))
assertSnapshot(matching: requestEvent, as: .formattedJson)
assertSnapshot(of: requestEvent, as: .formattedJson)
}
func testLoadedEvent() throws {
@@ -43,7 +43,7 @@ class AdFeatureEventsRequestTests: TestCase {
let storedEvent = try Self.createStoredAdEvent(from: event)
let requestEvent: AdEventsRequest.AdEventRequest = try XCTUnwrap(.init(storedEvent: storedEvent))
assertSnapshot(matching: requestEvent, as: .formattedJson)
assertSnapshot(of: requestEvent, as: .formattedJson)
}
func testDisplayedEvent() throws {
@@ -51,7 +51,7 @@ class AdFeatureEventsRequestTests: TestCase {
let storedEvent = try Self.createStoredAdEvent(from: event)
let requestEvent: AdEventsRequest.AdEventRequest = try XCTUnwrap(.init(storedEvent: storedEvent))
assertSnapshot(matching: requestEvent, as: .formattedJson)
assertSnapshot(of: requestEvent, as: .formattedJson)
}
func testOpenedEvent() throws {
@@ -59,7 +59,7 @@ class AdFeatureEventsRequestTests: TestCase {
let storedEvent = try Self.createStoredAdEvent(from: event)
let requestEvent: AdEventsRequest.AdEventRequest = try XCTUnwrap(.init(storedEvent: storedEvent))
assertSnapshot(matching: requestEvent, as: .formattedJson)
assertSnapshot(of: requestEvent, as: .formattedJson)
}
func testRevenueEvent() throws {
@@ -67,7 +67,7 @@ class AdFeatureEventsRequestTests: TestCase {
let storedEvent = try Self.createStoredAdEvent(from: event)
let requestEvent: AdEventsRequest.AdEventRequest = try XCTUnwrap(.init(storedEvent: storedEvent))
assertSnapshot(matching: requestEvent, as: .formattedJson)
assertSnapshot(of: requestEvent, as: .formattedJson)
}
func testCanInitFromDeserializedEvent() throws {
@@ -96,7 +96,7 @@ class AdFeatureEventsRequestTests: TestCase {
let requestEvent = try XCTUnwrap(AdEventsRequest.AdEventRequest(storedEvent: deserializedEvent))
assertSnapshot(matching: requestEvent, as: .formattedJson)
assertSnapshot(of: requestEvent, as: .formattedJson)
}
func testAdEventWithoutMillisecondPrecisionIsParsed() throws {
@@ -38,7 +38,7 @@ class CustomerCenterFeatureEventsRequestTests: TestCase {
FeatureEventsRequest.CustomerCenterEventBaseRequest.createBase(from: storedEvent)
)
assertSnapshot(matching: requestEvent, as: .formattedJson)
assertSnapshot(of: requestEvent, as: .formattedJson)
}
func testCanInitFromDeserializedEvent() throws {
@@ -69,7 +69,7 @@ class CustomerCenterFeatureEventsRequestTests: TestCase {
let requestEvent =
try XCTUnwrap(FeatureEventsRequest.CustomerCenterEventBaseRequest.createBase(from: deserializedEvent))
assertSnapshot(matching: requestEvent, as: .formattedJson)
assertSnapshot(of: requestEvent, as: .formattedJson)
}
func testCustomerCenterEventWithoutMillisecondPrecisionIsParsed() throws {
+5 -4
View File
@@ -12,6 +12,7 @@
// Created by Nacho Soto on 3/2/22.
import Nimble
import SnapshotTesting
import XCTest
@testable import RevenueCat
@@ -21,7 +22,7 @@ class AnyEncodableTests: TestCase {
func testEmptyDictionary() {
let empty: [String: Any] = [:]
assertSnapshot(matching: AnyEncodable(empty), as: .json)
assertSnapshot(of: AnyEncodable(empty), as: .json)
}
func testHomogenousDictionary() {
@@ -31,7 +32,7 @@ class AnyEncodableTests: TestCase {
"c": "3"
]
assertSnapshot(matching: AnyEncodable(dictionary), as: .json)
assertSnapshot(of: AnyEncodable(dictionary), as: .json)
}
func testDictionaryWithDifferentValues() {
@@ -42,7 +43,7 @@ class AnyEncodableTests: TestCase {
"d": nil
]
assertSnapshot(matching: AnyEncodable(dictionary), as: .json)
assertSnapshot(of: AnyEncodable(dictionary), as: .json)
}
func testNestedDictionary() throws {
@@ -64,7 +65,7 @@ class AnyEncodableTests: TestCase {
]
assertSnapshot(
matching: AnyEncodable(dictionary),
of: AnyEncodable(dictionary),
as: .json,
// Formatting `Double`s changed in iOS 17
testName: CurrentTestCaseTracker.osVersionAndTestName
+14 -12
View File
@@ -38,8 +38,6 @@ class TestCase: XCTestCase {
@MainActor
override class func setUp() {
XCTestObservationCenter.shared.addTestObserver(CurrentTestCaseTracker.shared)
SnapshotTests.updateSnapshotsIfNeeded()
}
@MainActor
@@ -54,6 +52,18 @@ class TestCase: XCTestCase {
self.initializeLogger()
}
override func invokeTest() {
if SnapshotTests.shouldRecordSnapshots {
withSnapshotTesting(record: .all) {
super.invokeTest()
}
} else {
withSnapshotTesting(record: .never) {
super.invokeTest()
}
}
}
@MainActor
override func tearDown() {
self.logger = nil
@@ -66,17 +76,9 @@ class TestCase: XCTestCase {
}
private enum SnapshotTests {
private static var environmentVariableChecked = false
static func updateSnapshotsIfNeeded() {
guard !Self.environmentVariableChecked else { return }
if ProcessInfo.processInfo.environment["CIRCLECI_TESTS_GENERATE_SNAPSHOTS"] == "1" {
isRecording = true
}
static var shouldRecordSnapshots: Bool {
return ProcessInfo.processInfo.environment["CIRCLECI_TESTS_GENERATE_SNAPSHOTS"] == "true"
}
}
extension ForceServerErrorStrategy {
+1 -1
View File
@@ -106,7 +106,7 @@ class MockHTTPClient: HTTPClient {
self.calls.append(call)
if self.shouldAssertSnapshot {
assertSnapshot(matching: call,
assertSnapshot(of: call,
as: .formattedJson,
file: self.sourceTestFile,
testName: CurrentTestCaseTracker.osVersionAndTestName)
@@ -55,7 +55,7 @@ class DiagnosticsEventEncodingTests: TestCase {
)
func testEncoding() {
assertSnapshot(matching: self.exampleEvent, as: .backwardsCompatibleFormattedJson)
assertSnapshot(of: self.exampleEvent, as: .backwardsCompatibleFormattedJson)
}
func testReencoding() {
@@ -263,24 +263,24 @@ class CustomerInfoEncodingTests: BaseHTTPResponseTest {
}
func testEncoding() {
assertSnapshot(matching: self.customerInfo, as: .backwardsCompatibleFormattedJson)
assertSnapshot(of: self.customerInfo, as: .backwardsCompatibleFormattedJson)
}
func testEncodingWithVerifiedResponse() {
assertSnapshot(matching: self.customerInfo.copy(with: .verified,
httpResponseOriginalSource: .mainServer),
assertSnapshot(of: self.customerInfo.copy(with: .verified,
httpResponseOriginalSource: .mainServer),
as: .backwardsCompatibleFormattedJson)
}
func testEncodingWithFailedVerificationResponse() {
assertSnapshot(matching: self.customerInfo.copy(with: .failed,
httpResponseOriginalSource: .mainServer),
assertSnapshot(of: self.customerInfo.copy(with: .failed,
httpResponseOriginalSource: .mainServer),
as: .backwardsCompatibleFormattedJson)
}
func testEncodingLoadShedderResponse() throws {
assertSnapshot(matching: self.customerInfo.copy(with: .failed,
httpResponseOriginalSource: .loadShedder),
assertSnapshot(of: self.customerInfo.copy(with: .failed,
httpResponseOriginalSource: .loadShedder),
as: .backwardsCompatibleFormattedJson)
}
@@ -31,7 +31,7 @@ class PaywallFeatureEventsRequestTests: TestCase {
let storedEvent = try Self.createStoredFeatureEvent(from: event)
let requestEvent: FeatureEventsRequest.PaywallEvent = try XCTUnwrap(.init(storedEvent: storedEvent))
assertSnapshot(matching: requestEvent, as: .formattedJson)
assertSnapshot(of: requestEvent, as: .formattedJson)
}
func testCancelEvent() throws {
@@ -39,7 +39,7 @@ class PaywallFeatureEventsRequestTests: TestCase {
let storedEvent = try Self.createStoredFeatureEvent(from: event)
let requestEvent: FeatureEventsRequest.PaywallEvent = try XCTUnwrap(.init(storedEvent: storedEvent))
assertSnapshot(matching: requestEvent, as: .formattedJson)
assertSnapshot(of: requestEvent, as: .formattedJson)
}
func testCloseEvent() throws {
@@ -47,7 +47,7 @@ class PaywallFeatureEventsRequestTests: TestCase {
let storedEvent = try Self.createStoredFeatureEvent(from: event)
let requestEvent: FeatureEventsRequest.PaywallEvent = try XCTUnwrap(.init(storedEvent: storedEvent))
assertSnapshot(matching: requestEvent, as: .formattedJson)
assertSnapshot(of: requestEvent, as: .formattedJson)
}
func testCanInitFromDeserializedEvent() throws {
@@ -79,7 +79,7 @@ class PaywallFeatureEventsRequestTests: TestCase {
let requestEvent = try XCTUnwrap(FeatureEventsRequest.PaywallEvent(storedEvent: deserializedEvent))
assertSnapshot(matching: requestEvent, as: .formattedJson)
assertSnapshot(of: requestEvent, as: .formattedJson)
}
func testPaywallEventWithoutMillisecondPrecisionIsParsed() throws {
@@ -1,4 +1,5 @@
import Nimble
import SnapshotTesting
import XCTest
@testable import RevenueCat
@@ -217,7 +218,7 @@ private extension ProductRequestDataTests {
testName: String = #function,
line: UInt = #line) {
assertSnapshot(
matching: data,
of: data,
as: .formattedJson,
testName: testName,
line: line
@@ -22,71 +22,6 @@ import SwiftUI
@testable import RevenueCat
// MARK: - Overloads for Xcode Cloud support
func assertSnapshot<Value, Format>(
matching value: @autoclosure () throws -> Value,
as snapshotting: Snapshotting<Value, Format>,
named name: String? = nil,
record recording: Bool = false,
timeout: TimeInterval = 5,
file: StaticString = #file,
testName: String = #function,
line: UInt = #line
) {
let failure = verifySnapshot(
matching: try value(),
as: snapshotting,
named: name,
record: recording,
timeout: timeout,
file: file,
testName: testName,
line: line
)
if let message = failure {
XCTFail(message, file: file, line: line)
}
}
func verifySnapshot<Value, Format>(
matching value: @autoclosure () throws -> Value,
as snapshotting: Snapshotting<Value, Format>,
named name: String? = nil,
record recording: Bool = false,
timeout: TimeInterval = 5,
file: StaticString = #file,
testName: String = #function,
line: UInt = #line
) -> String? {
let snapshotDirectory: String?
if ProcessInfo.isXcodeCloud {
let ciPathPrefix = "/Volumes/workspace/repository/ci_scripts/"
let components = URL(string: file.description)!.pathComponents
let projectIndex = components.firstIndex(of: "repository")!
let folders = components[(projectIndex + 1)..<components.endIndex - 1].joined(separator: "/")
let fileName = (components[components.endIndex - 1] as NSString).deletingPathExtension
snapshotDirectory = "\(ciPathPrefix)\(folders)/__Snapshots__/\(fileName)"
} else {
snapshotDirectory = nil
}
return SnapshotTesting.verifySnapshot(
matching: try value(),
as: snapshotting,
named: name,
record: recording,
snapshotDirectory: snapshotDirectory,
timeout: timeout,
file: file,
testName: testName,
line: line
)
}
// MARK: - Snapshotting extensions
extension Snapshotting where Value == Encodable, Format == String {