Skip to content

Commit b4c58d7

Browse files
authored
Write to snapshot state before failing (pointfreeco#787)
XCTest test cases can be configured with `continueAfterFailure = false`, and in fact UI tests are configured with this by default, but in these cases inline snapshots will never be written because the failure aborts the test before we write to the snapshot state. This commit reorders things to fix the problem.
1 parent 5b356ad commit b4c58d7

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

Sources/InlineSnapshotTesting/AssertInlineSnapshot.swift

+13-11
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,19 @@ public func assertInlineSnapshot<Value>(
7373
}
7474
guard !isRecording, let expected = expected?()
7575
else {
76+
// NB: Write snapshot state before calling `XCTFail` in case `continueAfterFailure = false`
77+
inlineSnapshotState[File(path: file), default: []].append(
78+
InlineSnapshot(
79+
expected: expected?(),
80+
actual: actual,
81+
wasRecording: isRecording,
82+
syntaxDescriptor: syntaxDescriptor,
83+
function: "\(function)",
84+
line: line,
85+
column: column
86+
)
87+
)
88+
7689
var failure: String
7790
if syntaxDescriptor.trailingClosureLabel
7891
== InlineSnapshotSyntaxDescriptor.defaultTrailingClosureLabel
@@ -97,17 +110,6 @@ public func assertInlineSnapshot<Value>(
97110
file: file,
98111
line: line
99112
)
100-
inlineSnapshotState[File(path: file), default: []].append(
101-
InlineSnapshot(
102-
expected: expected?(),
103-
actual: actual,
104-
wasRecording: isRecording,
105-
syntaxDescriptor: syntaxDescriptor,
106-
function: "\(function)",
107-
line: line,
108-
column: column
109-
)
110-
)
111113
return
112114
}
113115
guard let difference = snapshotting.diffing.diff(actual, expected)?.0

0 commit comments

Comments
 (0)