diff --git a/R/TealAppDriver.R b/R/TealAppDriver.R index 3130b78a58..c3426d4965 100644 --- a/R/TealAppDriver.R +++ b/R/TealAppDriver.R @@ -16,8 +16,20 @@ TealAppDriver <- R6::R6Class( # nolint: object_name. #' Initialize a `TealAppDriver` object for testing a `teal` application. #' #' @param data,modules,filter,title,header,footer arguments passed to `init` + #' @param timeout (`numeric`) Default number of milliseconds for any timeout or + #' timeout_ parameter in the `TealAppDriver` class. + #' Defaults to 20s. + #' + #' See [`shinytest2::AppDriver`] `new` method for more details on how to change it + #' via options or environment variables. + #' @param load_timeout (`numeric`) How long to wait for the app to load, in ms. + #' This includes the time to start R. Defaults to 100s. + #' + #' See [`shinytest2::AppDriver`] `new` method for more details on how to change it + #' via options or environment variables #' @param ... Additional arguments to be passed to `shinytest2::AppDriver$new` #' + #' #' @return Object of class `TealAppDriver` initialize = function(data, modules, @@ -25,6 +37,8 @@ TealAppDriver <- R6::R6Class( # nolint: object_name. title = build_app_title(), header = tags$p(), footer = tags$p(), + timeout = rlang::missing_arg(), + load_timeout = rlang::missing_arg(), ...) { private$data <- data private$modules <- modules @@ -37,16 +51,29 @@ TealAppDriver <- R6::R6Class( # nolint: object_name. header = header, footer = footer ) + + # Default timeout is hardcoded to 4s in shinytest2:::resolve_timeout + # It must be set as parameter to the AppDriver suppressWarnings( super$initialize( - shinyApp(app$ui, app$server), + app_dir = shinyApp(app$ui, app$server), name = "teal", variant = platform_variant(), + timeout = rlang::maybe_missing(timeout, 20 * 1000), + load_timeout = rlang::maybe_missing(load_timeout, 100 * 1000), ... ) ) private$set_active_ns() + self$wait_for_idle() + }, + #' @description + #' Append parent [`shinytest2::AppDriver`] `click` method with a call to `waif_for_idle()` method. + #' @param ... arguments passed to parent [`shinytest2::AppDriver`] `click()` method. + click = function(...) { + super$click(...) + self$wait_for_idle() }, #' @description #' Check if the app has shiny errors. This checks for global shiny errors. @@ -112,7 +139,7 @@ TealAppDriver <- R6::R6Class( # nolint: object_name. ) root <- sprintf("%s-%s", private$modules$label, get_unique_labels(tab)) } - self$wait_for_idle(timeout = private$idle_timeout) + self$wait_for_idle() private$set_active_ns() invisible(self) }, @@ -444,8 +471,6 @@ TealAppDriver <- R6::R6Class( # nolint: object_name. module = character(0), filter_panel = character(0) ), - idle_timeout = 20000, # 20 seconds - load_timeout = 100000, # 100 seconds # private methods ---- set_active_ns = function() { all_inputs <- self$get_values()$input diff --git a/man/TealAppDriver.Rd b/man/TealAppDriver.Rd index 3a3e482dbc..0d2e8bb556 100644 --- a/man/TealAppDriver.Rd +++ b/man/TealAppDriver.Rd @@ -20,6 +20,7 @@ driving a teal application for performing interactions for \code{shinytest2} tes \subsection{Public methods}{ \itemize{ \item \href{#method-TealAppDriver-new}{\code{TealAppDriver$new()}} +\item \href{#method-TealAppDriver-click}{\code{TealAppDriver$click()}} \item \href{#method-TealAppDriver-expect_no_shiny_error}{\code{TealAppDriver$expect_no_shiny_error()}} \item \href{#method-TealAppDriver-expect_no_validation_error}{\code{TealAppDriver$expect_no_validation_error()}} \item \href{#method-TealAppDriver-expect_validation_error}{\code{TealAppDriver$expect_validation_error()}} @@ -48,7 +49,6 @@ driving a teal application for performing interactions for \code{shinytest2} tes \if{html}{\out{
Inherited methods