Skip to content

Commit ab11383

Browse files
FIX: add local changes back to fork
1 parent 7e472fa commit ab11383

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
@@ -272,10 +272,25 @@ public func verifySnapshot<Value, Format>(
272272
}
273273

274274
let testName = sanitizePathComponent(testName)
275-
let snapshotFileUrl =
276-
snapshotDirectoryUrl
277-
.appendingPathComponent("\(testName).\(identifier)")
278-
.appendingPathExtension(snapshotting.pathExtension ?? "")
275+
276+
// Check the bundle for the resource first, then the file system
277+
// But, if we're recording, don't bother checking the bundle, since we aren't comparing it to anything, and
278+
// want the new file to be generated in the source directory, not the bundle.
279+
var snapshotFileUrlCandidate: URL?
280+
if !recording {
281+
let thisBundle = Bundle(for: CleanCounterBetweenTestCases.self)
282+
let resourcePath = thisBundle.path(forResource: "\(testName).\(identifier)", ofType: snapshotting.pathExtension)
283+
snapshotFileUrlCandidate = resourcePath.map({ URL(fileURLWithPath: $0) })
284+
}
285+
if snapshotFileUrlCandidate == nil {
286+
snapshotFileUrlCandidate = snapshotDirectoryUrl
287+
.appendingPathComponent("\(testName).\(identifier)")
288+
.appendingPathExtension(snapshotting.pathExtension ?? "")
289+
}
290+
guard let snapshotFileUrl = snapshotFileUrlCandidate else {
291+
return nil
292+
}
293+
279294
let fileManager = FileManager.default
280295
try fileManager.createDirectory(at: snapshotDirectoryUrl, withIntermediateDirectories: true)
281296

0 commit comments

Comments
 (0)