Skip to content

Commit 8234143

Browse files
authored
Merge pull request #7 from oreillymedia/ticket/GUAC-5510-update-and-apply-fixes
GUAC-5510 Apply our customization to updated snapshot library
2 parents 7c06008 + cfad28c commit 8234143

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

Sources/SnapshotTesting/AssertSnapshot.swift

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -316,10 +316,25 @@ public func verifySnapshot<Value, Format>(
316316
}
317317

318318
let testName = sanitizePathComponent(testName)
319-
let snapshotFileUrl =
320-
snapshotDirectoryUrl
321-
.appendingPathComponent("\(testName).\(identifier)")
322-
.appendingPathExtension(snapshotting.pathExtension ?? "")
319+
320+
// Check the bundle for the resource first, then the file system
321+
// But, if we're recording, don't bother checking the bundle, since we aren't comparing it to anything, and
322+
// want the new file to be generated in the source directory, not the bundle.
323+
var snapshotFileUrlCandidate: URL?
324+
if record != .all {
325+
let thisBundle = Bundle(for: CleanCounterBetweenTestCases.self)
326+
let resourcePath = thisBundle.path(forResource: "\(testName).\(identifier)", ofType: snapshotting.pathExtension)
327+
snapshotFileUrlCandidate = resourcePath.map({ URL(fileURLWithPath: $0) })
328+
}
329+
if snapshotFileUrlCandidate == nil {
330+
snapshotFileUrlCandidate = snapshotDirectoryUrl
331+
.appendingPathComponent("\(testName).\(identifier)")
332+
.appendingPathExtension(snapshotting.pathExtension ?? "")
333+
}
334+
guard let snapshotFileUrl = snapshotFileUrlCandidate else {
335+
return nil
336+
}
337+
323338
let fileManager = FileManager.default
324339
try fileManager.createDirectory(at: snapshotDirectoryUrl, withIntermediateDirectories: true)
325340

0 commit comments

Comments
 (0)