rstudio / shinytest

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

Can't make test without snapshot (or how to check if your app starts without errors) #422

Open burgerga opened 2 years ago

burgerga commented 2 years ago

Our app is in heavy development and I'm just interested to see if the app starts without errors

So using a shinytest like this won't work:

# file: test-app-runs.R
app <- ShinyDriver$new("../../")

because it doesn't create an current directory:

Error (test-app-runs.R:10:3): runApp() works
Error: Current result directory not found: app/tests/shinytest/app-runs-current
Backtrace:
 1. shinytest::expect_pass(testApp(test_path("app"), compareImages = FALSE)) test-app-runs.R:10:2
 2. shinytest::testApp(test_path("app"), compareImages = FALSE)
 3. shinytest::snapshotCompare(...)
 4. base::lapply(...)
 5. shinytest:::FUN(X[[i]], ...)
 6. shinytest:::snapshotCompareSingle(...)
 7. shinytest::snapshotUpdate(appDir, testname, quiet = quiet, suffix = suffix)
 8. shinytest:::snapshotUpdateSingle(appDir, testname, quiet, suffix)

So I looked at the items option of snapshot, but this also doesn't work

# file: test-app-runs.R
app <- ShinyDriver$new("../../")
app$snapshotInit("app-runs", screenshot = F)
app$waitForShiny()
app$snapshot(items = list(input = F, output = F, export = F))

result:

Running app-runs.R Query failed (400)----------------------
No encoding supplied: defaulting to UTF-8.
None of export, input, or output requested. 
----------------------------------------
x | 1       0 | app-runs [9.7s]                                
---------------------------------------------------------------
Error (test-app-runs.R:10:3): runApp() works
Error in `httr_get(url)`: Unable request data from server
Backtrace:
  1. shinytest::expect_pass(testApp(test_path("app"), compareImages = FALSE)) test-app-runs.R:10:2
  2. shinytest::testApp(test_path("app"), compareImages = FALSE)
  3. base::lapply(...)
  4. shinytest:::FUN(X[[i]], ...)
  5. base::source(testname, local = env)
  7. [ base::eval(...) ] with 1 more call
  9. app$snapshot(items = list(input = F, output = F, export = F))
 10. shinytest:::sd_snapshot(self, private, items, filename, screenshot)
 11. shinytest:::httr_get(url)

If I change any of the items to T, the test starts working, but I am not interested in those values.

Is there a way to fix this (write an empty json?) or is there an easier way to test if an app runs that I am missing?