Skip to content

Commit d9d2ef9

Browse files
committed
wip
1 parent 9a1e03f commit d9d2ef9

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

Sources/SnapshotTesting/AssertSnapshot.swift

+8-6
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,9 @@ public func verifySnapshot<Value, Format>(
318318
if let name = name {
319319
identifier = sanitizePathComponent(name)
320320
} else {
321-
identifier = String(counter.next())
321+
identifier = String(
322+
counter.next(for: snapshotDirectoryUrl.appendingPathComponent(testName).absoluteString)
323+
)
322324
}
323325

324326
let testName = sanitizePathComponent(testName)
@@ -560,22 +562,22 @@ enum File {
560562
@TaskLocal static var counter = Counter()
561563

562564
final class Counter: @unchecked Sendable {
563-
private var count = 0
565+
private var counts: [String: Int] = [:]
564566
private let lock = NSLock()
565567

566568
init() {}
567569

568-
func next() -> Int {
570+
func next(for key: String) -> Int {
569571
lock.lock()
570572
defer { lock.unlock() }
571-
count += 1
572-
return count
573+
counts[key, default: 0] += 1
574+
return counts[key]!
573575
}
574576

575577
func reset() {
576578
lock.lock()
577579
defer { lock.unlock() }
578-
count = 0
580+
counts.removeAll()
579581
}
580582
}
581583
}

Sources/SnapshotTesting/SnapshotsTestTrait.swift

+5
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@
88
}
99

1010
extension Trait where Self == _SnapshotsTestTrait {
11+
/// Configure snapshot testing in a suite or test.
12+
public static var snapshots: Self {
13+
snapshots()
14+
}
15+
1116
/// Configure snapshot testing in a suite or test.
1217
///
1318
/// - Parameters:

0 commit comments

Comments
 (0)