Skip to content

Commit 052e14d

Browse files
committed
Merge branch 'main' into pkg_support
* main: fix(snapshot): Use local testthat edition to announcing files (#419) feat: Allow for dev packages to be dynamically loaded (#402) fix(testthat): Use `muffle_expectation`, not `continue_test` (#418) v0.4.1 (#415) fix: default `transform=` to NULL, not itself (#413) Increment version number to 0.4.0.9000 v0.4.0 (#410) Pre-release cleanups for shinytest 2 0.3.3 (#409) feat: Add `transform=` parameter to `$expect_download()` and `$expect_values()` (#403) chore!: Skip all tests using `AppDriver` during CRAN testing. Deprecate `cran=` parameters (#407) docs: Namespace `ChromoteSession` (#406)
2 parents e003ab3 + f840052 commit 052e14d

File tree

122 files changed

+2513
-828
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

122 files changed

+2513
-828
lines changed

.Rbuildignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,6 @@ _\.new\.png$
2020

2121
^tests/testthat/migrate-apps$
2222
^tests/testthat/apps$
23+
^tests/testthat/pkgs$
2324
^CRAN-SUBMISSION$
2425
^_dev$

.github/workflows/test-actions.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,10 @@ jobs:
3535

3636
- uses: r-lib/actions/setup-r-dependencies@v2
3737
with:
38-
extra-packages:
39-
"local::."
38+
needs: |
39+
shinytest2-testing
40+
extra-packages: |
41+
local::.
4042
4143
# ## Suggested usage
4244
# - name: Test app

.lintr

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@ linters: linters_with_defaults(
22
line_length_linter = NULL,
33
indentation_linter = NULL,
44
commented_code_linter = NULL,
5-
cyclocomp_linter = NULL
5+
return_linter = NULL
66
)
77
exclusions: list(
88
"inst/gha/audit-app.R" = list(
99
"object_usage_linter" = 81
1010
),
11-
"R/cpp11.R"
11+
"R/cpp11.R",
12+
"tests/testthat/pkgs/golem/R/run_app.R",
13+
"vignettes/use-package.Rmd",
14+
"tests/testthat/pkgs/"
1215
)

DESCRIPTION

Lines changed: 39 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,74 @@
11
Package: shinytest2
22
Title: Testing for Shiny Applications
3-
Version: 0.3.2.9001
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.9001
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),
28-
chromote (>= 0.1.2),
28+
chromote (>= 0.5.0),
2929
cli,
3030
fs,
3131
globals (>= 0.14.0),
3232
httr,
3333
jsonlite,
3434
lifecycle (>= 1.0.3),
3535
pingr,
36+
pkgload,
37+
R6 (>= 2.4.0),
3638
rlang (>= 1.0.0),
3739
rmarkdown,
3840
shiny,
3941
withr
4042
Suggests:
43+
box,
4144
deSolve,
4245
diffobj,
4346
ggplot2,
47+
golem,
4448
knitr,
4549
plotly,
4650
png,
51+
rhino,
4752
rstudioapi,
48-
shinyWidgets,
4953
shinytest (>= 1.5.1),
5054
shinyvalidate (>= 0.1.2),
55+
shinyWidgets,
5156
showimage,
57+
spelling,
5258
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
59+
vdiffr (>= 1.0.0)
60+
LinkingTo:
61+
cpp11
62+
VignetteBuilder:
63+
knitr
64+
Config/Needs/check: rstudio/shiny, bslib
65+
Config/Needs/shinytest2-testing: decor
66+
Config/Needs/website: pkgdown, tidyverse/tidytemplate
6167
Config/testthat/edition: 3
68+
Encoding: UTF-8
69+
Language: en-US
70+
Roxygen: list(markdown = TRUE)
71+
RoxygenNote: 7.3.3
6272
Collate:
6373
'R6-helper.R'
6474
'app-driver-chromote.R'
@@ -101,5 +111,3 @@ Collate:
101111
'shinytest2-package.R'
102112
'test-app.R'
103113
'use.R'
104-
LinkingTo:
105-
cpp11

NEWS.md

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

3+
* Added support for local package development for the background Shiny App process in `AppDriver$new(app_dir=)`. In the background test R process, any `library(<pkg>)` or `require(<pkg>)` call will automatically execute `pkgload::load_all()` to load the local R package's source code. Installing the package before testing is no longer required! (#402).
4+
5+
* Added support for function execution for `AppDriver$new(app_dir=)`. You must run the App or document yourself. Similar to `{mirai}`, all packages must be `library()`'d or `require()`'d again as the function is being ran in the background R process (#402).
6+
7+
* Fixed internal bug where `{testthat}` v3.3.0 changed expectation behavior for screenshot snapshots within `App$expect_values()` (#418).
8+
9+
# shinytest2 0.4.1
10+
11+
## Bug
12+
13+
* Fixed a bug where `AppDriver$expect_values(transform=)` default value caused error to be thrown. (#413)
14+
15+
16+
# shinytest2 0.4.0
17+
18+
## Breaking changes
19+
20+
* `{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)
21+
322
## Bug / Improvements
423

524
* Add support for `$click()`ing `{bslib}`'s `input_task_button()` (#389).
@@ -8,7 +27,10 @@
827

928
* 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)
1029

11-
* `{shinytest2}` now imports `{cli}` and no longer imports `{crayon}` (@olivroy, #399).
30+
* `{shinytest2}` now imports `{cli}` and no longer imports `{crayon}` (@olivroy, #399).
31+
32+
* Added [`{testthat}`'s snapshot file `transform=` parameter support](https://github.com/r-lib/testthat/pull/1530) to `AppDriver$expect_download()` and `AppDriver$expect_values()`. This allows for text transformations of the snapshot files before they are compared. (#403)
33+
1234

1335
# shinytest2 0.3.2
1436

R/app-driver-dir.R

Lines changed: 78 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,47 @@
1-
21
app_set_dir <- function(
3-
self, private,
2+
self,
3+
private,
44
app_dir
55
) {
66
ckm8_assert_app_driver(self, private)
77

8+
if (is.function(app_dir)) {
9+
# package_path <- tryCatch(pkgload::pkg_path(), error = function(e) NULL)
10+
package_name <- tryCatch(pkgload::pkg_name(), error = function(e) NULL)
11+
12+
if (
13+
!is.null(package_name) &&
14+
rlang::env_label(environment(app_dir)) ==
15+
rlang::env_label(pkgload::pkg_ns())
16+
) {
17+
# If the function is from the local package, ensure the package is loaded
18+
# Make a new function that first loads the package, then runs the original function
19+
message(
20+
"Upgrading `app_dir` function to load dev package: ",
21+
package_name
22+
)
23+
24+
app_fn <- app_dir
25+
app_dir <- function() {}
26+
rlang::fn_body(app_dir) <- rlang::expr({
27+
# Run app with dev package loaded
28+
# `library()` shimmed in app driver start
29+
library(!!package_name, character.only = TRUE)
30+
31+
.pkg_ns <- rlang::ns_env(!!package_name)
32+
.dev_pkg_run_app <- !!app_fn
33+
environment(.dev_pkg_run_app) <- .pkg_ns
34+
35+
.dev_pkg_run_app()
36+
})
37+
rlang::fn_env(app_dir) <- globalenv()
38+
}
39+
40+
# Set app function
41+
private$dir <- app_dir
42+
return()
43+
}
44+
845
app_dir <- app_dir_value(app_dir)
946

1047
if (!fs::dir_exists(app_dir)) {
@@ -16,7 +53,8 @@ app_set_dir <- function(
1653
paste0("\"", cur_dir, "\"")
1754
}
1855
app_abort(
19-
self, private,
56+
self,
57+
private,
2058
c(
2159
"`app_dir` must be an existing directory",
2260
"i" = paste0("Received: ", cur_dir)
@@ -25,25 +63,33 @@ app_set_dir <- function(
2563
}
2664

2765
shiny_app_and_rmd_abort <- function() {
28-
app_abort(self, private, c(
29-
"`app_dir` must be a directory containing:",
30-
"",
31-
"*" = "an `./app.R` Shiny application",
32-
"",
33-
" " = "or",
34-
"",
35-
"*" = "a Shiny R Markdown file",
36-
"*" = "a `./server.R` Shiny server",
37-
"",
38-
"i" = "If a Shiny R Markdown document is found, it will be the prefered document.",
39-
"i" = "`./app.R` is not compatible with Shiny R Markdown files."
40-
))
66+
app_abort(
67+
self,
68+
private,
69+
c(
70+
"`app_dir` must be a directory containing:",
71+
"",
72+
"*" = "an `./app.R` Shiny application",
73+
"",
74+
" " = "or",
75+
"",
76+
"*" = "a Shiny R Markdown file",
77+
"*" = "a `./server.R` Shiny server",
78+
"",
79+
"i" = "If a Shiny R Markdown document is found, it will be the prefered document.",
80+
"i" = "`./app.R` is not compatible with Shiny R Markdown files."
81+
)
82+
)
4183
}
4284
shiny_app_and_server_abort <- function() {
43-
app_abort(self, private, c(
44-
"`app_dir` contains both `app.R` and `server.R`. Unintented behavior may occur.",
45-
"!" = "Please either use `app.R` or `server.R`, but not both."
46-
))
85+
app_abort(
86+
self,
87+
private,
88+
c(
89+
"`app_dir` contains both `app.R` and `server.R`. Unintented behavior may occur.",
90+
"!" = "Please either use `app.R` or `server.R`, but not both."
91+
)
92+
)
4793
}
4894

4995
if (!fs::dir_exists(app_dir)) {
@@ -74,6 +120,10 @@ app_set_dir <- function(
74120

75121
app_get_dir <- function(self, private) {
76122
ckm8_assert_app_driver(self, private)
123+
if (is.function(private$dir)) {
124+
return(private$dir)
125+
}
126+
77127
as.character(private$dir)
78128
}
79129

@@ -82,6 +132,9 @@ app_dir_has_rmd <- function(self, private, app_dir = missing_arg()) {
82132
ckm8_assert_app_driver(self, private)
83133
app_dir <- self$get_dir()
84134
}
135+
if (is.function(app_dir)) {
136+
return(FALSE)
137+
}
85138
length(app_dir_rmd(app_dir = app_dir)) >= 1
86139
}
87140
app_dir_rmd <- function(self, private, app_dir = rlang::missing_arg()) {
@@ -90,7 +143,11 @@ app_dir_rmd <- function(self, private, app_dir = rlang::missing_arg()) {
90143
app_dir <- self$get_dir()
91144
}
92145
# Similar to https://github.com/rstudio/rmarkdown/issues/2236
93-
docs <- fs::dir_ls(app_dir, regexp = "^[^_].*\\.[Rrq][Mm][Dd]$", type = "file")
146+
docs <- fs::dir_ls(
147+
app_dir,
148+
regexp = "^[^_].*\\.[Rrq][Mm][Dd]$",
149+
type = "file"
150+
)
94151

95152
if (length(docs) >= 1) {
96153
docs <- Filter(docs, f = function(doc_path) {

0 commit comments

Comments
 (0)