Skip to content
Merged
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
### Enhancements

* Exported `select_decorators()` to help module developers resolve the decorators applied to a specific output (#1733).
* Add support for function argument in `TealAppDriver$new(app)`.

### Bug fixes

Expand Down
33 changes: 18 additions & 15 deletions R/TealAppDriver.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@ TealAppDriver <- R6::R6Class( # nolint: object_name.
#' @description
#' Initialize a `TealAppDriver` object for testing a `teal` application.
#'
#' @param app (`teal_app`)
#' @param app (`teal_app` or `function`) The `teal` application to be tested.
#' This value can be 2 different things:
#' - A `teal_app` object, which is the result of calling `teal::init()`.
#' - A function that returns a `teal_app` object.
#'
#' Other values that [`shinytest2::AppDriver`] `new()` functions accepts are not yet supported.
#' @param options (`list`) passed to `shinyApp(options)`. See [shiny::shinyApp()].
#' @param timeout (`numeric`) Default number of milliseconds for any timeout or
#' timeout_ parameter in the `TealAppDriver` class.
Expand All @@ -51,7 +56,12 @@ TealAppDriver <- R6::R6Class( # nolint: object_name.
timeout = rlang::missing_arg(),
load_timeout = rlang::missing_arg(),
...) {
checkmate::assert_class(app, "teal_app")
checkmate::assert(
combine = "or",
.var.name = "app",
checkmate::check_function(app),
checkmate::check_class(app, "teal_app")
)
checkmate::assert_list(teal_options, names = "named")
# Default timeout is hardcoded to 4s in shinytest2:::resolve_timeout
# New default is set with environment variables if not already set by user
Expand All @@ -61,28 +71,21 @@ TealAppDriver <- R6::R6Class( # nolint: object_name.
extra_envvar$SHINYTEST2_TIMEOUT <- "20000"
}
if (Sys.getenv("SHINYTEST2_LOAD_TIMEOUT") == "") {
extra_envvar$SHINYTEST2_TIMEOUT <- "100000"
}

if (length(teal_options)) {
orig_server <- app$server
opts <- teal_options
app$server <- function(input, output, session) {
do.call(base::options, opts)
orig_server(input, output, session)
}
extra_envvar$SHINYTEST2_LOAD_TIMEOUT <- "100000"
}

rlang::check_installed("withr")
suppressWarnings(
withr::with_envvar(
new = extra_envvar,
code = super$initialize(
shiny::shinyApp(ui = app$ui, server = app$server, options = options),
if (is.function(app)) app else shiny::shinyApp(ui = app$ui, server = app$server),
Comment thread
averissimo marked this conversation as resolved.
Resolved
name = "teal",
variant = shinytest2::platform_variant(),
timeout = timeout,
load_timeout = load_timeout
load_timeout = load_timeout,
shiny_args = options,
Comment thread
averissimo marked this conversation as resolved.
Resolved
options = teal_options
)
)
)
Expand Down Expand Up @@ -128,7 +131,7 @@ TealAppDriver <- R6::R6Class( # nolint: object_name.
super$stop(...)
},
#' @description
#' Append parent [`shinytest2::AppDriver`] `click` method with a call to `waif_for_idle()` method.
#' Append parent [`shinytest2::AppDriver`] `click` method with a call to `wait_for_idle()` method.
#' @param ... arguments passed to parent [`shinytest2::AppDriver`] `click()` method.
click = function(...) {
super$click(...)
Expand Down
11 changes: 9 additions & 2 deletions man/TealAppDriver.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading