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

Coverage For Shiny Applications #277

Open
jimhester opened this issue Aug 10, 2017 · 8 comments
Open

Coverage For Shiny Applications #277

jimhester opened this issue Aug 10, 2017 · 8 comments
Labels
feature a feature request or enhancement

Comments

@jimhester
Copy link
Member

No description provided.

@javierluraschi
Copy link

https://github.com/rstudio/shinytest makes this feature request more compelling, I think.

CC: @wch

@jimhester
Copy link
Member Author

I actually worked on this at the work week in May / June last year and had a simple proof of concept, it requires fairly small changes to covr and shiny test.

https://github.com/r-lib/covr/compare/shiny-app?expand=1
https://github.com/rstudio/shinytest/compare/master...jimhester:covr?expand=1

I didn't proceed further because it didn't seem like there was a terrible amount of interest.

If we want this it should not be a great deal of work, happy to do what is needed.

@jimhester jimhester added feature a feature request or enhancement and removed enhancement feature a feature request or enhancement labels May 17, 2018
@DavidBreuer
Copy link

Hi, the combination of covr and shinytests seems very valuable to me! It's a pity to write nice shinytests which do not add to the "visible" test coverage... :)

Unfortunately, I wasn't able to transfer this proof of concept to the most recent version of shinytest (1.3.0). But if you can give me some hints or adjust the shinytest 1.3.0 initialize.R code I'm happy to test or extend this proof of concept. Thanks and best!

rfaelens added a commit to tdmore-dev/tdmore that referenced this issue Jun 13, 2019
@bedantaguru
Copy link

bedantaguru commented Jul 28, 2019

Is there any update on this. This will be a great functionality.

Ref: rstudio/shinytest#97

This will helpful for tracking code coverage for packages with shiny modules.

@rfaelens
Copy link

There is a difference between instrumenting code coverage for a package and for a seperate shiny app.

If you use a package where the shiny app is fully contained in source code in the package itself, e.g.

<R/shinyApp.R>
#' @export
myShinyApp <- function() {
    shiny::shinyApp(ui=ui, server=server)
}

then the package_coverage() function will correctly install the package in a temporary directory and set up tracing appropriately. You can set up shinytest as follows:

<tests/testApp.R>
shinytest::testApp(appDir="tests/testApp")
<tests/testApp/app.R>
myShinyApp()
<tests/testApp/tests/test.R>
app <- ShinyDriver$new("..", loadTimeout = 30000, seed=1234)
app$snapshotInit("full-test")
## execute test actions

## Interrupt shinyProcess so covr::save_trace can execute onExit
p <- app$.__enclos_env__$private$shinyProcess
p$interrupt()
p$wait()

Hope this helps others!

@bedantaguru
Copy link

@rfaelens do you have an example package for this. Let me try to re-create it and see.

@rfaelens
Copy link

rfaelens commented Jan 8, 2020

See https://github.com/rfaelens/exampleShinyTest for a nice example.
Travis: https://travis-ci.com/rfaelens/exampleShinyTest
Codecov: https://codecov.io/gh/rfaelens/exampleShinyTest
Docker: https://hub.docker.com/r/rfaelens/exampleshinytest

@bedantaguru
Copy link

Great.
Working like a charm
Thanks a lot @rfaelens

Here is also my quick take :
https://github.com/bedantaguru/covrChecks
(if it helps others)

I adopted testthat folder structure

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature a feature request or enhancement
Projects
None yet
Development

No branches or pull requests

5 participants