From ab113839f65f6693ca0c8898fc0e7fe7e19d629a Mon Sep 17 00:00:00 2001 From: Scott Starr Date: Wed, 31 Jul 2024 14:04:38 -0400 Subject: [PATCH 1/3] FIX: add local changes back to fork --- Sources/SnapshotTesting/AssertSnapshot.swift | 23 ++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/Sources/SnapshotTesting/AssertSnapshot.swift b/Sources/SnapshotTesting/AssertSnapshot.swift index b2d473d38..68b4f56ae 100644 --- a/Sources/SnapshotTesting/AssertSnapshot.swift +++ b/Sources/SnapshotTesting/AssertSnapshot.swift @@ -272,10 +272,25 @@ public func verifySnapshot( } 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) From 646b6bec92c5617d4b5ea16502c0ea06b3f15e37 Mon Sep 17 00:00:00 2001 From: Scott Starr Date: Wed, 31 Jul 2024 14:20:00 -0400 Subject: [PATCH 2/3] fix `record` --- Sources/SnapshotTesting/AssertSnapshot.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/SnapshotTesting/AssertSnapshot.swift b/Sources/SnapshotTesting/AssertSnapshot.swift index 68b4f56ae..9f62bcfef 100644 --- a/Sources/SnapshotTesting/AssertSnapshot.swift +++ b/Sources/SnapshotTesting/AssertSnapshot.swift @@ -277,7 +277,7 @@ public func verifySnapshot( // 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 { + if record != .never { let thisBundle = Bundle(for: CleanCounterBetweenTestCases.self) let resourcePath = thisBundle.path(forResource: "\(testName).\(identifier)", ofType: snapshotting.pathExtension) snapshotFileUrlCandidate = resourcePath.map({ URL(fileURLWithPath: $0) }) From 08604305d51d050a180928519384a4d1fd0f8b09 Mon Sep 17 00:00:00 2001 From: Scott Starr Date: Thu, 1 Aug 2024 07:04:28 -0400 Subject: [PATCH 3/3] fix indentation, `record` value check --- Sources/SnapshotTesting/AssertSnapshot.swift | 34 ++++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/Sources/SnapshotTesting/AssertSnapshot.swift b/Sources/SnapshotTesting/AssertSnapshot.swift index 9f62bcfef..60a905ee8 100644 --- a/Sources/SnapshotTesting/AssertSnapshot.swift +++ b/Sources/SnapshotTesting/AssertSnapshot.swift @@ -273,23 +273,23 @@ public func verifySnapshot( let testName = sanitizePathComponent(testName) - // 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 != .never { - 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 - } + // 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)