Skip to content

Commit 0679813

Browse files
authored
chore!: Skip all tests using AppDriver during CRAN testing. Deprecate cran= parameters (#407)
1 parent ec1477a commit 0679813

15 files changed

+555
-273
lines changed

DESCRIPTION

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ Imports:
3535
rlang (>= 1.0.0),
3636
rmarkdown,
3737
shiny,
38-
withr
38+
withr,
39+
lifecycle
3940
Suggests:
4041
deSolve,
4142
diffobj,

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ importFrom(cli,col_magenta)
2323
importFrom(cli,col_red)
2424
importFrom(cli,col_silver)
2525
importFrom(cli,make_ansi_style)
26+
importFrom(lifecycle,deprecated)
2627
importFrom(rlang,"%||%")
2728
importFrom(rlang,":=")
2829
importFrom(rlang,list2)

NEWS.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# shinytest2 (development version)
22

3+
## Breaking changes
4+
5+
* `{shinytest2}` will skip and test on CRAN where an `AppDriver` is initialized. From a request from CRAN, using [`{chromote}` during CRAN package testing](https://rstudio.github.io/chromote/articles/example-cran-tests.html) should be avoided as it can create failing tests over time due to application changes within the testing machine, not changes in package code. Since `AppDriver` directly depends on `{chromote}` to test Shiny applications, creating an `AppDriver` should always skip the current test during CRAN package testing. This decision was made to achieve consistent testing behavior over time (rather than silently skipping tests that are expected to run due to a Chrome update). To escape this behavior, you can set the system environment variable `SHINYTEST2_APP_DRIVER_TEST_ON_CRAN=1`. Following `{chromote}`'s recommendation, you should test your R package [in a CI environment, ideally on a weekly or monthly schedule](https://rstudio.github.io/chromote/articles/example-cran-tests.html) to test your Shiny app with the latest R package versions. (#407)
6+
37
## Bug / Improvements
48

59
* Add support for `$click()`ing `{bslib}`'s `input_task_button()` (#389).
@@ -8,7 +12,7 @@
812

913
* The `threshold` and `kernel_size` default values of the `AppDriver$expect_screenshot()` method are now configurable via two new global options: `shinytest2.compare_screenshot.threshold` and `shinytest2.compare_screenshot.kernel_size` (#401)
1014

11-
* `{shinytest2}` now imports `{cli}` and no longer imports `{crayon}` (@olivroy, #399).
15+
* `{shinytest2}` now imports `{cli}` and no longer imports `{crayon}` (@olivroy, #399).
1216

1317
# shinytest2 0.3.2
1418

R/app-driver-expect-download.R

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
21
app_download <- function(
3-
self, private,
2+
self,
3+
private,
44
output,
55
name = NULL,
66
save_dir = tempdir(),
@@ -25,11 +25,18 @@ app_download <- function(
2525
# Find suggested name
2626
content_dispo <- httr::headers(req)[["content-disposition"]]
2727
filename_header <- NULL
28-
if (length(content_dispo) == 1 && is.character(content_dispo) && nzchar(content_dispo)) {
28+
if (
29+
length(content_dispo) == 1 &&
30+
is.character(content_dispo) &&
31+
nzchar(content_dispo)
32+
) {
2933
vals <- strsplit(content_dispo, "filename=")[[1]]
3034
if (length(vals) > 1) {
3135
filename_header <- gsub("\"", "", vals[2], fixed = TRUE)
32-
self$log_message(paste0("Content disposition file name: ", filename_header))
36+
self$log_message(paste0(
37+
"Content disposition file name: ",
38+
filename_header
39+
))
3340
}
3441
}
3542

@@ -83,14 +90,14 @@ app_expect_download <- function(
8390
output,
8491
...,
8592
compare = NULL,
86-
name = NULL,
87-
cran = FALSE
93+
name = NULL
8894
) {
8995
ckm8_assert_app_driver(self, private)
9096
rlang::check_dots_empty()
9197

9298
snapshot_info <- app_download(
93-
self, private,
99+
self,
100+
private,
94101
output = output,
95102
name = name,
96103
# Save within temp app dir
@@ -101,19 +108,19 @@ app_expect_download <- function(
101108

102109
# Compare download_file content
103110
app__expect_snapshot_file(
104-
self, private,
111+
self,
112+
private,
105113
snapshot_info$download_path,
106-
cran = cran,
107114
compare = compare
108115
)
109116

110117
# Compare requested filename
111118
requested_download_name <- snapshot_info$filename_header
112119
if (!is.null(requested_download_name)) {
113120
app__expect_snapshot_value(
114-
self, private,
115-
requested_download_name,
116-
cran = cran
121+
self,
122+
private,
123+
requested_download_name
117124
)
118125
}
119126

@@ -122,7 +129,8 @@ app_expect_download <- function(
122129

123130

124131
app_get_download <- function(
125-
self, private,
132+
self,
133+
private,
126134
output,
127135
filename = NULL
128136
) {
@@ -140,7 +148,8 @@ app_get_download <- function(
140148
}
141149

142150
snapshot_info <- app_download(
143-
self, private,
151+
self,
152+
private,
144153
output = output,
145154
name = name,
146155
save_dir = save_dir,

R/app-driver-expect-js.R

Lines changed: 40 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,25 @@
1-
app_js_script_helper <- function(self, private, script = missing_arg(), file = missing_arg()) {
1+
app_js_script_helper <- function(
2+
self,
3+
private,
4+
script = missing_arg(),
5+
file = missing_arg()
6+
) {
27
ckm8_assert_app_driver(self, private)
38
if (rlang::is_missing(file)) return(script)
49

510
if (!rlang::is_missing(script)) {
6-
app_warn(self, private,
11+
app_warn(
12+
self,
13+
private,
714
"Both `file` and `script` are specified. `script` will be ignored."
815
)
916
}
1017
read_utf8(file)
1118
}
1219

1320
app_get_js <- function(
14-
self, private,
21+
self,
22+
private,
1523
script,
1624
...,
1725
file = missing_arg(),
@@ -31,7 +39,8 @@ app_get_js <- function(
3139
)$result$value
3240
}
3341
app_run_js <- function(
34-
self, private,
42+
self,
43+
private,
3544
script,
3645
...,
3746
file = missing_arg(),
@@ -56,13 +65,13 @@ app_run_js <- function(
5665

5766

5867
app_expect_js <- function(
59-
self, private,
68+
self,
69+
private,
6070
script,
6171
...,
6272
file = missing_arg(),
6373
timeout = missing_arg(),
64-
pre_snapshot = NULL,
65-
cran = FALSE
74+
pre_snapshot = NULL
6675
) {
6776
ckm8_assert_app_driver(self, private)
6877
rlang::check_dots_empty()
@@ -82,20 +91,23 @@ app_expect_js <- function(
8291
# Must use _value_ output as _print_ output is unstable
8392
# over different R versions and locales
8493
app__expect_snapshot_value(
85-
self, private,
86-
result,
87-
cran = cran
94+
self,
95+
private,
96+
result
8897
)
8998
}
9099

91100

92101
get_text_js <- function(selector) {
93102
paste0(
94-
"Array.from(document.querySelectorAll(", toJSON_atomic(selector), ")).map((item, i) => item.textContent);"
103+
"Array.from(document.querySelectorAll(",
104+
toJSON_atomic(selector),
105+
")).map((item, i) => item.textContent);"
95106
)
96107
}
97108
app_get_text <- function(
98-
self, private,
109+
self,
110+
private,
99111
selector
100112
) {
101113
ckm8_assert_app_driver(self, private)
@@ -107,18 +119,17 @@ app_get_text <- function(
107119
unlist(ret)
108120
}
109121
app_expect_text <- function(
110-
self, private,
122+
self,
123+
private,
111124
selector,
112-
...,
113-
cran = FALSE
125+
...
114126
) {
115127
ckm8_assert_app_driver(self, private)
116128
rlang::check_dots_empty()
117129

118130
self$expect_js(
119131
script = get_text_js(selector),
120-
pre_snapshot = unlist,
121-
cran = cran
132+
pre_snapshot = unlist
122133
)
123134

124135
invisible(self)
@@ -127,12 +138,17 @@ app_expect_text <- function(
127138

128139
get_html_js <- function(selector, outer_html) {
129140
paste0(
130-
"let map_fn = ", toJSON_atomic(outer_html), " ? (item, i) => item.outerHTML : (item, i) => item.innerHTML;\n",
131-
"Array.from(document.querySelectorAll(", toJSON_atomic(selector), ")).map(map_fn);"
141+
"let map_fn = ",
142+
toJSON_atomic(outer_html),
143+
" ? (item, i) => item.outerHTML : (item, i) => item.innerHTML;\n",
144+
"Array.from(document.querySelectorAll(",
145+
toJSON_atomic(selector),
146+
")).map(map_fn);"
132147
)
133148
}
134149
app_get_html <- function(
135-
self, private,
150+
self,
151+
private,
136152
selector,
137153
...,
138154
outer_html = TRUE
@@ -146,19 +162,18 @@ app_get_html <- function(
146162
unlist(ret)
147163
}
148164
app_expect_html <- function(
149-
self, private,
165+
self,
166+
private,
150167
selector,
151168
...,
152-
outer_html = TRUE,
153-
cran = FALSE
169+
outer_html = TRUE
154170
) {
155171
ckm8_assert_app_driver(self, private)
156172
rlang::check_dots_empty()
157173

158174
self$expect_js(
159175
script = get_html_js(selector, isTRUE(outer_html)),
160-
pre_snapshot = unlist,
161-
cran = cran
176+
pre_snapshot = unlist
162177
)
163178

164179
invisible(self)

0 commit comments

Comments
 (0)