Skip to content

Commit 361d2d7

Browse files
authored
Fix integration tests. (#3294)
* Fix integration tests. * wip * wip
1 parent da6ff4d commit 361d2d7

File tree

5 files changed

+80
-44
lines changed

5 files changed

+80
-44
lines changed

ComposableArchitecture.xcworkspace/xcshareddata/swiftpm/Package.resolved

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Examples/Integration/Integration/IntegrationApp.swift

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
@_spi(Logging) import ComposableArchitecture
2+
import IssueReporting
23
import SwiftUI
34
import TestCases
45

@@ -48,13 +49,16 @@ final class IntegrationSceneDelegate: NSObject, UIWindowSceneDelegate {
4849
self.keyWindow.makeKeyAndVisible()
4950
}
5051
}
52+
5153
final class IntegrationAppDelegate: NSObject, UIApplicationDelegate {
5254
func application(
5355
_ application: UIApplication,
5456
configurationForConnecting connectingSceneSession: UISceneSession,
5557
options: UIScene.ConnectionOptions
5658
) -> UISceneConfiguration {
59+
UIView.setAnimationsEnabled(false)
5760
Logger.shared.isEnabled = true
61+
IssueReporters.current.append(NotificationReporter())
5862
let sceneConfig = UISceneConfiguration(name: nil, sessionRole: connectingSceneSession.role)
5963
sceneConfig.delegateClass = IntegrationSceneDelegate.self
6064
return sceneConfig
@@ -279,7 +283,7 @@ struct RuntimeWarnings: View {
279283
.transition(.opacity.animation(.default))
280284
}
281285
}
282-
.onReceive(NotificationCenter.default.publisher(for: ._runtimeWarning)) { notification in
286+
.onReceive(NotificationCenter.default.publisher(for: .issueReported)) { notification in
283287
if let message = notification.userInfo?["message"] as? String {
284288
self.runtimeWarnings.append(message)
285289
}
@@ -289,6 +293,23 @@ struct RuntimeWarnings: View {
289293

290294
extension Notification.Name {
291295
static let clearLogs = Self("clear-logs")
296+
static let issueReported = Self("issue-reported")
297+
}
298+
299+
private struct NotificationReporter: IssueReporter {
300+
func reportIssue(
301+
_ message: @autoclosure () -> String?,
302+
fileID: StaticString,
303+
filePath: StaticString,
304+
line: UInt,
305+
column: UInt
306+
) {
307+
NotificationCenter.default.post(
308+
name: .issueReported,
309+
object: nil,
310+
userInfo: message().map { ["message": $0] }
311+
)
312+
}
292313
}
293314

294315
#Preview {

Examples/Integration/Integration/iOS 16+17/NewContainsOldTestCase.swift

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,28 @@ struct NewContainsOldTestCase: View {
77
}
88

99
var body: some View {
10-
let _ = Logger.shared.log("\(Self.self).body")
11-
Form {
12-
Section {
13-
Text(self.store.count.description)
14-
Button("Increment") { self.store.send(.incrementButtonTapped) }
15-
} header: {
16-
Text("iOS 17")
17-
}
18-
Section {
19-
if self.store.isObservingChildCount {
20-
Text("Child count: \(self.store.child.count)")
10+
WithPerceptionTracking {
11+
let _ = Logger.shared.log("\(Self.self).body")
12+
Form {
13+
Section {
14+
Text(self.store.count.description)
15+
Button("Increment") { self.store.send(.incrementButtonTapped) }
16+
} header: {
17+
Text("iOS 17")
2118
}
22-
Button("Toggle observe child count") {
23-
self.store.send(.toggleIsObservingChildCount)
19+
Section {
20+
if self.store.isObservingChildCount {
21+
Text("Child count: \(self.store.child.count)")
22+
}
23+
Button("Toggle observe child count") {
24+
self.store.send(.toggleIsObservingChildCount)
25+
}
26+
}
27+
Section {
28+
BasicsView(store: self.store.scope(state: \.child, action: \.child))
29+
} header: {
30+
Text("iOS 16")
2431
}
25-
}
26-
Section {
27-
BasicsView(store: self.store.scope(state: \.child, action: \.child))
28-
} header: {
29-
Text("iOS 16")
3032
}
3133
}
3234
}

Examples/Integration/Integration/iOS 17/ObservableBindingLocalTest.swift

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -134,18 +134,20 @@ private struct ChildView: View {
134134
@Environment(\.dismiss) var dismiss
135135

136136
var body: some View {
137-
Form {
138-
Button("Dismiss") {
139-
self.dismiss()
140-
}
141-
TextField("Text", text: self.$store.text)
142-
Button(self.store.sendOnDisappear ? "Don't send onDisappear" : "Send onDisappear") {
143-
self.store.sendOnDisappear.toggle()
137+
WithPerceptionTracking {
138+
Form {
139+
Button("Dismiss") {
140+
self.dismiss()
141+
}
142+
TextField("Text", text: self.$store.text)
143+
Button(self.store.sendOnDisappear ? "Don't send onDisappear" : "Send onDisappear") {
144+
self.store.sendOnDisappear.toggle()
145+
}
144146
}
145-
}
146-
.onDisappear {
147-
if self.store.sendOnDisappear {
148-
self.store.send(.onDisappear)
147+
.onDisappear {
148+
if self.store.sendOnDisappear {
149+
self.store.send(.onDisappear)
150+
}
149151
}
150152
}
151153
}

Examples/Integration/IntegrationUITests/Internal/BaseIntegrationTests.swift

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import Accessibility
22
import CustomDump
33
@preconcurrency import InlineSnapshotTesting
4+
import IssueReporting
45
import XCTest
56

67
class BaseIntegrationTests: XCTestCase {
@@ -13,6 +14,14 @@ class BaseIntegrationTests: XCTestCase {
1314
self._expectRuntimeWarnings = (filePath, line)
1415
}
1516

17+
override func invokeTest() {
18+
withSnapshotTesting(
19+
//record: .failed
20+
) {
21+
super.invokeTest()
22+
}
23+
}
24+
1625
@MainActor
1726
override func setUp() async throws {
1827
// SnapshotTesting.isRecording = true
@@ -40,7 +49,6 @@ class BaseIntegrationTests: XCTestCase {
4049
"\(self.name) emitted an unexpected runtime warning"
4150
)
4251
}
43-
SnapshotTesting.isRecording = false
4452
}
4553

4654
@MainActor
@@ -61,6 +69,7 @@ class BaseIntegrationTests: XCTestCase {
6169
func assertLogs(
6270
_ logConfiguration: LogConfiguration = .unordered,
6371
matches expectedLogs: (() -> String)? = nil,
72+
fileID: StaticString = #fileID,
6473
filePath: StaticString = #filePath,
6574
function: StaticString = #function,
6675
line: UInt = #line,
@@ -74,16 +83,18 @@ class BaseIntegrationTests: XCTestCase {
7483
case .unordered:
7584
logs = self.logs.label.split(separator: "\n").sorted().joined(separator: "\n")
7685
}
77-
assertInlineSnapshot(
78-
of: logs,
79-
as: ._lines,
80-
matches: expectedLogs,
81-
fileID: fileID,
82-
file: filePath,
83-
function: function,
84-
line: line,
85-
column: column
86-
)
86+
withExpectedIssue(isIntermittent: true) {
87+
assertInlineSnapshot(
88+
of: logs,
89+
as: ._lines,
90+
matches: expectedLogs,
91+
fileID: fileID,
92+
file: filePath,
93+
function: function,
94+
line: line,
95+
column: column
96+
)
97+
}
8798
}
8899
}
89100

0 commit comments

Comments
 (0)