From 7d53cdf39e250339b678b11f18d9d3014cba2d1b Mon Sep 17 00:00:00 2001 From: Rodrigo Basa Date: Wed, 25 Jan 2023 13:46:56 +0800 Subject: [PATCH 01/21] covr support --- DESCRIPTION | 2 +- NAMESPACE | 2 ++ R/tools.R | 64 ++++++++++++++++++++++++++++++++++++++++++++++ man/covr_r.Rd | 23 +++++++++++++++++ man/covr_report.Rd | 28 ++++++++++++++++++++ 5 files changed, 118 insertions(+), 1 deletion(-) create mode 100644 man/covr_r.Rd create mode 100644 man/covr_report.Rd diff --git a/DESCRIPTION b/DESCRIPTION index c442dc30e..b21865f6c 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: rhino Title: A Framework for Enterprise Shiny Applications -Version: 1.3.0 +Version: 1.3.0.1 Authors@R: c( person("Kamil", "Żyła", role = c("aut", "cre"), email = "opensource+kamil@appsilon.com"), diff --git a/NAMESPACE b/NAMESPACE index f6eb65075..c801696be 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -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) diff --git a/R/tools.R b/R/tools.R index 53baf8b45..02ccb4eb2 100644 --- a/R/tools.R +++ b/R/tools.R @@ -342,3 +342,67 @@ 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() { + rm(list = ls(box:::loaded_mods), envir = box:::loaded_mods) + + 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, ...) +} diff --git a/man/covr_r.Rd b/man/covr_r.Rd new file mode 100644 index 000000000..7676caef4 --- /dev/null +++ b/man/covr_r.Rd @@ -0,0 +1,23 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/tools.R +\name{covr_r} +\alias{covr_r} +\title{Run a test coverage check} +\usage{ +covr_r() +} +\value{ +A \code{covr} coverage dataset. +} +\description{ +Uses the \code{{covr}} package to produce unit test coverage reports. +Uses the \code{{testhat}} package to run all unit tests in \code{tests/testthat} directory. +} +\examples{ +if (interactive()) { + # Run a test coverage check for the entire rhino app + # using all tests in the `tests/testthat` directory. + covr_r() +} + +} diff --git a/man/covr_report.Rd b/man/covr_report.Rd new file mode 100644 index 000000000..a9b619e63 --- /dev/null +++ b/man/covr_report.Rd @@ -0,0 +1,28 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/tools.R +\name{covr_report} +\alias{covr_report} +\title{Display rhino test coverage results using a standalone report} +\usage{ +covr_report(rhino_coverage = covr_r(), ...) +} +\arguments{ +\item{rhino_coverage}{a rhino coverage dataset, a defaults to \code{covr_r()}.} + +\item{...}{additional arguments to pass to +\href{https://covr.r-lib.org/reference/report.html}{\code{covr::report()}}} +} +\value{ +None. This function is called for side effects. +} +\description{ +Uses the \code{{covr}} package to produce unit test coverage reports. +Uses the \code{{testhat}} package to run all unit tests in \code{tests/testthat} directory. +} +\examples{ +if (interactive()) { + # Run a test coverage report on a rhino app + covr_report() +} + +} From 50a3ddb850fbc7b7d085a81a30b748334dbb1fc4 Mon Sep 17 00:00:00 2001 From: Rodrigo Basa Date: Wed, 25 Jan 2023 14:17:26 +0800 Subject: [PATCH 02/21] removed box environment clearing --- R/tools.R | 2 -- 1 file changed, 2 deletions(-) diff --git a/R/tools.R b/R/tools.R index 02ccb4eb2..7ac8559ee 100644 --- a/R/tools.R +++ b/R/tools.R @@ -359,8 +359,6 @@ test_e2e <- function(interactive = FALSE) { #' #' @export covr_r <- function() { - rm(list = ls(box:::loaded_mods), envir = box:::loaded_mods) - withr::with_file("box_loader.R", { module_list <- sub( "__init__", From f25ce9d46485bf1abab79d0943160b6d373a0e87 Mon Sep 17 00:00:00 2001 From: Rodrigo Basa Date: Wed, 25 Jan 2023 16:26:14 +0800 Subject: [PATCH 03/21] version number change as suggested Co-authored-by: Jakub Nowicki --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index b21865f6c..a572c5ba1 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: rhino Title: A Framework for Enterprise Shiny Applications -Version: 1.3.0.1 +Version: 1.3.0.9000 Authors@R: c( person("Kamil", "Żyła", role = c("aut", "cre"), email = "opensource+kamil@appsilon.com"), From fbb3d46b1dbd2f8abf53653e5e12f9785dc82e9a Mon Sep 17 00:00:00 2001 From: Rodrigo Basa Date: Wed, 25 Jan 2023 18:02:17 +0800 Subject: [PATCH 04/21] added filter pattern to list.files for test_files to only get test-????.R files --- DESCRIPTION | 2 +- R/tools.R | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index a572c5ba1..3c28f6d76 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: rhino Title: A Framework for Enterprise Shiny Applications -Version: 1.3.0.9000 +Version: 1.3.0.9001 Authors@R: c( person("Kamil", "Żyła", role = c("aut", "cre"), email = "opensource+kamil@appsilon.com"), diff --git a/R/tools.R b/R/tools.R index 7ac8559ee..11d1d4c55 100644 --- a/R/tools.R +++ b/R/tools.R @@ -377,7 +377,7 @@ covr_r <- function() { coverage <- covr::file_coverage( source_files = "box_loader.R", - test_files = list.files("tests/testthat", full.names = TRUE) + test_files = list.files("tests/testthat", pattern = "^test-.*\\.R", full.names = TRUE) ) }) From 01340248fbd3eab46c8eae6b41b7da559a4551ad Mon Sep 17 00:00:00 2001 From: Rodrigo Basa Date: Wed, 25 Jan 2023 18:25:16 +0800 Subject: [PATCH 05/21] exposed covr::file_coverage parameters --- DESCRIPTION | 2 +- R/tools.R | 13 +++++++++++-- man/covr_r.Rd | 19 ++++++++++++++++--- 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 3c28f6d76..f587cc69b 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: rhino Title: A Framework for Enterprise Shiny Applications -Version: 1.3.0.9001 +Version: 1.3.0.9002 Authors@R: c( person("Kamil", "Żyła", role = c("aut", "cre"), email = "opensource+kamil@appsilon.com"), diff --git a/R/tools.R b/R/tools.R index 11d1d4c55..f86c091ca 100644 --- a/R/tools.R +++ b/R/tools.R @@ -348,6 +348,10 @@ test_e2e <- function(interactive = FALSE) { #' 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-.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 @@ -358,7 +362,10 @@ test_e2e <- function(interactive = FALSE) { #' } #' #' @export -covr_r <- function() { +covr_r <- function( + test_files = list.files("tests/testthat", pattern = "^test-.*\\.R", full.names = TRUE), + line_exclusions = NULL, + function_exclusions = NULL) { withr::with_file("box_loader.R", { module_list <- sub( "__init__", @@ -377,7 +384,9 @@ covr_r <- function() { coverage <- covr::file_coverage( source_files = "box_loader.R", - test_files = list.files("tests/testthat", pattern = "^test-.*\\.R", full.names = TRUE) + test_files = test_files, + line_exclusions = line_exclusions, + function_exclusions = function_exclusions ) }) diff --git a/man/covr_r.Rd b/man/covr_r.Rd index 7676caef4..24239fc20 100644 --- a/man/covr_r.Rd +++ b/man/covr_r.Rd @@ -2,9 +2,22 @@ % Please edit documentation in R/tools.R \name{covr_r} \alias{covr_r} -\title{Run a test coverage check} +\title{Run a covr test coverage check} \usage{ -covr_r() +covr_r( + test_files = list.files("tests/testthat", pattern = "^test-.*\\\\.R", full.names = + TRUE), + line_exclusions = NULL, + function_exclusions = NULL +) +} +\arguments{ +\item{test_files}{Character vector of test files with code to test the functions. Defaults to +all test files in \code{tests/testthat} with the \verb{test-.R} filename pattern.} + +\item{line_exclusions}{passed to \code{covr::file_coverage}} + +\item{function_exclusions}{passed to \code{covr::file_coverage}} } \value{ A \code{covr} coverage dataset. @@ -15,7 +28,7 @@ Uses the \code{{testhat}} package to run all unit tests in \code{tests/testthat} } \examples{ if (interactive()) { - # Run a test coverage check for the entire rhino app + # Run a test coverage check for the entire rhino app # using all tests in the `tests/testthat` directory. covr_r() } From ffceaf912ed74ba53e8de27e657079dc0353a196 Mon Sep 17 00:00:00 2001 From: Rodrigo Basa Date: Wed, 25 Jan 2023 18:57:02 +0800 Subject: [PATCH 06/21] github spell check complained about covr --- R/tools.R | 2 +- man/covr_r.Rd | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/R/tools.R b/R/tools.R index f86c091ca..1d79d88af 100644 --- a/R/tools.R +++ b/R/tools.R @@ -343,7 +343,7 @@ test_e2e <- function(interactive = FALSE) { } } -#' Run a covr test coverage check +#' 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. diff --git a/man/covr_r.Rd b/man/covr_r.Rd index 24239fc20..4c9039352 100644 --- a/man/covr_r.Rd +++ b/man/covr_r.Rd @@ -2,7 +2,7 @@ % Please edit documentation in R/tools.R \name{covr_r} \alias{covr_r} -\title{Run a covr test coverage check} +\title{Run a unit test coverage check} \usage{ covr_r( test_files = list.files("tests/testthat", pattern = "^test-.*\\\\.R", full.names = From 019be637aecb0bccd182a73052e53edf2a35b0e0 Mon Sep 17 00:00:00 2001 From: Rodrigo Basa Date: Fri, 27 Jan 2023 16:03:41 +0800 Subject: [PATCH 07/21] let covr_r search for test files recursively --- DESCRIPTION | 2 +- R/tools.R | 5 ++++- man/covr_r.Rd | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index f587cc69b..409ab736b 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: rhino Title: A Framework for Enterprise Shiny Applications -Version: 1.3.0.9002 +Version: 1.3.0.9003 Authors@R: c( person("Kamil", "Żyła", role = c("aut", "cre"), email = "opensource+kamil@appsilon.com"), diff --git a/R/tools.R b/R/tools.R index 1d79d88af..439382366 100644 --- a/R/tools.R +++ b/R/tools.R @@ -363,7 +363,10 @@ test_e2e <- function(interactive = FALSE) { #' #' @export covr_r <- function( - test_files = list.files("tests/testthat", pattern = "^test-.*\\.R", full.names = TRUE), + test_files = list.files("tests/testthat", + pattern = "^test-.*\\.R", + full.names = TRUE, + recursive = TRUE), line_exclusions = NULL, function_exclusions = NULL) { withr::with_file("box_loader.R", { diff --git a/man/covr_r.Rd b/man/covr_r.Rd index 4c9039352..aba8be0e4 100644 --- a/man/covr_r.Rd +++ b/man/covr_r.Rd @@ -6,7 +6,7 @@ \usage{ covr_r( test_files = list.files("tests/testthat", pattern = "^test-.*\\\\.R", full.names = - TRUE), + TRUE, recursive = TRUE), line_exclusions = NULL, function_exclusions = NULL ) From ec28a9ebfaf68e9bf65e91c3bc1ef43cb65b21f1 Mon Sep 17 00:00:00 2001 From: Rodrigo Basa Date: Fri, 27 Jan 2023 16:12:13 +0800 Subject: [PATCH 08/21] remove extra "a" --- R/tools.R | 2 +- man/covr_report.Rd | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/R/tools.R b/R/tools.R index 439382366..a359dbc08 100644 --- a/R/tools.R +++ b/R/tools.R @@ -401,7 +401,7 @@ covr_r <- function( #' 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 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. diff --git a/man/covr_report.Rd b/man/covr_report.Rd index a9b619e63..d813c2188 100644 --- a/man/covr_report.Rd +++ b/man/covr_report.Rd @@ -7,7 +7,7 @@ covr_report(rhino_coverage = covr_r(), ...) } \arguments{ -\item{rhino_coverage}{a rhino coverage dataset, a defaults to \code{covr_r()}.} +\item{rhino_coverage}{a rhino coverage dataset, defaults to \code{covr_r()}.} \item{...}{additional arguments to pass to \href{https://covr.r-lib.org/reference/report.html}{\code{covr::report()}}} From 5a772e90566a54a5ad98ba70345a8b3e9036148e Mon Sep 17 00:00:00 2001 From: Rodrigo Basa Date: Fri, 3 Feb 2023 18:56:00 +0800 Subject: [PATCH 09/21] add purge_box_cache() before any tests are run to clear the environment of box modules --- R/tools.R | 2 ++ 1 file changed, 2 insertions(+) diff --git a/R/tools.R b/R/tools.R index a359dbc08..fe0e76d4a 100644 --- a/R/tools.R +++ b/R/tools.R @@ -11,6 +11,7 @@ #' } #' @export test_r <- function() { + purge_box_cache() testthat::test_dir(fs::path("tests", "testthat")) } @@ -369,6 +370,7 @@ covr_r <- function( recursive = TRUE), line_exclusions = NULL, function_exclusions = NULL) { + purge_box_cache() withr::with_file("box_loader.R", { module_list <- sub( "__init__", From a335bfaabd5498e47018e0a78dd6c75cc1ccdfdb Mon Sep 17 00:00:00 2001 From: Rodrigo Basa Date: Fri, 3 Feb 2023 19:18:52 +0800 Subject: [PATCH 10/21] rationalize versions --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 409ab736b..8f4703cd9 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: rhino Title: A Framework for Enterprise Shiny Applications -Version: 1.3.0.9003 +Version: 1.3.0.9104 Authors@R: c( person("Kamil", "Żyła", role = c("aut", "cre"), email = "opensource+kamil@appsilon.com"), From 9f3ec62877ed5b0d1ddd2c782a732a14e9a584cd Mon Sep 17 00:00:00 2001 From: Rodrigo Basa Date: Fri, 3 Feb 2023 19:24:53 +0800 Subject: [PATCH 11/21] news entry --- NEWS.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/NEWS.md b/NEWS.md index 9f8e40633..7fc6ec04e 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,7 @@ +# rhino (development version) + +1. Adds `covr` support for `rhino` apps. + # rhino 1.3.0 1. Rhino now works with `shinytest2` out of the box. From 771676cb287c4ab068e2ccf2568c7639ac83e15e Mon Sep 17 00:00:00 2001 From: Rodrigo Basa Date: Mon, 11 May 2026 16:18:30 +0800 Subject: [PATCH 12/21] provide covr support to Rhino apps --- .github/workflows/e2e-test.yml | 1 + DESCRIPTION | 6 ++++-- NEWS.md | 1 + R/tools.R | 15 +++++++------- man/covr_r.Rd | 5 +++++ tests/e2e/test-covr_r.R | 3 +++ tests/testthat/helpers/hello.R | 4 ++++ tests/testthat/helpers/main.R | 32 +++++++++++++++++++++++++++++ tests/testthat/helpers/test-hello.R | 8 ++++++++ tests/testthat/test-tools.R | 31 ++++++++++++++++++++++++++++ 10 files changed, 97 insertions(+), 9 deletions(-) create mode 100644 tests/e2e/test-covr_r.R create mode 100644 tests/testthat/helpers/hello.R create mode 100644 tests/testthat/helpers/main.R create mode 100644 tests/testthat/helpers/test-hello.R diff --git a/.github/workflows/e2e-test.yml b/.github/workflows/e2e-test.yml index 82846d52e..cc10e61fb 100644 --- a/.github/workflows/e2e-test.yml +++ b/.github/workflows/e2e-test.yml @@ -185,6 +185,7 @@ jobs: Rscript -e "rhino::build_sass()" Rscript -e "rhino::build_js()" Rscript -e "rhino::test_r()" + Rscript -e "rhino::covr_r()" - name: Cypress e2e tests should confirm RhinoApp works if: runner.os != 'Windows' diff --git a/DESCRIPTION b/DESCRIPTION index cda222c2c..5b5fb129f 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: rhino Title: A Framework for Enterprise Shiny Applications -Version: 1.11.0.9000 +Version: 1.11.0.9001 Authors@R: c( person("Kamil", "Żyła", role = c("aut", "cre"), email = "opensource+kamil@appsilon.com"), @@ -19,7 +19,6 @@ BugReports: https://github.com/Appsilon/rhino/issues License: LGPL-3 Encoding: UTF-8 Roxygen: list(markdown = TRUE) -RoxygenNote: 7.3.2 Depends: R (>= 2.10) Imports: @@ -45,6 +44,8 @@ Imports: yaml Suggests: covr, + DT, + htmltools, knitr, lifecycle, mockery, @@ -58,3 +59,4 @@ LazyData: true Config/testthat/edition: 3 Config/testthat/parallel: true Language: en-US +Config/roxygen2/version: 8.0.0 diff --git a/NEWS.md b/NEWS.md index 3426f6e00..dd13daf0e 100644 --- a/NEWS.md +++ b/NEWS.md @@ -2,6 +2,7 @@ 1. Added `AGENTS.md` with repository guidance for AI coding agents. 2. Fixed: `main.R` template imports functions in alphabetical order. +3. Added `covr_r()` and `covr_report()` to execute test coverage for Rhino applications using `{covr}`. # [rhino 1.11.0](https://github.com/Appsilon/rhino/releases/tag/v1.11.0) diff --git a/R/tools.R b/R/tools.R index ef2e7f4ce..c8edbc84b 100644 --- a/R/tools.R +++ b/R/tools.R @@ -552,6 +552,8 @@ test_e2e <- function(interactive = FALSE) { #' Uses the `{covr}` package to produce unit test coverage reports. #' Uses the `{testhat}` package to run all unit tests in `tests/testthat` directory. #' +#' @param source_files Character vector of source files with function definitions to measure coverage. +#' Defaults to all `.R` files in the `app` tree. #' @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-.R` filename pattern. #' @param line_exclusions passed to `covr::file_coverage` @@ -567,23 +569,22 @@ test_e2e <- function(interactive = FALSE) { #' #' @export covr_r <- function( + source_files = list.files("app", + pattern = "\\.[rR]$", + full.names = TRUE, + recursive = TRUE), 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) - ), - "," - ) + paste0(tools::file_path_sans_ext(source_files), ",") ) loader_lines <- c("box::use(", module_list, ")") diff --git a/man/covr_r.Rd b/man/covr_r.Rd index aba8be0e4..7a2adf501 100644 --- a/man/covr_r.Rd +++ b/man/covr_r.Rd @@ -5,6 +5,8 @@ \title{Run a unit test coverage check} \usage{ covr_r( + source_files = list.files("app", pattern = "\\\\.[rR]$", full.names = TRUE, recursive = + TRUE), test_files = list.files("tests/testthat", pattern = "^test-.*\\\\.R", full.names = TRUE, recursive = TRUE), line_exclusions = NULL, @@ -12,6 +14,9 @@ covr_r( ) } \arguments{ +\item{source_files}{Character vector of source files with function definitions to measure coverage. +Defaults to all \code{.R} files in the \code{app} tree.} + \item{test_files}{Character vector of test files with code to test the functions. Defaults to all test files in \code{tests/testthat} with the \verb{test-.R} filename pattern.} diff --git a/tests/e2e/test-covr_r.R b/tests/e2e/test-covr_r.R new file mode 100644 index 000000000..f489788f0 --- /dev/null +++ b/tests/e2e/test-covr_r.R @@ -0,0 +1,3 @@ + +expect_no_error(rhino::covr_r()) +expect_no_error(rhino::covr_report()) \ No newline at end of file diff --git a/tests/testthat/helpers/hello.R b/tests/testthat/helpers/hello.R new file mode 100644 index 000000000..dc19f1bb7 --- /dev/null +++ b/tests/testthat/helpers/hello.R @@ -0,0 +1,4 @@ +#' @export +hello <- function() { + "Check out Rhino docs!" +} \ No newline at end of file diff --git a/tests/testthat/helpers/main.R b/tests/testthat/helpers/main.R new file mode 100644 index 000000000..3e4857b8e --- /dev/null +++ b/tests/testthat/helpers/main.R @@ -0,0 +1,32 @@ +box::use( + shiny[NS, bootstrapPage, div, moduleServer, renderUI, tags, uiOutput], +) + +box::use( + app/logic/hello[hello], +) + +#' @export +ui <- function(id) { + ns <- NS(id) + bootstrapPage( + uiOutput(ns("message")) + ) +} + +#' @export +server <- function(id) { + moduleServer(id, function(input, output, session) { + output$message <- renderUI({ + div( + style = "display: flex; justify-content: center; align-items: center; height: 100vh;", + tags$h1( + tags$a( + hello(), + href = "https://appsilon.github.io/rhino/" + ) + ) + ) + }) + }) +} diff --git a/tests/testthat/helpers/test-hello.R b/tests/testthat/helpers/test-hello.R new file mode 100644 index 000000000..17d699b53 --- /dev/null +++ b/tests/testthat/helpers/test-hello.R @@ -0,0 +1,8 @@ +box::use(testthat[describe, expect_identical, it], ) +box::use(app/logic/hello[hello], ) + +describe("hello()", { + it("should return the welcome message", { + expect_identical(hello(), "Check out Rhino docs!") + }) +}) \ No newline at end of file diff --git a/tests/testthat/test-tools.R b/tests/testthat/test-tools.R index c0d1d6c44..2c8c0b136 100644 --- a/tests/testthat/test-tools.R +++ b/tests/testthat/test-tools.R @@ -28,3 +28,34 @@ test_that("build_sass_r builds a minified CSS file out of a Sass file", { ".components-container{display:inline-grid;grid-template-columns:1fr 1fr;width:100%}.components-container .component-box{padding:10px;margin:10px}" # nolint: line_length_linter ) }) + +test_that("covr_r runs a coverage test on a rhino app.", { + wd <- getwd() + + withr::with_tempdir({ + fs::dir_create("app") + fs::dir_create("app", "logic") + fs::dir_create("tests", "testthat") + + fs::file_copy( + fs::path(wd, "helpers", "main.R"), + fs::path("app", "main.R") + ) + + fs::file_copy( + fs::path(wd, "helpers", "hello.R"), + fs::path("app", "logic", "hello.R") + ) + + fs::file_copy( + fs::path(wd, "helpers", "test-hello.R"), + fs::path("tests", "testthat", "test-hello.R") + ) + + box::purge_cache() + configure_box() + + expect_no_error(covr_r()) + expect_no_error(covr_report()) + }) +}) \ No newline at end of file From 414a3508a3418ce33b69129c790b5b427ebbf17d Mon Sep 17 00:00:00 2001 From: Rodrigo Basa Date: Mon, 11 May 2026 16:40:30 +0800 Subject: [PATCH 13/21] lint --- R/tools.R | 8 ++++---- tests/e2e/app-files/main.R | 2 ++ tests/e2e/test-covr_r.R | 2 +- tests/testthat/helpers/hello.R | 2 +- tests/testthat/helpers/main.R | 2 ++ tests/testthat/helpers/test-hello.R | 2 +- tests/testthat/test-tools.R | 14 +++++++------- 7 files changed, 18 insertions(+), 14 deletions(-) diff --git a/R/tools.R b/R/tools.R index c8edbc84b..d09dd0b5a 100644 --- a/R/tools.R +++ b/R/tools.R @@ -552,8 +552,8 @@ test_e2e <- function(interactive = FALSE) { #' Uses the `{covr}` package to produce unit test coverage reports. #' Uses the `{testhat}` package to run all unit tests in `tests/testthat` directory. #' -#' @param source_files Character vector of source files with function definitions to measure coverage. -#' Defaults to all `.R` files in the `app` tree. +#' @param source_files Character vector of source files with function definitions to measure +#' coverage. Defaults to all `.R` files in the `app` tree. #' @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-.R` filename pattern. #' @param line_exclusions passed to `covr::file_coverage` @@ -579,7 +579,7 @@ covr_r <- function( recursive = TRUE), line_exclusions = NULL, function_exclusions = NULL) { - + withr::with_file("box_loader.R", { module_list <- sub( "__init__", @@ -599,7 +599,7 @@ covr_r <- function( ) }) - return(coverage) + coverage } #' Display rhino test coverage results using a standalone report diff --git a/tests/e2e/app-files/main.R b/tests/e2e/app-files/main.R index ce3bd35d8..2572f70cb 100644 --- a/tests/e2e/app-files/main.R +++ b/tests/e2e/app-files/main.R @@ -1,3 +1,4 @@ +# nolint start box::use( rhino[log, react_component], shiny, @@ -23,3 +24,4 @@ server <- function(id) { hello$server("hello") }) } +# nolint end \ No newline at end of file diff --git a/tests/e2e/test-covr_r.R b/tests/e2e/test-covr_r.R index f489788f0..66d04108a 100644 --- a/tests/e2e/test-covr_r.R +++ b/tests/e2e/test-covr_r.R @@ -1,3 +1,3 @@ expect_no_error(rhino::covr_r()) -expect_no_error(rhino::covr_report()) \ No newline at end of file +expect_no_error(rhino::covr_report()) diff --git a/tests/testthat/helpers/hello.R b/tests/testthat/helpers/hello.R index dc19f1bb7..b13875a8c 100644 --- a/tests/testthat/helpers/hello.R +++ b/tests/testthat/helpers/hello.R @@ -1,4 +1,4 @@ #' @export hello <- function() { "Check out Rhino docs!" -} \ No newline at end of file +} diff --git a/tests/testthat/helpers/main.R b/tests/testthat/helpers/main.R index 3e4857b8e..d0dd3e629 100644 --- a/tests/testthat/helpers/main.R +++ b/tests/testthat/helpers/main.R @@ -1,3 +1,4 @@ +# nolint start box::use( shiny[NS, bootstrapPage, div, moduleServer, renderUI, tags, uiOutput], ) @@ -30,3 +31,4 @@ server <- function(id) { }) }) } +# nolint end diff --git a/tests/testthat/helpers/test-hello.R b/tests/testthat/helpers/test-hello.R index 17d699b53..f022913cd 100644 --- a/tests/testthat/helpers/test-hello.R +++ b/tests/testthat/helpers/test-hello.R @@ -5,4 +5,4 @@ describe("hello()", { it("should return the welcome message", { expect_identical(hello(), "Check out Rhino docs!") }) -}) \ No newline at end of file +}) diff --git a/tests/testthat/test-tools.R b/tests/testthat/test-tools.R index 2c8c0b136..26a6dbc52 100644 --- a/tests/testthat/test-tools.R +++ b/tests/testthat/test-tools.R @@ -31,31 +31,31 @@ test_that("build_sass_r builds a minified CSS file out of a Sass file", { test_that("covr_r runs a coverage test on a rhino app.", { wd <- getwd() - + withr::with_tempdir({ fs::dir_create("app") fs::dir_create("app", "logic") fs::dir_create("tests", "testthat") - + fs::file_copy( fs::path(wd, "helpers", "main.R"), fs::path("app", "main.R") ) - + fs::file_copy( fs::path(wd, "helpers", "hello.R"), fs::path("app", "logic", "hello.R") ) - + fs::file_copy( fs::path(wd, "helpers", "test-hello.R"), fs::path("tests", "testthat", "test-hello.R") ) - + box::purge_cache() configure_box() - + expect_no_error(covr_r()) expect_no_error(covr_report()) }) -}) \ No newline at end of file +}) From c056da887427d15a30c238fda6efb7aeabcdc11a Mon Sep 17 00:00:00 2001 From: Rodrigo Basa Date: Mon, 11 May 2026 16:49:48 +0800 Subject: [PATCH 14/21] add covr dependency --- DESCRIPTION | 1 + 1 file changed, 1 insertion(+) diff --git a/DESCRIPTION b/DESCRIPTION index 5b5fb129f..c6ec93005 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -28,6 +28,7 @@ Imports: callr, cli, config, + covr, fs, glue, lintr (>= 3.0.0), From 7b1437636b72c7b333cb2e7a1bb779f0b146916c Mon Sep 17 00:00:00 2001 From: Rodrigo Basa Date: Mon, 11 May 2026 16:53:49 +0800 Subject: [PATCH 15/21] fix package dependency issues --- DESCRIPTION | 3 --- 1 file changed, 3 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index c6ec93005..0ef27d52f 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -44,9 +44,6 @@ Imports: withr, yaml Suggests: - covr, - DT, - htmltools, knitr, lifecycle, mockery, From 829e27b58b474d1320085e0d0e4744785ae9395f Mon Sep 17 00:00:00 2001 From: Rodrigo Basa Date: Mon, 11 May 2026 16:56:03 +0800 Subject: [PATCH 16/21] more package dependecy issues --- DESCRIPTION | 2 ++ 1 file changed, 2 insertions(+) diff --git a/DESCRIPTION b/DESCRIPTION index 0ef27d52f..650f99211 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -29,8 +29,10 @@ Imports: cli, config, covr, + DT, fs, glue, + htmltools, lintr (>= 3.0.0), logger, purrr, From 08cb4ffc7d3df503f2c8150f96d34a8a3b23dafa Mon Sep 17 00:00:00 2001 From: Rodrigo Basa Date: Mon, 11 May 2026 17:00:59 +0800 Subject: [PATCH 17/21] package dependency fix again --- DESCRIPTION | 4 ++-- man/covr_r.Rd | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 650f99211..2dafdeedd 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -29,10 +29,8 @@ Imports: cli, config, covr, - DT, fs, glue, - htmltools, lintr (>= 3.0.0), logger, purrr, @@ -46,6 +44,8 @@ Imports: withr, yaml Suggests: + DT, + htmltools, knitr, lifecycle, mockery, diff --git a/man/covr_r.Rd b/man/covr_r.Rd index 7a2adf501..50deecefe 100644 --- a/man/covr_r.Rd +++ b/man/covr_r.Rd @@ -14,8 +14,8 @@ covr_r( ) } \arguments{ -\item{source_files}{Character vector of source files with function definitions to measure coverage. -Defaults to all \code{.R} files in the \code{app} tree.} +\item{source_files}{Character vector of source files with function definitions to measure +coverage. Defaults to all \code{.R} files in the \code{app} tree.} \item{test_files}{Character vector of test files with code to test the functions. Defaults to all test files in \code{tests/testthat} with the \verb{test-.R} filename pattern.} From 8b0c4f60ce9b3eb5c93487777b829227ac67e23e Mon Sep 17 00:00:00 2001 From: Rodrigo Basa Date: Mon, 11 May 2026 17:32:04 +0800 Subject: [PATCH 18/21] try test coverage only on ubuntu-release --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6cc041a8b..95474afb3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -67,7 +67,7 @@ jobs: quit(status = warnings_found) - name: Test coverage - if: always() + if: ${{ always() && matrix.os == 'ubuntu-24.04' && matrix.r == 'release' }} env: CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} shell: Rscript {0} From bc5f6aeb5e722d40117c44f640cc6b5a40caf6a1 Mon Sep 17 00:00:00 2001 From: Rodrigo Basa Date: Mon, 11 May 2026 17:37:48 +0800 Subject: [PATCH 19/21] fix a step conditional --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 95474afb3..982c2a40f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -67,7 +67,7 @@ jobs: quit(status = warnings_found) - name: Test coverage - if: ${{ always() && matrix.os == 'ubuntu-24.04' && matrix.r == 'release' }} + if: ${{ always() && matrix.config.os == 'ubuntu-24.04' && matrix.config.r == 'release' }} env: CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} shell: Rscript {0} From e31dc54477cca941673802c701ef8eb1f0b85775 Mon Sep 17 00:00:00 2001 From: Rodrigo Basa Date: Mon, 11 May 2026 17:42:49 +0800 Subject: [PATCH 20/21] skip covr test on covr run --- tests/testthat/test-tools.R | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/testthat/test-tools.R b/tests/testthat/test-tools.R index 26a6dbc52..ead17ccff 100644 --- a/tests/testthat/test-tools.R +++ b/tests/testthat/test-tools.R @@ -30,6 +30,7 @@ test_that("build_sass_r builds a minified CSS file out of a Sass file", { }) test_that("covr_r runs a coverage test on a rhino app.", { + skip_on_covr() wd <- getwd() withr::with_tempdir({ From d03964ab68ff6810bf9194bd542fe2476ed2c32e Mon Sep 17 00:00:00 2001 From: Rodrigo Basa Date: Mon, 11 May 2026 17:53:42 +0800 Subject: [PATCH 21/21] revert ci to existing. add covr minimum version --- .github/workflows/ci.yml | 2 +- DESCRIPTION | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 982c2a40f..6cc041a8b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -67,7 +67,7 @@ jobs: quit(status = warnings_found) - name: Test coverage - if: ${{ always() && matrix.config.os == 'ubuntu-24.04' && matrix.config.r == 'release' }} + if: always() env: CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} shell: Rscript {0} diff --git a/DESCRIPTION b/DESCRIPTION index 2dafdeedd..dc78e613d 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -28,7 +28,7 @@ Imports: callr, cli, config, - covr, + covr (>= 3.6.5), fs, glue, lintr (>= 3.0.0),