Skip to content

Commit 590c356

Browse files
authored
fix(testthat): Use muffle_expectation, not continue_test (#418)
1 parent bcac429 commit 590c356

File tree

35 files changed

+68
-42
lines changed

35 files changed

+68
-42
lines changed

DESCRIPTION

Lines changed: 35 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11
Package: shinytest2
22
Title: Testing for Shiny Applications
3-
Version: 0.4.1
4-
Authors@R:
5-
c(
6-
person("Barret", "Schloerke", role = c("cre", "aut"), email = "barret@posit.co", comment = c(ORCID = "0000-0001-9986-114X")),
7-
person(family = "Posit Software, PBC", role = c("cph", "fnd")),
8-
person("Winston", "Chang", role ="ctb", email = "winston@posit.co", comment = "Original author to rstudio/shinytest"),
9-
person("Gábor", "Csárdi", role = "ctb", email = "gabor@posit.co", comment = "Original author to rstudio/shinytest"),
10-
person("Hadley", "Wickham", role = "ctb", email = "hadley@posit.co", comment = "Original author to rstudio/shinytest"),
11-
person(family = "Mango Solutions", role = c("cph", "ccp"), comment = "Original author to rstudio/shinytest")
12-
)
13-
Description: Automated unit testing of Shiny applications through a headless 'Chromium' browser.
3+
Version: 0.4.1.9000
4+
Authors@R: c(
5+
person("Barret", "Schloerke", , "barret@posit.co", role = c("cre", "aut"),
6+
comment = c(ORCID = "0000-0001-9986-114X")),
7+
person(, "Posit Software, PBC", role = c("cph", "fnd")),
8+
person("Winston", "Chang", , "winston@posit.co", role = "ctb",
9+
comment = "Original author to rstudio/shinytest"),
10+
person("Gábor", "Csárdi", , "gabor@posit.co", role = "ctb",
11+
comment = "Original author to rstudio/shinytest"),
12+
person("Hadley", "Wickham", , "hadley@posit.co", role = "ctb",
13+
comment = "Original author to rstudio/shinytest"),
14+
person(, "Mango Solutions", role = c("cph", "ccp"),
15+
comment = "Original author to rstudio/shinytest")
16+
)
17+
Description: Automated unit testing of Shiny applications through a
18+
headless 'Chromium' browser.
1419
License: MIT + file LICENSE
15-
Encoding: UTF-8
16-
Language: en-US
17-
Roxygen: list(markdown = TRUE)
18-
RoxygenNote: 7.3.2
19-
URL: https://rstudio.github.io/shinytest2/, https://github.com/rstudio/shinytest2
20+
URL: https://rstudio.github.io/shinytest2/,
21+
https://github.com/rstudio/shinytest2
2022
BugReports: https://github.com/rstudio/shinytest2/issues
21-
VignetteBuilder: knitr
2223
Depends:
23-
testthat (>= 3.1.2)
24+
testthat (>= 3.3.0)
2425
Imports:
25-
R6 (>= 2.4.0),
2626
callr,
2727
checkmate (>= 2.0.0),
2828
chromote (>= 0.5.0),
@@ -31,12 +31,13 @@ Imports:
3131
globals (>= 0.14.0),
3232
httr,
3333
jsonlite,
34+
lifecycle,
3435
pingr,
36+
R6 (>= 2.4.0),
3537
rlang (>= 1.0.0),
3638
rmarkdown,
3739
shiny,
38-
withr,
39-
lifecycle
40+
withr
4041
Suggests:
4142
deSolve,
4243
diffobj,
@@ -45,20 +46,24 @@ Suggests:
4546
plotly,
4647
png,
4748
rstudioapi,
48-
shinyWidgets,
4949
shinytest (>= 1.5.1),
5050
shinyvalidate (>= 0.1.2),
51+
shinyWidgets,
5152
showimage,
53+
spelling,
5254
usethis,
53-
vdiffr (>= 1.0.0),
54-
spelling
55-
Config/Needs/check:
56-
rstudio/shiny,
57-
bslib
58-
Config/Needs/website:
59-
pkgdown,
60-
tidyverse/tidytemplate
55+
vdiffr (>= 1.0.0)
56+
LinkingTo:
57+
cpp11
58+
VignetteBuilder:
59+
knitr
60+
Config/Needs/check: rstudio/shiny, bslib
61+
Config/Needs/website: pkgdown, tidyverse/tidytemplate
6162
Config/testthat/edition: 3
63+
Encoding: UTF-8
64+
Language: en-US
65+
Roxygen: list(markdown = TRUE)
66+
RoxygenNote: 7.3.3
6267
Collate:
6368
'R6-helper.R'
6469
'app-driver-chromote.R'
@@ -101,5 +106,3 @@ Collate:
101106
'shinytest2-package.R'
102107
'test-app.R'
103108
'use.R'
104-
LinkingTo:
105-
cpp11

NEWS.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# shinytest2 (development version)
2+
3+
* Fixed internal bug where `{testthat}` v3.3.0 changed expectation behavior for screenshot snapshots within `App$expect_values()` (#418).
4+
15
# shinytest2 0.4.1
26

37
## Bug

R/app-driver-expect-download.R

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,11 @@ app_expect_download <- function(
9696
ckm8_assert_app_driver(self, private)
9797
rlang::check_dots_empty()
9898

99+
## Announce snapshot file
100+
# Cannot announce before download because we need the filename
101+
# from the Content-Disposition header... which is after we download the file
102+
# Therefore, we cannot announce the testthat file
103+
99104
snapshot_info <- app_download(
100105
self,
101106
private,

R/app-driver-expect-screenshot.R

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,9 @@ app_expect_screenshot <- function(
115115

116116
filename <- app_next_temp_snapshot_path(self, private, name, "png")
117117

118+
# Announce snapshot file before touching before any other expressions can fail
119+
testthat::announce_snapshot_file(filename)
120+
118121
# Take screenshot
119122
self$get_screenshot(
120123
file = filename,

R/app-driver-expect-values.R

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,16 @@ app_expect_values <- function(
193193
)
194194

195195
json_path <- app_next_temp_snapshot_path(self, private, name, "json")
196+
# `NAME.json` -> `NAME_.png`; `NAME_.new.png`
197+
png_path <-
198+
fs::path_ext_set(
199+
paste0(fs::path_ext_remove(json_path), "_"),
200+
"png"
201+
)
202+
203+
# Announce snapshot file before touching before any other expressions can fail
204+
testthat::announce_snapshot_file(json_path)
205+
testthat::announce_snapshot_file(png_path)
196206

197207
url <- app_get_shiny_test_url(
198208
self,
@@ -238,13 +248,6 @@ app_expect_values <- function(
238248
withCallingHandlers(
239249
# swallow expectation
240250
{
241-
# nolint
242-
# `NAME.json` -> `NAME_.png`; `NAME_.new.png`
243-
png_path <-
244-
fs::path_ext_set(
245-
paste0(fs::path_ext_remove(json_path), "_"),
246-
"png"
247-
)
248251
# Take screenshot using snapshot expectation.
249252
# Skip the variant check in `$expect_snapshot()`
250253
# Leverage testthat snapshot logic, but muffle any expectation output
@@ -258,8 +261,8 @@ app_expect_values <- function(
258261
# Muffle any expectation (good or bad) thrown by testthat
259262
expectation = function(ex) {
260263
# Continue, skipping the signaling of the condition
261-
# https://github.com/r-lib/testthat/blob/38c087d3bb5ec3c098c181f1e58a55c687268fba/R/expectation.R#L32-L34
262-
invokeRestart("continue_test")
264+
# https://github.com/r-lib/testthat/pull/2271/files#diff-eeb22563925ae9725656cfbfc44bd5001428734041747d5d90d364464e8e651cR107
265+
invokeRestart("muffle_expectation")
263266
}
264267
)
265268
}

man/compare_screenshot_threshold.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)