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 NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# testthat (development version)

* `expect_snapshot()` and friends will now fail when creating a new snapshot on CI. This is usually a signal that you've forgotten to run it locally before committing (#1461).
* `expect_snapshot_value()` can now handle expressions that generate `-` (#1678) or zero length atomic vectors (#2042).
* `expect_matches()` failures should be a little easier to read (#2135).
* New `local_on_cran(TRUE)` allows you to simulate how your tests will run on CRAN (#2112).
Expand Down
2 changes: 1 addition & 1 deletion R/test-files.R
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ test_files_reporter <- function(reporter, .env = parent.frame()) {
reporters <- list(
find_reporter(reporter),
lister, # track data
local_snapshotter("_snaps", fail_on_new = FALSE, .env = .env)
local_snapshotter("_snaps", fail_on_new = on_ci(), .env = .env)
)
list(
multi = MultiReporter$new(reporters = compact(reporters)),
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-snapshot-file.R
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ test_that("expect_snapshot_file works with variant", {
})

test_that("basic workflow", {
snapper <- local_snapshotter()
snapper <- local_snapshotter(fail_on_new = FALSE)

# warns on first run
snapper$start_file("snapshot-6", "test")
Expand All @@ -79,7 +79,7 @@ test_that("basic workflow", {
})

test_that("can announce snapshot file", {
snapper <- local_snapshotter()
snapper <- local_snapshotter(fail_on_new = FALSE)
snapper$start_file("snapshot-announce", "test")
announce_snapshot_file(name = "bar.svg")
expect_equal(snapper$snap_file_seen, "snapshot-announce/bar.svg")
Expand Down
12 changes: 6 additions & 6 deletions tests/testthat/test-snapshot-reporter.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
test_that("can establish local snapshotter for testing", {
snapper <- local_snapshotter()
snapper <- local_snapshotter(fail_on_new = FALSE)

snapper$start_file("snapshot-1", "test")
expect_true(snapper$is_active())
Expand All @@ -9,7 +9,7 @@ test_that("can establish local snapshotter for testing", {

test_that("basic workflow", {
path <- withr::local_tempdir()
snapper <- local_snapshotter(path)
snapper <- local_snapshotter(path, fail_on_new = FALSE)
snapper$start_file("snapshot-2")
# output if not active (because test not set here)
expect_snapshot_output("x") |>
Expand Down Expand Up @@ -39,7 +39,7 @@ test_that("basic workflow", {
})

test_that("only create new files for changed variants", {
snapper <- local_snapshotter()
snapper <- local_snapshotter(fail_on_new = FALSE)
snapper$start_file("variants", "test")
expect_warning(expect_snapshot_output("x"), "Adding new")
expect_warning(expect_snapshot_output("x", variant = "a"), "Adding new")
Expand Down Expand Up @@ -75,7 +75,7 @@ test_that("only create new files for changed variants", {
})

test_that("only reverting change in variant deletes .new", {
snapper <- local_snapshotter()
snapper <- local_snapshotter(fail_on_new = FALSE)
snapper$start_file("v", "test")
expect_warning(expect_snapshot_output("x", variant = "a"), "Adding new")
expect_warning(expect_snapshot_output("x", variant = "b"), "Adding new")
Expand All @@ -98,7 +98,7 @@ test_that("only reverting change in variant deletes .new", {

test_that("removing tests removes snap file", {
path <- withr::local_tempdir()
snapper <- local_snapshotter(path)
snapper <- local_snapshotter(path, fail_on_new = FALSE)
snapper$start_file("snapshot-3", "test")
expect_warning(expect_snapshot_output("x"), "Adding new")
snapper$end_file()
Expand All @@ -110,7 +110,7 @@ test_that("removing tests removes snap file", {
})

test_that("errors in test doesn't change snapshot", {
snapper <- local_snapshotter()
snapper <- local_snapshotter(fail_on_new = FALSE)

# First run
snapper$start_file("snapshot-5", "test")
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-snapshot-value.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ test_that("reparse handles common cases", {
})

test_that("errors if can't roundtrip", {
snapper <- local_snapshotter()
snapper <- local_snapshotter(fail_on_new = FALSE)
snapper$start_file("snapshot-4", "test")

expect_error(expect_snapshot_value(NULL), "safely serialized")
Expand Down
2 changes: 1 addition & 1 deletion vignettes/custom-expectation.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ library(testthat)
knitr::opts_chunk$set(collapse = TRUE, comment = "#>")

# Pretend we're snapsotting
snapper <- local_snapshotter()
snapper <- local_snapshotter(fail_on_new = FALSE)
snapper$start_file("snapshotting.Rmd", "test")
```

Expand Down
2 changes: 1 addition & 1 deletion vignettes/snapshotting.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ library(testthat)
```

```{r include = FALSE}
snapper <- local_snapshotter()
snapper <- local_snapshotter(fail_on_new = FALSE)
snapper$start_file("snapshotting.Rmd", "test")
```

Expand Down
Loading