Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-apply local changes after updating main #3

Merged
merged 2 commits into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@

Delightful Swift snapshot testing.

<!--
![An example of a snapshot failure in Xcode.](.github/snapshot-test-1.png)
-->

## This is a fork

It differs from the original in just one key way. When looking for a snapshot resource (usually an image), it tries to load it from the test bundle first. Everything else _should_ be the same.

## Usage

Once [installed](#installation), _no additional configuration is required_. You can import the
Expand Down
27 changes: 21 additions & 6 deletions Sources/SnapshotTesting/AssertSnapshot.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ public var isRecording = false
/// Due to a name clash in Xcode 12, this has been renamed to `isRecording`.
@available(*, deprecated, renamed: "isRecording")
public var record: Bool {
get { isRecording }
set { isRecording = newValue }
get { isRecording }
set { isRecording = newValue }
}

/// Asserts that a given value matches a reference on disk.
Expand Down Expand Up @@ -220,10 +220,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 !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)")
.appendingPathExtension(snapshotting.pathExtension ?? "")
}
guard let snapshotFileUrl = snapshotFileUrlCandidate else {
return nil
}

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

Expand Down
Loading