Skip to content

[Feature Request]: auto-updated inline snaps #110

@ottaviohartman

Description

@ottaviohartman

🚀 Feature Proposal

cargo insta has this very cool feature called inline snapshots. When a snapshot updates, it updates the code itself. How hard would this be to implement in Go?

It could be based on some //go: marker above the check, possibly? And maybe it would need to be an option in TestMain.

Motivation

Seeing, inline, the expected values of unit tests instead of hopping between files and scanning multiple lines of output.

Example

Not sure yet, perhaps using //go:generate? The crazy part is Rust somehow generates the code inside the file, rather than writing a new file. I'm not sure if this breaks certain Go workflows.

// before compilation
// `snapshot-inline`, or some marker, tells the codegen where to inject

// snapshot-inline
snaps.MatchSnapshot(t, rr.Code, "")
// after compilation

// snapshot-inline
snaps.MatchSnapshot(t, rr.Code, 201)

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions