Skip to content

Commit 346f84c

Browse files
authored
New canGenerateNewSnapshots to avoid automatically creating missing ones in CI (pointfreeco#768)
* New `canGenerateNewSnapshots` to avoid automatically creating missing ones in CI Fixes pointfreeco#748. * Update AssertSnapshot.swift
1 parent 02ff553 commit 346f84c

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

Sources/SnapshotTesting/AssertSnapshot.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ public var isRecording: Bool = {
3636
return false
3737
}()
3838

39+
/// Whether or not to create snapshots if they aren't found.
40+
/// It's recommended to set this to `false` in CI to avoid false positives if the test is retried.
41+
public var canGenerateNewSnapshots = true
42+
3943
/// Whether or not to record all new references.
4044
///
4145
/// Due to a name clash in Xcode 12, this has been renamed to `isRecording`.
@@ -281,7 +285,7 @@ public func verifySnapshot<Value, Format>(
281285
return "Couldn't snapshot value"
282286
}
283287

284-
guard !recording, fileManager.fileExists(atPath: snapshotFileUrl.path) else {
288+
guard !recording, canGenerateNewSnapshots, fileManager.fileExists(atPath: snapshotFileUrl.path) else {
285289
try snapshotting.diffing.toData(diffable).write(to: snapshotFileUrl)
286290
#if !os(Linux) && !os(Windows)
287291
if ProcessInfo.processInfo.environment.keys.contains("__XCODE_BUILT_PRODUCTS_DIR_PATHS") {

Sources/SnapshotTesting/Documentation.docc/SnapshotTesting.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Powerfully flexible snapshot testing.
1818
### Configuration
1919

2020
- ``isRecording``
21+
- ``canGenerateNewSnapshots``
2122
- ``diffTool``
2223

2324
### Deprecations

0 commit comments

Comments
 (0)