Open ottaviohartman opened 2 weeks ago
Hey 👋 Thanks for opening this issue. I have explored this idea in the past. You can see this pull request here experimenting with inline snapshot support.
I was able to make it work quite well but
If that's something that you would find useful, I can try and unearth that pr and share more details of limitations and/or feasibility.
I'd find value! If I have time I can work on this too. Maybe even having it under some experimental flag would be nice while I use in my projects.
Okay early next week will have some time to refresh my memory on this and I can share a branch for you to test and see from there where we can go with this feature. But I am not against it as long as it's useful and stable (even if it has limitations).
🚀 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 inTestMain
.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.