covr
covr copied to clipboard
Coverage For Shiny Applications
https://github.com/rstudio/shinytest makes this feature request more compelling, I think.
CC: @wch
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.
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!
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.
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 do you have an example package for this. Let me try to re-create it and see.
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
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