covr icon indicating copy to clipboard operation
covr copied to clipboard

Coverage For Shiny Applications

Open jimhester opened this issue 7 years ago • 8 comments

jimhester avatar Aug 10 '17 15:08 jimhester

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

CC: @wch

javierluraschi avatar Apr 24 '18 21:04 javierluraschi

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 avatar Apr 25 '18 11:04 jimhester

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!

DavidBreuer avatar Aug 23 '18 14:08 DavidBreuer

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

Ref: https://github.com/rstudio/shinytest/issues/97

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

bedantaguru avatar Jul 28 '19 06:07 bedantaguru

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!

rfaelens avatar Nov 19 '19 13:11 rfaelens

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

bedantaguru avatar Jan 08 '20 07:01 bedantaguru

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

rfaelens avatar Jan 08 '20 11:01 rfaelens

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

bedantaguru avatar Jan 08 '20 11:01 bedantaguru