Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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.9000
Version: 1.3.0.9104
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
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# rhino (development version)

1. Adds `covr` support for `rhino` apps.

# [rhino 1.3.0](https://github.com/Appsilon/rhino/releases/tag/v1.3.0)

1. Rhino now works with `shinytest2` out of the box.
Expand Down
76 changes: 76 additions & 0 deletions R/tools.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#' }
#' @export
test_r <- function() {
purge_box_cache()
testthat::test_dir(fs::path("tests", "testthat"))
}

Expand Down Expand Up @@ -342,3 +343,78 @@ test_e2e <- function(interactive = FALSE) {
npm("run", "test-e2e")
}
}

#' Run a unit 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.
#'
#' @param test_files Character vector of test files with code to test the functions. Defaults to
#' all test files in `tests/testthat` with the `test-<name>.R` filename pattern.
#' @param line_exclusions passed to `covr::file_coverage`
#' @param function_exclusions passed to `covr::file_coverage`
#' @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(
test_files = list.files("tests/testthat",
pattern = "^test-.*\\.R",
full.names = TRUE,
recursive = TRUE),
line_exclusions = NULL,
function_exclusions = NULL) {
purge_box_cache()
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 = test_files,
line_exclusions = line_exclusions,
function_exclusions = function_exclusions
)
})

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, 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, ...)
}
36 changes: 36 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.