ThinkR-open / golem

A Framework for Building Robust Shiny Apps
https://thinkr-open.github.io/golem/
Other
908 stars 132 forks source link

Golem and Shinytest #461

Open hijifres opened 4 years ago

hijifres commented 4 years ago

Hi,

Many thanks for this great framework. I was wondering if there was a way to combine golem and Shinytest, as testApp() only take a "path" argument, in which there must be an app.R file or ui.R / server.R files.

Is that achievable?

ColinFay commented 4 years ago

hello!

Sure thing, you can do:

golem::add_rstudioconnect_file()
shinytest::recordTest()

See https://engineering-shiny.org/step-secure.html#shinytest for more information

AlexandraKapp commented 4 years ago

Hi, I'm also using golem and Shinytest. This works fine when running shiny::runTests()or devtools::test(), but I don't get it to work with devtools::check() (and therefore also not on the CI).

I get this error:

`> pkgload::load_all()

[error]Error: No root directory found in /tmp/Rtmpyq9iyB/PACKAGE_NAME.Rcheck/tests or its parent directories. Root criterion: contains a file DESCRIPTION`

I followed this instructions, to run shinytests within a package: https://rstudio.github.io/shinytest/articles/package.html There another "app.R" file is created within the testfolder which is used for testing (instead of the app.R in the root folder).

Is there a possibility to get this to work? I'm happy to provide a reproducable example, if that helps.

ColinFay commented 4 years ago

Hey @AlexandraKapp,

This is a known bug that should now be solved in the latest version of golem (git version).

Can you try the following in your app:

remotes::install_github("thinkr-open/golem", force = TRUE)
unlink("tests/testthat/test-golem-recommended.R")
golem::use_recommended_tests()
devtools::check()

Thanks, Colin

AlexandraKapp commented 4 years ago

Thanks for you're help! I do run into the same problem though after following the steps... I also created a fresh test project with the current golem version (0.2.1.9024) and followed the steps.

I tried the folder setup recommended here: https://rstudio.github.io/shinytest/articles/package.html as well as this setup:


└───tests
    │───app.R
    │───shinytest.R
    ├───shinytest
    │   └───my_shiny_test.R
    │   └───my_shiny_test-expected

Anything I might have forgotten?

Cristianetaniguti commented 2 years ago

Hello,

First, thank you so much for developing this great framework. I think I got a solution for this issue. My setup is:

├── DESCRIPTION
├── NAMESPACE
├── R
├── inst
 |   ├── app.R
 |   └── tests/    
 |       ├── shinytest.R
 |       └── shinytest/
 |           ├── mytest.R
 |           └── mytest-expected/
 |              ├── 001.json
 |              └── 001.png
└── tests
    ├── testthat
    │   └── test-shinyTest.R
    └── testthat.R

The shinytest package needs to be included in the Suggests field of the DESCRIPTION file. I don´t know if it is the best way possible, but it is working using devtools::test() and GitHub actions.

king-of-poppk commented 1 year ago

How about testing individual modules?