Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
53ee0a4
Update .gitignore
schloerke Feb 1, 2023
a572661
Turn off `check_setup` by default
schloerke Feb 1, 2023
da036f2
Move test files and snaps for hello test app
schloerke Feb 1, 2023
7047ac8
Move bookmark app to inline app
schloerke Feb 1, 2023
a4d7a5f
Move download app
schloerke Feb 1, 2023
e20f828
Move `window` app
schloerke Feb 1, 2023
b5b51d4
Move `widgets` app
schloerke Feb 1, 2023
25298b0
Move `wait` and `upload` apps
schloerke Feb 2, 2023
49f3bf2
Update test-app.R
schloerke Feb 2, 2023
827ce45
Move `update` app
schloerke Feb 2, 2023
72864d4
Move `text_html` app
schloerke Feb 2, 2023
8b4aa7f
Move `stop` app
schloerke Feb 2, 2023
c05b525
Move `export` app
schloerke Feb 2, 2023
52a947a
Move rmd apps
schloerke Feb 2, 2023
fb3cc8d
Move `quarto` app
schloerke Feb 2, 2023
2c21b33
Move `plotly` app
schloerke Feb 2, 2023
40fba47
Move `image` app
schloerke Feb 2, 2023
b042c0b
Move `files` apps
schloerke Feb 2, 2023
8f73ee6
Move `export` app
schloerke Feb 2, 2023
4ab2862
Move `profile` app
schloerke Feb 2, 2023
7e6ca07
Move test-app test file
schloerke Feb 2, 2023
9364d01
lint
schloerke Feb 2, 2023
148ba80
Bump dev version
schloerke Feb 2, 2023
613f58a
Update snaps
schloerke Feb 10, 2023
46665f8
Add todos; Deprecate `test_app(check_setup=TRUE)`; Add `test_app()` w…
schloerke Feb 10, 2023
63bbf85
Update test-app.R
schloerke Feb 10, 2023
5ab4576
Merge branch 'main' into pkg_support
schloerke Feb 22, 2023
5436a18
Update TODO
schloerke Feb 23, 2023
15bf131
tmp
schloerke Apr 10, 2024
8c6aaa5
Merge branch 'main' into pkg_support
schloerke Feb 10, 2025
6b4109f
Merge branch 'main' into pkg_support
schloerke Feb 10, 2025
e003ab3
Merge branch 'main' into pkg_support
schloerke Feb 10, 2025
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 .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ docs
inst/doc
/doc/
/Meta/
CRAN-SUBMISSION
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: shinytest2
Title: Testing for Shiny Applications
Version: 0.3.2.9000
Version: 0.3.2.9001
Authors@R:
c(
person("Barret", "Schloerke", role = c("cre", "aut"), email = "barret@posit.co", comment = c(ORCID = "0000-0001-9986-114X")),
Expand Down Expand Up @@ -31,6 +31,7 @@ Imports:
globals (>= 0.14.0),
httr,
jsonlite,
lifecycle (>= 1.0.3),
pingr,
rlang (>= 1.0.0),
rmarkdown,
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ importFrom(cli,col_magenta)
importFrom(cli,col_red)
importFrom(cli,col_silver)
importFrom(cli,make_ansi_style)
importFrom(lifecycle,deprecated)
importFrom(rlang,"%||%")
importFrom(rlang,":=")
importFrom(rlang,list2)
Expand Down
2 changes: 2 additions & 0 deletions R/record-test.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
warning("TODO-barret; Record test should save the recording into the package if within a package.")

#' Launch test event recorder for a Shiny app
#'
#' Once a recording is completed, it will create or append a new
Expand Down
85 changes: 52 additions & 33 deletions R/test-app.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
warning("TODO-barret; test check_setup values")
warning("TODO-barret; requires R file loading; Look into using `testthat::test_dir(load_package=)` and `testthat:::test_files_setup_env()`")
warning("TODO-barret; use-package.Rmd vignette")

# Import something from testthat to avoid a check error that nothing is imported from a `Depends` package
#' @importFrom testthat default_reporter
NULL
Expand Down Expand Up @@ -70,11 +74,9 @@ NULL
#' @param name Name to display in the middle of the test name. This value is only used
#' when calling `test_app()` inside of \pkg{testhat} test. The final testing context will
#' have the format of `"{test_context} - {name} - {app_test_context}"`.
#' @param check_setup If `TRUE`, the app will be checked for the presence of
#' `./tests/testthat/setup-shinytest2.R`. This file must contain a call to
#' [`shinytest2::load_app_env()`].
#' @param reporter Reporter to pass through to [`testthat::test_dir()`].
#' @param stop_on_failure If missing, the default value of `TRUE` will be used. However, if missing and currently testing, `FALSE` will be used to seamlessly integrate the app reporter to `reporter`.
#' @param check_setup [Deprecated]. Parameter ignored.
#' @seealso
#' * [`record_test()`] to create tests to record against your Shiny application.
#' * [testthat::snapshot_review()] and [testthat::snapshot_accept()] if
Expand All @@ -83,13 +85,15 @@ NULL
#' This is only necessary if you want access to the values while testing.
#'
#' @export
#' @importFrom lifecycle deprecated
test_app <- function(
app_dir = missing_arg(),
...,
name = missing_arg(),
check_setup = TRUE,
reporter = testthat::get_reporter(),
stop_on_failure = missing_arg()
# TODO-v0.4.0; Remove this argument and let `...` handle it
stop_on_failure = missing_arg(),
check_setup = deprecated()
) {
# Inspiration from https://github.com/rstudio/shiny/blob/a8c14dab9623c984a66fcd4824d8d448afb151e7/inst/app_template/tests/testthat.R

Expand All @@ -114,40 +118,29 @@ test_app <- function(

app_dir <- app_dir_value(app_dir)

if (isTRUE(check_setup)) {
# Legacy support for `setup.R`; Same content, just different name
setup_paths <- fs::path(app_dir, "tests", "testthat", c("setup-shinytest2.R", "setup.R"))
setup_paths_exist <- fs::file_exists(setup_paths)
if (!any(setup_paths_exist)) {
rlang::abort(
c(
"No `setup-shinytest2.R` file found in `./tests/testthat`",
"i" = paste0("To create a `setup-shinytest2.R` file, please run `shinytest2::use_shinytest2(\"", app_dir, "\", setup = TRUE)`"),
"i" = "To disable this message, please set `test_app(check_setup = FALSE)`"
)
)
}
found <- FALSE
for (setup_path in setup_paths) {
if (has_load_app_env(setup_path)) {
found <- TRUE
break
}
}
if (!found) {
rlang::abort(
c(
"No call to `shinytest2::load_app_env()` found in `./tests/testthat/setup-shinytest2.R`",
"i" = paste0("To create a `setup-shinytest2.R` file, please run `shinytest2::use_shinytest2(\"", app_dir, "\", setup = TRUE)`"),
"i" = "To disable this message, please set `test_app(check_setup = FALSE)`"
# If value is provided and `TRUE`...
if (lifecycle::is_present(check_setup)) {
if (isTRUE(check_setup)) {
lifecycle::deprecate_warn(
"0.1.0",
"shinytest2::test_app(check_setup = 'is no longer used')",
details = c(
"To manually load an app's support files, call `shinytest2::local_app_support(app_dir=)` within your {testthat} test",
i = "Please see `?shinytest2::local_app_support` for more information"
)
)
}
}



if (testthat::is_testing()) {
warning("TODO-barret; missing url for migration warning")
rlang::warn(c(
"x" = "Calling `shinytest2::test_app()` within a {testthat} test has been deprecated in {shinytest2} v0.3.0",
"!" = "Calling `shinytest2::test_app()` within a {testthat} test will be hard deprecated in {shinytest2} v0.4.0",
"i" = "If you are testing within a package, please see URL on how to migrate your App tests to be located in your package tests.",
"i" = "If you are using CI, don't forget to collect your new snapshots after your initial run."
))

# Normalize the reporter given any input
outer_reporter <- testthat::with_reporter(reporter, testthat::get_reporter(), start_end_reporter = FALSE)

Expand Down Expand Up @@ -283,6 +276,32 @@ load_app_env <- function(
shiny::loadSupport(app_dir, renv = renv, globalrenv = globalrenv)
}

warning("Document how to use load_app_env() in both an app testing context and a package testing context.")

# warning("load_app_env() is deprecated. Use `load_app_support()` / `with_app_support()` instead.")
# # #' @export
# # local_app_env <- function(
# local_app_support <- function(
# app_dir,
# envir = rlang::caller_env()
# ) {
# shiny::loadSupport(app_dir, renv = envir, globalrenv = envir)
# }

# with_app_support <- function(
# app_dir,
# expr,
# envir = rlang::caller_env()
# ) {

# # Make new environment
# tmp_envir <- rlang::new_environment(parent = envir)
# # Load support files into new environment
# local_app_support(app_dir, envir = tmp_envir)
# # Evaluate expression in new environment
# withr::with_environment(tmp_envir, expr, name = "app_support")
# }


has_load_app_env <- function(file) {
if (!fs::file_exists(file)) {
Expand Down
Binary file modified logo/shinytest2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading