Skip to content
Closed
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
12 changes: 11 additions & 1 deletion Sources/SnapshotTesting/AssertSnapshot.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import XCTest
/// diffTool = "ksdiff"
public var diffTool: String? = nil

/// Whether or not to automatically record snapshots when an existing file is not found.
public var recordMissingSnapshots = true

/// Whether or not to record all new references.
public var isRecording = false

Expand Down Expand Up @@ -232,8 +235,15 @@ public func verifySnapshot<Value, Format>(
guard var diffable = optionalDiffable else {
return "Couldn't snapshot value"
}

guard !recording, fileManager.fileExists(atPath: snapshotFileUrl.path) else {
if !recording && !recordMissingSnapshots {
return """
No reference was found on disk, and `recordMissingSnapshots` is false.
Did not record snapshot.
"""
}

try snapshotting.diffing.toData(diffable).write(to: snapshotFileUrl)
return recording
? """
Expand Down