Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# testthat (development version)

* `snapshot_accept()`, `snapshot_reject()`, and `snapshot_review()` now correctly
find changed snapshots in variant subdirectories when filtering by test file
name (#2325).
* `run_cpp_tests()` no longer accidentally reports that a test has been skipped (#2315).
* `expect_setequal()` uses better wording in the results (@mcol, #2310).

Expand Down
7 changes: 6 additions & 1 deletion R/snapshot-manage.R
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,12 @@ snapshot_meta <- function(files = NULL, path = "tests/testthat") {
# Match regardless of whether user include .md or not
files <- c(files, paste0(files, ".md"))

out <- out[out$name %in% files | out$test %in% dirs, , drop = FALSE]
# Also match basename to handle variant snapshots (e.g. "variant/html.md")
out <- out[
out$name %in% files | basename(out$name) %in% files | out$test %in% dirs,
,
drop = FALSE
]
}

out
Expand Down
31 changes: 31 additions & 0 deletions tests/testthat/test-snapshot-manage.R
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,37 @@ test_that("can work with variants", {
path <- local_snapshot_dir(c("foo/a.md", "foo/a.new.md"))
expect_snapshot(snapshot_accept("foo/a", path = path))
expect_equal(dir(file.path(path, "_snaps", "foo")), "a.md")

# Can accept by test name alone (#2325)
path <- local_snapshot_dir(c("foo/a.md", "foo/a.new.md"))
suppressMessages(snapshot_accept("a", path = path))
expect_equal(dir(file.path(path, "_snaps", "foo")), "a.md")

# Can accept across multiple variants (#2325)
path <- local_snapshot_dir(c(
"variant1/a.md",
"variant1/a.new.md",
"variant2/a.md",
"variant2/a.new.md"
))
suppressMessages(snapshot_accept("a", path = path))
expect_equal(
dir(file.path(path, "_snaps"), recursive = TRUE),
c("variant1/a.md", "variant2/a.md")
)

# Only accepts matching test name (#2325)
path <- local_snapshot_dir(c(
"foo/a.md",
"foo/a.new.md",
"foo/b.md",
"foo/b.new.md"
))
suppressMessages(snapshot_accept("a", path = path))
expect_equal(
dir(file.path(path, "_snaps"), recursive = TRUE),
c("foo/a.md", "foo/b.md", "foo/b.new.md")
)
})

test_that("snapshot_reject deletes .new files", {
Expand Down
Loading