Skip to content

Commit d9d20f4

Browse files
committed
Add cran argument to expect_doppelganger()
1 parent 32096d8 commit d9d20f4

File tree

2 files changed

+57
-3
lines changed

2 files changed

+57
-3
lines changed

R/testthat-ui.R

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,29 @@
2525
#' and an optional plot title. It should transform the plot to SVG
2626
#' in a deterministic way and write it to the target file. See
2727
#' [write_svg()] (the default) for an example.
28+
#' @param cran If `FALSE` (the default), mismatched snapshots only
29+
#' cause a failure when you run tests locally or in your CI (Github
30+
#' Actions or any platform that sets the `CI` environment variable).
31+
#' If `TRUE`, failures may also occur on CRAN machines.
32+
#'
33+
#' Failures are disabled on CRAN by default because testing the
34+
#' appearance of a figure is inherently fragile. Changes in the R
35+
#' graphics engine or in ggplot2 may cause subtle differences in the
36+
#' aspect of a plot, such as a slightly smaller or larger margin.
37+
#' These changes will cause spurious failures because you need to
38+
#' update your snapshots to reflect the upstream changes.
39+
#'
40+
#' It would be distracting for both you and the CRAN maintainers if
41+
#' such changes systematically caused failures on CRAN. This is why
42+
#' snapshot expectations do not fail on CRAN by default and should
43+
#' be treated as a monitoring tool that allows you to quickly check
44+
#' how the appearance of your figures changes over time, and to
45+
#' manually assess whether changes reflect actual problems in your
46+
#' package.
47+
#'
48+
#' Internally, this argument is passed to
49+
#' [testthat::expect_snapshot_file()].
50+
#'
2851
#'
2952
#' @section Debugging:
3053
#' It is sometimes difficult to understand the cause of a failure.
@@ -66,7 +89,8 @@ expect_doppelganger <- function(title,
6689
fig,
6790
path = deprecated(),
6891
...,
69-
writer = write_svg) {
92+
writer = write_svg,
93+
cran = FALSE) {
7094
fig_name <- str_standardise(title)
7195
testcase <- make_testcase_file(fig_name)
7296
writer(fig, testcase, title)
@@ -87,7 +111,7 @@ expect_doppelganger <- function(title,
87111
testcase,
88112
name = file,
89113
binary = FALSE,
90-
cran = FALSE
114+
cran = cran
91115
),
92116
expectation_failure = function(cnd) {
93117
if (is_snapshot_stale(title, testcase)) {

man/expect_doppelganger.Rd

Lines changed: 31 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)