Skip to content

Commit

Permalink
Merge pull request #7 from oreillymedia/ticket/GUAC-5510-update-and-a…
Browse files Browse the repository at this point in the history
…pply-fixes

GUAC-5510 Apply our customization to updated snapshot library
  • Loading branch information
mblackmon authored Dec 11, 2024
2 parents 7c06008 + cfad28c commit 8234143
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 @@ -316,10 +316,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 8234143

Please sign in to comment.