Skip to content

Commit

Permalink
feat: use hint instead library/pkgload
Browse files Browse the repository at this point in the history
  • Loading branch information
averissimo committed Apr 17, 2024
1 parent f6d1c5e commit a6c801e
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions tests/testthat/test-examples.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,16 @@ suppress_warnings <- function(expr, pattern = "*", ...) {
}

with_mocked_app_bindings <- function(code) {
shiny__shinyApp <- shiny::shinyApp # nolint object_name_linter.

shiny__shinyApp <- shiny::shinyApp # nolint object_name.
shiny__runApp <- shiny::runApp # nolint object_name.
# workaround of https://github.com/rstudio/shinytest2/issues/381
# change to `print(shiny__shinyApp(...))` and remove allow warning once fixed
mocked_shinyApp <- function(ui, server, ...) { # nolint object_name_linter.
mocked_shinyApp <- function(ui, server, ...) { # nolint object_linter.
functionBody(server) <- bquote({
library(.(testthat::testing_package()), character.only = TRUE)
.hint_to_load_package <- add_facet_labels # Hint to shinytest2 when looking for packages in globals
.(functionBody(server))
})
print(do.call(shiny__shinyApp, append(x = list(ui = ui, server = server), list(...))))
shiny::runApp(do.call(shiny__shinyApp, append(x = list(ui = ui, server = server), list(...))))
}

mocked_runApp <- function(x, ...) { # nolint object_name_linter.
Expand Down Expand Up @@ -92,8 +92,6 @@ with_mocked_app_bindings <- function(code) {
## Throw an error instead of a warning (default `AppDriver$new(..., check_names = TRUE)` throws a warning)
app_driver$expect_unique_names()

print(app_driver$get_html(".tab-pane.active"))

err_el <- Filter(
function(x) {
allowed_errors <- getOption("test_examples.discard_error_regex", "")
Expand All @@ -112,6 +110,8 @@ with_mocked_app_bindings <- function(code) {
if (!is.null(err_el <- app_driver$get_html(".shiny-input-container.has-error:not(.shiny-output-error-validation)"))) { # nolint line_length_linter.
stop(sprintf("shinyvalidate error is observed:\n%s", err_el))
}

app_driver$get_screenshot(sprintf("~/%s", uuid::UUIDgenerate()))
}

# support both `shinyApp(...)` as well as prefixed `shiny::shinyApp(...)` calls
Expand Down Expand Up @@ -147,7 +147,6 @@ for (i in rd_files()) {
testthat::test_that(
paste0("example-", basename(i)),
{
print(Sys.getenv("TESTING_DEPTH"))
skip_if_too_deep(5)
if (basename(i) %in% strict_exceptions) {
op <- options()
Expand Down

0 comments on commit a6c801e

Please sign in to comment.