swift-snapshot-testing icon indicating copy to clipboard operation
swift-snapshot-testing copied to clipboard

New `canGenerateNewSnapshots` to avoid automatically creating missing ones in CI

Open NachoSoto opened this issue 2 years ago • 2 comments

Fixes #748.

NachoSoto avatar Sep 12 '23 20:09 NachoSoto

Bump?

NachoSoto avatar Dec 19 '23 19:12 NachoSoto

I had a related idea and stumbled across this searching issues for it.

I was looking for a way to record only the snapshots for the failing tests to avoid re-recording all the snapshots in a project. Mainly to avoid unrelated changed being applied and the back and forth of intel/apple silicon shaping out images.


This is just an idea, feel free to take or leave it. We could introduce a recordingMode rather than having more bools in the tests/globally.

enum RecordingMode {
    /// Only record a snapshot when there isn't an existing one. The default behaviour.
    case missingSnapshots
    
    /// Record the snapshots only for failing tests. Useful for when a change affects many
    /// snapshots across a project but you don't want the snapshots for the passing tests
    /// to be recorded as well.
    case failingTests
    
    /// Always record snapshots. The same as setting `isRecording` to true.
    case always
    
    /// Never record a snapshot. The same as setting `canGenerateNewSnapshots` to true.
    case never
}

This could be introduced without being a breaking change by modifying isRecording to be

public var isRecording: Bool {
   get { recordingMode == .always }
   set { recordingMode = newValue ? .always : .missingSnapshot }
}

CraigSiemens avatar Jan 12 '24 01:01 CraigSiemens

Hi @NachoSoto, thanks for the PR!

It's taken some time, but this is now implemented in #867. I'm going to merge this PR and then it will be updated to mold into what we have going on in #867.

mbrandonw avatar Jul 04 '24 02:07 mbrandonw

Also, @CraigSiemens, #867 adds your option for recording failed snapshots only (see 0c6b44916f169bf670463133432b7c301da65573). Thanks for the suggestion!

mbrandonw avatar Jul 04 '24 14:07 mbrandonw