swift-snapshot-testing
swift-snapshot-testing copied to clipboard
Running test repeatedly results in duplicate snapshot being created.
Describe the bug Running a snapshot test repeatedly with xcode's new 'run test repeatedly' functionality results in additional snapshots being created for that test.
We've a wrapper around this library which I've posted below although the identifier we're passing in to the testName does not include the iteration number at the real testSnapshot callsite.
public func testSnapshot(_ view: UIView,
identifier: String = #function,
snapshotType: SnapshotType = .image,
precision: CGFloat = 0.95,
file: StaticString = #file,
line: UInt = #line,
waiting: TimeInterval = 0,
isArchitectureDependent: Bool = false) {
semaphore.wait()
var testID = identifier
if isArchitectureDependent && (Architecture.isArm64 || Architecture.isRosettaEmulated) {
testID.append("-arm64")
}
switch snapshotType {
case .image:
assertSnapshot(matching: view,
as: .wait(for: waiting, on: .image(precision: Float(precision))),
record: isRecording,
file: file,
testName: testID,
line: line)
case .recursiveDescription:
assertSnapshot(matching: view,
as: .wait(for: waiting, on: .recursiveDescription()),
record: isRecording,
file: file,
testName: testID,
line: line)
}
semaphore.signal()
}
To Reproduce
Take any snapshot test right click on it and run "test
Expected behavior I'd expect the test to use only one snapshot no matter how many time they're run.
Environment
- swift-snapshot-testing version [e.g. 1.8.1]
- Xcode 13.2
- Swift 5.5
- OS: iOS 15
A workaround is to set the named
parameter
@simondelphia @Deco354 Thank you. You guys really saved my day. Running TC on Xcode Cloud will hit the issue.
@stephencelis Can we reopen this? Using the named parameter is a work-around rather than a fix. It won't be immediately obvious to anyone other than those within this thread.
@Deco354 this was closed by merging #585. Are you still having issues running repeatedly in yesterday's 1.10.0 release?
Sorry I must have skimmed this thread and missed #585 completely. Thanks for getting this merged and thanks @krzysztofpawski for taking the time to fix this 🍾