Skip to content
Merged
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
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ export(skip_on_os)
export(skip_on_travis)
export(skip_unless_r)
export(snapshot_accept)
export(snapshot_reject)
export(snapshot_review)
export(source_dir)
export(source_file)
Expand Down
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# testthat (development version)

* New `snapshot_reject()` rejects all modified snapshots by deleting the `.new` variants (#1923).
* New `SlowReporter` makes it easier to find the slowest tests in your package. The easiest way to run it is with `devtools::test(reporter = "slow")` (#1466).
* Power `expect_mapequal()` with `waldo::compare(list_as_map = TRUE)` (#1521).
* On CRAN, `test_that()` now automatically skips if a package is not installed (#1585). Practically, this means that you no longer need to check that suggested packages are installed. (We don't do this in the tidyverse because we think it has limited payoff, but other styles advise differently.)
Expand Down
17 changes: 17 additions & 0 deletions R/snapshot-manage.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#' Accept or reject modified snapshots
#'
#' * `snapshot_accept()` accepts all modified snapshots.
#' * `snapshot_reject()` rejects all modified snapshots by deleting the `.new` variants.
#' * `snapshot_review()` opens a Shiny app that shows a visual diff of each
#' modified snapshot. This is particularly useful for whole file snapshots
#' created by `expect_snapshot_file()`.
Expand All @@ -26,6 +27,22 @@ snapshot_accept <- function(files = NULL, path = "tests/testthat") {
invisible()
}

#' @rdname snapshot_accept
#' @export
snapshot_reject <- function(files = NULL, path = "tests/testthat") {
changed <- snapshot_meta(files, path)
if (nrow(changed) == 0) {
inform("No snapshots to reject")
return(invisible())
}

inform(c("Rejecting snapshots:", changed$name))
unlink(changed$new)

rstudio_tickle()
invisible()
}

#' @rdname snapshot_accept
#' @export
snapshot_review <- function(files = NULL, path = "tests/testthat") {
Expand Down
4 changes: 4 additions & 0 deletions man/snapshot_accept.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions tests/testthat/_snaps/snapshot-manage.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,12 @@
Updating snapshots:
* foo/a.md

# snapshot_reject deletes .new files

Code
snapshot_reject(path = path)
Message
Rejecting snapshots:
* a.md
* b.md

7 changes: 7 additions & 0 deletions tests/testthat/test-snapshot-manage.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ test_that("can work with variants", {
expect_equal(dir(file.path(path, "_snaps", "foo")), "a.md")
})

test_that("snapshot_reject deletes .new files", {
path <- local_snapshot_dir(c("a.md", "a.new.md", "b.md", "b.new.md"))

expect_snapshot(snapshot_reject(path = path))
expect_equal(dir(file.path(path, "_snaps")), c("a.md", "b.md"))
})


# snapshot_meta -----------------------------------------------------------

Expand Down
Loading