Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AppDriver$new registers the app path with devtools::test() but fails with devtools::check() #432

Open
matt-sd-watson opened this issue Dec 7, 2022 · 0 comments

Comments

@matt-sd-watson
Copy link

matt-sd-watson commented Dec 7, 2022

I am implementing snapshot/screenshot-based testing for a Shiny app that is wrapped in a R package using shinytest2.

The basic layout of the directories in my package is as follows (some files omitted for simplicity);

.
├── app.R
├── R
│   ├── app.R
├── README.md
├── tests
│   ├── testthat
│   │   ├── setup-shinytest2.R
│   │   ├── _snaps
│   │   │   └── linux-4.2
│   │   │       └── shinytest2
│   │   │           └── myapp-001.png
│   │   ├── test-shinytest2.R
│   └── testthat.R

The app is calling a function in app.R from the base directory that originally comes from the R/app.R directory, which is a shinyApp() function call on a UI and server function, respectively. The contents of app.R is:

library(BiocManager)
options(repos = BiocManager::repositories())
options(shiny.autoload.r=FALSE)

pkgload::load_all()
myapp::myapp()

The contents of the test-shinytest2.R file are as follows:

library(shinytest2)

test_that("{shinytest2} recording: my-app", {
  app <- AppDriver$new(app_dir = test_path("../../"),
                       variant = platform_variant(), name = "my-app", height = 732, 
      width = 1161, load_timeout = 1e+05
      # shinyOptions = list(test.mode = TRUE)
      )
  app$expect_screenshot()
})

When using devtools::test(), this test passes with no problems, but when calling through devtools::check(), the following error occurs:

Error in `app_initialize(self, private, app_dir = app_dir, ..., load_timeout = load_timeout, 
    timeout = timeout, wait = wait, expect_values_screenshot_args = expect_values_screenshot_args, 
    screenshot_args = screenshot_args, check_names = check_names, 
    name = name, variant = variant, view = view, height = height, 
    width = width, seed = seed, clean_logs = clean_logs, shiny_args = shiny_args, 
    render_args = render_args, options = options)`: Error starting shiny application:
Loading required package: shiny
Error in shinyAppDir(x) : App dir must contain either app.R or server.R.


ℹ You can inspect the failed AppDriver object via `rlang::last_error()$app`
ℹ AppDriver logs:
{shinytest2} R info   04:02:23.73 Start AppDriver initialization
{shinytest2} R info   04:02:23.73 Starting Shiny app
{shinytest2} R info   04:02:24.83 Error while initializing AppDriver:
                                  Error starting shiny application:
                                  Loading required package: shiny
                                  Error in shinyAppDir(x) : App dir must contain either app.R or server.R.
{shiny}      R stderr ----------- Loading required package: shiny
{shiny}      R stderr ----------- Error in shinyAppDir(x) : App dir must contain either app.R or server.R.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant