Skip to content

New canGenerateNewSnapshots to avoid automatically creating missing ones in CI #768

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion Sources/SnapshotTesting/AssertSnapshot.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ public var diffTool: String? = nil
/// Whether or not to record all new references.
public var isRecording = false

/// Whether or not to create snapshots if they aren't found.
/// It's recommended to set this to `false` in CI to avoid false positives if the test is retried.
public var canGenerateNewSnapshots = true

/// Whether or not to record all new references.
///
/// Due to a name clash in Xcode 12, this has been renamed to `isRecording`.
Expand Down Expand Up @@ -256,7 +260,7 @@ public func verifySnapshot<Value, Format>(
return "Couldn't snapshot value"
}

guard !recording, fileManager.fileExists(atPath: snapshotFileUrl.path) else {
guard !recording, canGenerateNewSnapshots, fileManager.fileExists(atPath: snapshotFileUrl.path) else {
try snapshotting.diffing.toData(diffable).write(to: snapshotFileUrl)
#if !os(Linux) && !os(Windows)
if ProcessInfo.processInfo.environment.keys.contains("__XCODE_BUILT_PRODUCTS_DIR_PATHS") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Powerfully flexible snapshot testing.
### Configuration

- ``isRecording``
- ``canGenerateNewSnapshots``
- ``diffTool``

### Deprecations
Expand Down