rstudio / shinytest

Automated testing for shiny apps
https://rstudio.github.io/shinytest/
Other
225 stars 55 forks source link

testServer error: '' does not exist in current working directory when trying to find data files #430

Closed matt-sd-watson closed 2 years ago

matt-sd-watson commented 2 years ago

I am currently implementing server-side testing using testServer with a shiny app wrapped in a function like so:

testServer(my_app::app_func(), expr = {}

where expr has a number of specific tests for the behaviour of the app. The tests run properly using devtools::test() but do not run with devtools::check() due to the following error:

══ Failed tests ════════════════════════════════════════════════════════════════
── Error (test_server.R:13:3): Server has functionality ────────────────────────
Error: '' does not exist in current working directory ('/private/var/folders/b0/t5xcnhp13831xdy00jfm2j400000gn/T/Rtmp84ItLk/my_app.Rcheck/tests/testthat').
Backtrace:
    ▆
 1. ├─shiny::testServer(...) at test_server.R:13:2
 2. │ └─shiny:::isModuleServer(app)
 3. ├─my_app::app_func()
 4. │ └─readr::read_csv(...)
 5. │   └─vroom::vroom(...)
 6. │     └─vroom:::vroom_(...)
 7. └─vroom (local) `<fn>`("")
 8.   └─vroom:::check_path(path)

The traceback is linked to a CSV file that is read in for every shiny session that allows the app to perform calculations.

Is there a way to properly specify the top-level directory for the package for testServer so that the testing framework is able to find the files required for the server testing?

matt-sd-watson commented 2 years ago

errors are caused by the change in working directory between devtools::test() and both devtools::check() and R CMD check. Saving the session input files as internal package sysdata allows all tests to complete while having the package load the package data for the session inputs.