Open schloerke opened 2 years ago
Should we not run the load_env()
logic if:
golem
is in app.R
and DESCRIPTION
contains a Package
field?pkgload::load_all
in app.R
?# Launch the ShinyApp
?Current logic in shiny::loadSupport()
that triggers the warning:
if (
file.exists(file.path.ci(appDir, "NAMESPACE")) ||
(
file.exists(descFile) &&
identical(as.character(read.dcf(descFile, fields = "Type")), "Package")
)
) {
# display warning
}
Maybe it is a documentation thing. If NAMESPACE
is found, then maybe we should not auto check for the tests/testthat/setup-shinytest2.R
file in shinytest2::test_app(check_setup=TRUE)
in tests/testthat.R
's
Maybe the initial value could be !fs::file_exists(fs::path(app_dir, "NAMESPACE"))
? Reasoning is that NAMESPACE files will never really exist without a DESCRIPTION
file.
Could also look for inst/golem-config.yml
. If that file exists, then do not require a setup file. But this seems too specific to {golem}
.
Moving forward with trying to find a NAMESPACE file and altering behavior accordingly.
So more can of worms... which will cause this to be moved to next release 😞
Should we try using testthat for everything? Ex: test_dir(load_package = "source")
Situations:
Current behavior:
shinytest2::load_env()
/ shiny::loadSupport()
shinytest2::load_env()
/ shiny::loadSupport()
shiny::loadSupport()
shiny::loadSupport()
shiny::loadSupport()
shiny::loadSupport()
Using testthat only?:
testthat::source_file()
?testthat::test_dir(load_package = "source")
?testthat::test_dir(load_package = "source")
testthat::source_file()
?testthat::test_dir(load_package = "source")
testthat::source_file()
?testthat::test_dir(load_package = "source")
Feels bad not using {shiny}
load support method. But it could be argued that shiny::loadSupport()
should not have existed in the first place.
What about using test_env(PKG.NAME)
? This might resolve https://github.com/rstudio/shinytest2/issues/215 moving forward.
Test env may need to be loaded in the R background process if used in the foreground.
In conversation with @Shelmith-Kariuki, she was able to get around the warnings by creating the App object and supplying it directly to AppDirver
. Ex:
# Create app
shiny_app <- shinyreprexpkg::run_app()
# Test app
app <- AppDriver$new(shiny_app)
# test using `app`
In addition, the R folder does not need to be sourced as shinyreprexpkg
should exist as an installed package. To get around the setup script check, tests/testthat/setup-shinytest.R
file only needs to contain the text load_app_env
. For example, this can be inside a comment:
# File: tests/testthat/setup-shinytest2.R
# Do not load code via `load_app_env`
... which will be found with https://github.com/rstudio/shinytest2/blob/6850de4a421fd592873e638d6deda8a4fd176660/R/test-app.R#L293
From https://github.com/rstudio/shinytest2/issues/245#issue-1333355278
Looking at reprex Shiny golem package: https://github.com/whipson/shinytest2reprex
tree
:DESCRIPTION
file:app.R
shinytest2reprex::run_app() returns a shiny object, it does NOT call a
shiny::runApp()
.