Skip to content

Commit 6240817

Browse files
NachoSotoawaltzforvenus
authored andcommitted
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 7211112 commit 6240817

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

Diff for: Sources/SnapshotTesting/AssertSnapshot.swift

+5-1
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`.
@@ -296,7 +300,7 @@ public func verifySnapshot<Value, Format>(
296300
return "Couldn't snapshot value"
297301
}
298302

299-
guard !recording, fileManager.fileExists(atPath: snapshotFileUrl.path) else {
303+
guard !recording, canGenerateNewSnapshots, fileManager.fileExists(atPath: snapshotFileUrl.path) else {
300304
try snapshotting.diffing.toData(diffable).write(to: snapshotFileUrl)
301305
#if !os(Linux) && !os(Windows)
302306
if ProcessInfo.processInfo.environment.keys.contains("__XCODE_BUILT_PRODUCTS_DIR_PATHS") {

Diff for: Sources/SnapshotTesting/Documentation.docc/SnapshotTesting.md

+1
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)