Skip to content

Commit d816142

Browse files
committed
GUAC-4961 Change how reference image is found
If recording, don't look for the reference image in the bundle, since this sets the file name for generation later. Instead, look for a local copy of the file (since we won't be recording tests in CI), so that's where the new file gets generated.
1 parent 41af302 commit d816142

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

Sources/SnapshotTesting/AssertSnapshot.swift

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -221,10 +221,15 @@ public func verifySnapshot<Value, Format>(
221221

222222
let testName = sanitizePathComponent(testName)
223223

224-
// Check the bundle for the resource first, then the file system
225-
let thisBundle = Bundle(for: CleanCounterBetweenTestCases.self)
226-
let resourcePath = thisBundle.path(forResource: "\(testName).\(identifier)", ofType: snapshotting.pathExtension)
227-
var snapshotFileUrlCandidate = resourcePath.map({ URL(fileURLWithPath: $0) })
224+
// Check the bundle for the resource first, then the file system
225+
// But, if we're recording, don't bother checking the bundle, since we aren't comparing it to anything, and
226+
// want the new file to be generated in the source directory, not the bundle.
227+
var snapshotFileUrlCandidate: URL?
228+
if !recording {
229+
let thisBundle = Bundle(for: CleanCounterBetweenTestCases.self)
230+
let resourcePath = thisBundle.path(forResource: "\(testName).\(identifier)", ofType: snapshotting.pathExtension)
231+
snapshotFileUrlCandidate = resourcePath.map({ URL(fileURLWithPath: $0) })
232+
}
228233
if snapshotFileUrlCandidate == nil {
229234
snapshotFileUrlCandidate = snapshotDirectoryUrl
230235
.appendingPathComponent("\(testName).\(identifier)")

0 commit comments

Comments
 (0)