You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Documentation: is package installation necessary (golem/leprechaun) #298
The documentation for using shinytest2 with a packaged shiny app states that "shinytest2 requires that your package to be installed when testing".
Could you confirm whether or not this is still the case, please.
A) Without installing the package, the test runs and passes using either devtools::test() at the console or in the RStudio Build window
B) On installing the package (devtools::install()), the test runs and passes as well (either using the R console or the RStudio build window)
C) On changing the package so that output$greeting renders "Hello, Earth!", but without installing the new version of the package, the test fails because of a mismatch between the "Hello Earth!" in the uninstalled package's source code, and the expected "Hello World!" stored in the snapshots.
Is there a subtlety that I've missed? There didn't seem to be a setting where the installed version of the package was used preferentially over the working version when running tests.
This approach is different than what I was originally thinking of. Original thought was to use a directory to test. Ex: shinytest2::AppDriver$new(name = "using_app_folder") or shinytest2::AppDriver$new(system.file("apps/ex_app", package = "FOO"), name = "using_app_folder").
This approach will go to the folder, starts an new R session and try to load everything from scratch. Because there is no hook for "load new code here", it fails to retrieve local updates.
However, your approach loads the app into the main R session and then {shinytest2}saves the app to disk before testing. This allows for you to load your current app's code into main R session before testing. 🎉
This approach is clean. Even if you had a FOO:::my_method() call within your server function, it should try to load the locally loaded method from your local FOO package.
I believe there could be some subtle issues that can come out of making an app object directly, then resaving it somewhere else before testing it. There also might be some serialization issues when sending the app object to the background process. However, the gain of being able to test your local package without having to install would be magnitudes better.
Ideally, I'm hoping we can just use the {testthat} infrastructure to load the local package instead of {shinytest2}'s save app to disk functionality. Then everything is consistent with how {testthat} executes tests.
Thanks, I'm tidying up a couple of blogposts for publication this month and was a bit worried about this. The code above works fine for me, but it says you should install your package on the shinytest2 website. Basically, I didn't want to show a non-recommended way of working with shinytest2 if it might trip them up further down the line.
Activity
schloerke commentedon Jan 5, 2023
OOooooo. Nice work around!
This approach is different than what I was originally thinking of. Original thought was to use a directory to test. Ex:
shinytest2::AppDriver$new(name = "using_app_folder")orshinytest2::AppDriver$new(system.file("apps/ex_app", package = "FOO"), name = "using_app_folder").This approach will go to the folder, starts an new R session and try to load everything from scratch. Because there is no hook for "load new code here", it fails to retrieve local updates.
However, your approach loads the app into the main R session and then
{shinytest2}saves the app to disk before testing. This allows for you to load your current app's code into main R session before testing. 🎉This approach is clean. Even if you had a
FOO:::my_method()call within your server function, it should try to load the locally loaded method from your localFOOpackage.I believe there could be some subtle issues that can come out of making an app object directly, then resaving it somewhere else before testing it. There also might be some serialization issues when sending the app object to the background process. However, the gain of being able to test your local package without having to install would be magnitudes better.
Ideally, I'm hoping we can just use the
{testthat}infrastructure to load the local package instead of{shinytest2}'s save app to disk functionality. Then everything is consistent with how{testthat}executes tests.russHyde commentedon Jan 5, 2023
Thanks, I'm tidying up a couple of blogposts for publication this month and was a bit worried about this. The code above works fine for me, but it says you should install your package on the shinytest2 website. Basically, I didn't want to show a non-recommended way of working with shinytest2 if it might trip them up further down the line.
schloerke commentedon Jan 5, 2023
Thank you!
When your blogs are posted, can you please comment in #299.
schloerke commentedon Nov 18, 2025
Closing as #402 attempt to load the local package and adjusted documentation to state installation is no longer required.