Skip to content

Commit

Permalink
GUAC-4961 Change how reference image is found
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
lj-dickey committed Nov 29, 2023
1 parent 41af302 commit d816142
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions Sources/SnapshotTesting/AssertSnapshot.swift
Original file line number Diff line number Diff line change
Expand Up @@ -221,10 +221,15 @@ public func verifySnapshot<Value, Format>(

let testName = sanitizePathComponent(testName)

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

0 comments on commit d816142

Please sign in to comment.