Skip to content

Add use_snapshot() - #2180

Merged
hadley merged 10 commits into
r-lib:mainfrom
jonthegeek:fix-2156-use_snapshot
Sep 17, 2026
Merged

hadley merged 10 commits into
r-lib:mainfrom
jonthegeek:fix-2156-use_snapshot

Conversation

@jonthegeek

Copy link
Copy Markdown
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
Copy Markdown
Contributor Author

This should be good to go now!

Comment thread R/r.R Outdated
Comment thread R/r.R Outdated
@jonthegeek
jonthegeek requested a review from hadley September 26, 2025 21:06
@jennybc

jennybc commented Feb 2, 2026

Copy link
Copy Markdown
Member

@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
Copy Markdown
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

maelle commented Feb 3, 2026

Copy link
Copy Markdown
Contributor

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.

@jonthegeek

Copy link
Copy Markdown
Contributor Author

@jennybc Merge conflicts resolved. Should I re-mark this as "done" as far as tidy-dev-day?

@hadley
hadley merged commit 00a6a8d into r-lib:main Sep 17, 2026
14 of 15 checks passed
@hadley

hadley commented Sep 17, 2026

Copy link
Copy Markdown
Member

Thank you!

@maelle

maelle commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

馃帀 馃檹

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