Skip to content

Add use_snapshot()#2180

Open
jonthegeek wants to merge 9 commits intor-lib:mainfrom
jonthegeek:fix-2156-use_snapshot
Open

Add use_snapshot()#2180
jonthegeek wants to merge 9 commits intor-lib:mainfrom
jonthegeek:fix-2156-use_snapshot

Conversation

@jonthegeek
Copy link
Contributor

Implement a use_snapshot() helper to go with use_r() and use_test().

I ran out of time and didn't implement tests or NEWS for this yet (and there's a solid chance that this doesn't quite nail it), but I wanted to get it checked in.

Fixes #2156.

Implement a `use_snapshot()` helper to go with `use_r()` and `use_test()`.

I ran out of time and didn't implement tests or NEWS for this yet (and there's a solid chance that this doesn't quite nail it), but I wanted to get it checked in.

Fixes r-lib#2156.
@jonthegeek
Copy link
Contributor Author

This should be good to go now!

@jonthegeek jonthegeek requested a review from hadley September 26, 2025 21:06
@jennybc
Copy link
Member

jennybc commented Feb 2, 2026

@jonthegeek and/or @maelle What is the workflow in which you regularly want to open snapshot files in an editor? I mostly interact with them in the testthat::snapshot_review() app or in my git client. On the occasion I want to open a snapshot file, I think I just fall back to whatever usual ways I open files in, e.g., my IDE. It feels like there's some workflow context here that I'm missing.

@jonthegeek
Copy link
Contributor Author

@jonthegeek and/or @maelle What is the workflow in which you regularly want to open snapshot files in an editor?

I think my original interest in this was more for the other direction, where I'm looking at a snapshot (on a rare occasion when I edited one directly for an anticipated result or something) and want to hop to the test or R file with my hotkeys. I've had situations where I want to edit the file to define what I think it should look like, though (before working out exactly how to do that), so that's where this would come in for me. Not super common but it will be nice when it comes up.

@maelle
Copy link
Contributor

maelle commented Feb 3, 2026

I was interested in the other direction compared to @jonthegeek. If I'm reviewing a new-to-me package and reading a test file that contains snapshot tests, I'd like to be able to more easily go to the corresponding snapshot files. And obviously I'd then need to go back.

If it were not use_snapshot(), I'd imagine this as an IDE feature like what allows us to click on a function to go read its definition.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

How to browse snapshots from a test file?

4 participants