Skip to content

Commit

Permalink
Merge pull request #5 from oreillymedia/fix/reapply-fixes
Browse files Browse the repository at this point in the history
Fix/reapply fixes
  • Loading branch information
awaltzforvenus authored Aug 1, 2024
2 parents 7e472fa + 0860430 commit ae98fdf
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions Sources/SnapshotTesting/AssertSnapshot.swift
Original file line number Diff line number Diff line change
Expand Up @@ -272,10 +272,25 @@ public func verifySnapshot<Value, Format>(
}

let testName = sanitizePathComponent(testName)
let snapshotFileUrl =
snapshotDirectoryUrl
.appendingPathComponent("\(testName).\(identifier)")
.appendingPathExtension(snapshotting.pathExtension ?? "")

// 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 record != .all {
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)")
.appendingPathExtension(snapshotting.pathExtension ?? "")
}
guard let snapshotFileUrl = snapshotFileUrlCandidate else {
return nil
}

let fileManager = FileManager.default
try fileManager.createDirectory(at: snapshotDirectoryUrl, withIntermediateDirectories: true)

Expand Down

0 comments on commit ae98fdf

Please sign in to comment.