Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 16 additions & 24 deletions Package.resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice 🤩

)
]
if shouldIncludeDocCPlugin {
Expand Down
5 changes: 3 additions & 2 deletions Package@swift-5.8.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Comment on lines +14 to +15
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🫶

.package(
url: "https://github.com/pointfreeco/swift-snapshot-testing",
revision: "26ed3a2b4a2df47917ca9b790a57f91285b923fb"
exact: "1.17.7"
)
]
if shouldIncludeDocCPlugin {
Expand Down
43 changes: 31 additions & 12 deletions RevenueCat.xcworkspace/xcshareddata/swiftpm/Package.resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,15 @@ 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
}

func testCanGetProductEntitlementMappingFromFallbackURL() async throws {
let productEntitlementMapping = try await self.purchases.productEntitlementMapping()

expect(productEntitlementMapping.entitlementsByProduct).toNot(beEmpty())
assertSnapshot(matching: productEntitlementMapping, as: .formattedJson)
assertSnapshot(of: productEntitlementMapping, as: .formattedJson)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ private extension PaywallDataValidationTests {
#endif

assertSnapshot(
matching: paywall.withTestAssetBaseURL,
of: paywall.withTestAssetBaseURL,
as: .formattedJson,
file: file,
testName: test,
Expand Down
27 changes: 15 additions & 12 deletions Tests/RevenueCatUITests/Helpers/TestCase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ class TestCase: XCTestCase {
@MainActor
override class func setUp() {
XCTestObservationCenter.shared.addTestObserver(CurrentTestCaseTracker.shared)

SnapshotTests.updateSnapshotsIfNeeded()
}

@MainActor
Expand All @@ -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
Expand All @@ -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"
}

}
2 changes: 1 addition & 1 deletion Tests/StoreKitUnitTests/TestHelpers/ImageSnapshot.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func haveValidSnapshot<Value>(
}

guard let errorMessage = verifySnapshot(
matching: value,
of: value,
as: strategy,
named: name,
record: recording,
Expand Down
12 changes: 6 additions & 6 deletions Tests/UnitTests/Ads/Events/AdEventsRequestTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,39 +35,39 @@ 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 {
let event = AdEvent.loaded(Self.eventCreationData, Self.loadedData)
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 {
let event = AdEvent.displayed(Self.eventCreationData, Self.eventData)
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 {
let event = AdEvent.opened(Self.eventCreationData, Self.openedData)
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 {
let event = AdEvent.revenue(Self.eventCreationData, Self.revenueData)
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 {
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
9 changes: 5 additions & 4 deletions Tests/UnitTests/Misc/AnyEncodableTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// Created by Nacho Soto on 3/2/22.

import Nimble
import SnapshotTesting
import XCTest

@testable import RevenueCat
Expand All @@ -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() {
Expand All @@ -31,7 +32,7 @@ class AnyEncodableTests: TestCase {
"c": "3"
]

assertSnapshot(matching: AnyEncodable(dictionary), as: .json)
assertSnapshot(of: AnyEncodable(dictionary), as: .json)
}

func testDictionaryWithDifferentValues() {
Expand All @@ -42,7 +43,7 @@ class AnyEncodableTests: TestCase {
"d": nil
]

assertSnapshot(matching: AnyEncodable(dictionary), as: .json)
assertSnapshot(of: AnyEncodable(dictionary), as: .json)
}

func testNestedDictionary() throws {
Expand All @@ -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
Expand Down
Loading