pointfreeco / swift-snapshot-testing

📸 Delightful Swift snapshot testing.
https://www.pointfree.co/episodes/ep41-a-tour-of-snapshot-testing
MIT License
3.72k stars 565 forks source link

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

Closed NachoSoto closed 1 month ago

NachoSoto commented 11 months ago

Fixes #748.

NachoSoto commented 8 months ago

Bump?

CraigSiemens commented 7 months ago

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 }
}
mbrandonw commented 1 month ago

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 commented 1 month ago

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