You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Sources/SnapshotTesting/AssertSnapshot.swift
+36-4Lines changed: 36 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -114,11 +114,40 @@ public func assertSnapshots<Value, Format>(
114
114
115
115
/// Verifies that a given value matches a reference on disk.
116
116
///
117
+
/// Third party snapshot assert helpers can be built on top of this function. Simply invoke `verifySnapshot` with your own arguments, and then invoke `XCTFail` with the string returned if it is non-`nil`. For example, if you want the snapshot directory to be determined by an environment variable, you can create your own assert helper like so:
/// let snapshotDirectory = ProcessInfo.processInfo.environment["SNAPSHOT_REFERENCE_DIR"]! + "/" + #file
131
+
/// let failure = verifySnapshot(
132
+
/// matching: value,
133
+
/// as: snapshotting,
134
+
/// named: name,
135
+
/// record: recording,
136
+
/// snapshotDirectory: snapshotDirectory,
137
+
/// timeout: timeout,
138
+
/// file: file,
139
+
/// testName: testName
140
+
/// )
141
+
/// guard let message = failure else { return }
142
+
/// XCTFail(message, file: file, line: line)
143
+
/// }
144
+
///
117
145
/// - Parameters:
118
146
/// - value: A value to compare against a reference.
119
147
/// - snapshotting: A strategy for serializing, deserializing, and comparing values.
120
148
/// - name: An optional description of the snapshot.
121
149
/// - recording: Whether or not to record a new reference.
150
+
/// - snapshotDirectory: Optional directory to save snapshots. By default snapshots will be saved in a directory with the same name as the test file, and that directory will sit inside a directory `__Snapshots__` that sits next to your test file.
122
151
/// - timeout: The amount of time a snapshot must be generated in.
123
152
/// - file: The file in which failure occurred. Defaults to the file name of the test case in which this function was called.
124
153
/// - testName: The name of the test in which failure occurred. Defaults to the function name of the test case in which this function was called.
@@ -129,6 +158,7 @@ public func verifySnapshot<Value, Format>(
129
158
as snapshotting:Snapshotting<Value,Format>,
130
159
named name:String?=nil,
131
160
record recording:Bool=false,
161
+
snapshotDirectory:String?=nil,
132
162
timeout:TimeInterval=5,
133
163
file:StaticString= #file,
134
164
testName:String= #function,
@@ -141,10 +171,12 @@ public func verifySnapshot<Value, Format>(
0 commit comments