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

Test coverage using covr #431

Draft
wants to merge 14 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: rhino
Title: A Framework for Enterprise Shiny Applications
Version: 1.3.0
Version: 1.3.0.1
radbasa marked this conversation as resolved.
Show resolved Hide resolved
Authors@R:
c(
person("Kamil", "Żyła", role = c("aut", "cre"), email = "opensource+kamil@appsilon.com"),
Expand Down
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
export(app)
export(build_js)
export(build_sass)
export(covr_r)
export(covr_report)
export(diagnostics)
export(format_r)
export(init)
Expand Down
62 changes: 62 additions & 0 deletions R/tools.R
Original file line number Diff line number Diff line change
Expand Up @@ -342,3 +342,65 @@ test_e2e <- function(interactive = FALSE) {
npm("run", "test-e2e")
}
}

#' Run a covr test coverage check
#'
#' Uses the `{covr}` package to produce unit test coverage reports.
#' Uses the `{testhat}` package to run all unit tests in `tests/testthat` directory.
#'
#' @return A `covr` coverage dataset.
#'
#' @examples
#' if (interactive()) {
#' # Run a test coverage check for the entire rhino app
#' # using all tests in the `tests/testthat` directory.
#' covr_r()
#' }
#'
#' @export
covr_r <- function() {
withr::with_file("box_loader.R", {
module_list <- sub(
"__init__",
"`__init__`",
paste0(
tools::file_path_sans_ext(
list.files("app", pattern = "\\.[rR]$", full.names = TRUE, recursive = TRUE)
),
","
)
)

loader_lines <- c("box::use(", module_list, ")")

writeLines(loader_lines, "box_loader.R")

coverage <- covr::file_coverage(
source_files = "box_loader.R",
test_files = list.files("tests/testthat", full.names = TRUE)
)
})

return(coverage)
}

#' Display rhino test coverage results using a standalone report
#'
#' Uses the `{covr}` package to produce unit test coverage reports.
#' Uses the `{testhat}` package to run all unit tests in `tests/testthat` directory.
#'
#' @param rhino_coverage a rhino coverage dataset, a defaults to `covr_r()`.
#' @param ... additional arguments to pass to
#' [`covr::report()`](https://covr.r-lib.org/reference/report.html)
#' @return None. This function is called for side effects.
#'
#' @examples
#' if (interactive()) {
#' # Run a test coverage report on a rhino app
#' covr_report()
#' }
#'
#' @export
covr_report <- function(rhino_coverage = covr_r(), ...) {
covr::report(x = rhino_coverage, ...)
}
23 changes: 23 additions & 0 deletions man/covr_r.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions man/covr_report.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.