Skip to content

Commit 2f3fa16

Browse files
committed
tests - make theme tests run locally
1 parent 6c13f0c commit 2f3fa16

File tree

2 files changed

+55
-32
lines changed

2 files changed

+55
-32
lines changed

tests/testthat/helper.R

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,13 @@ local_quarto_project <- function(
9191
return(file.path(path_tmp, name))
9292
}
9393

94-
.render <- function(input, output_file = NULL, ..., .env = parent.frame()) {
94+
.render <- function(
95+
input,
96+
output_file = NULL,
97+
...,
98+
.quiet = TRUE,
99+
.env = parent.frame()
100+
) {
95101
skip_if_no_quarto()
96102
skip_if_not_installed("withr")
97103
# work inside input directory
@@ -102,7 +108,12 @@ local_quarto_project <- function(
102108
.local_envir = .env
103109
))
104110
}
105-
quarto_render(basename(input), output_file = output_file, quiet = TRUE, ...)
111+
expect_no_error(quarto_render(
112+
basename(input),
113+
output_file = output_file,
114+
quiet = .quiet,
115+
...
116+
))
106117
expect_true(file.exists(output_file))
107118
normalizePath(output_file)
108119
}
@@ -207,3 +218,32 @@ local_quarto_run_echo_cmd <- function(.env = parent.frame()) {
207218
withr::local_options(quarto.echo_cmd = TRUE, .local_envir = .env)
208219
}
209220
}
221+
222+
quick_install <- function(package, lib, quiet = TRUE) {
223+
opts <- c(
224+
"--data-compress=none",
225+
"--no-byte-compile",
226+
"--no-data",
227+
"--no-demo",
228+
"--no-docs",
229+
"--no-help",
230+
"--no-html",
231+
"--no-libs",
232+
"--use-vanilla",
233+
sprintf("--library=%s", lib),
234+
package
235+
)
236+
invisible(callr::rcmd("INSTALL", opts, show = !quiet, fail_on_status = TRUE))
237+
}
238+
239+
install_dev_package <- function(.local_envir = parent.frame()) {
240+
# if not inside of R CMD check, install dev version into temp directory
241+
if (Sys.getenv("_R_CHECK_TIMINGS_") == "") {
242+
withr::local_temp_libpaths(.local_envir = .local_envir)
243+
quick_install(pkgload::pkg_path("."), lib = .libPaths()[1])
244+
withr::local_envvar(
245+
R_LIBS = paste0(.libPaths(), collapse = .Platform$path.sep),
246+
.local_envir = .local_envir
247+
)
248+
}
249+
}

tests/testthat/test-theme.R

Lines changed: 13 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,31 @@
1+
# don't run on CRAN - this require installed Quarto version with the right version of the quarto package.
2+
skip_on_cran()
3+
skip_if_no_quarto()
4+
skip_if_not_installed("withr")
5+
6+
# We need to install the package in a temporary library when we are in dev mode
7+
install_dev_package()
18

29
test_that("render flextable", {
3-
skip_if_no_quarto()
4-
quarto_render("theme/flextable.qmd", quiet = TRUE)
5-
expect_true(file.exists("theme/flextable.html"))
6-
unlink("theme/flextable.html")
10+
.render(test_path("theme/flextable.qmd"))
711
})
812

9-
1013
test_that("render ggiraph", {
11-
skip_if_no_quarto()
12-
quarto_render("theme/ggiraph.qmd", quiet = TRUE)
13-
expect_true(file.exists("theme/ggiraph.html"))
14-
unlink("theme/ggiraph.html")
14+
.render(test_path("theme/ggiraph.qmd"))
1515
})
1616

17-
1817
test_that("render ggplot", {
19-
skip_if_no_quarto()
20-
quarto_render("theme/ggplot.qmd", quiet = TRUE)
21-
expect_true(file.exists("theme/ggplot.html"))
22-
unlink("theme/ggplot.html")
18+
.render(test_path("theme/ggplot.qmd"))
2319
})
2420

25-
2621
test_that("render gt", {
27-
skip_if_no_quarto()
28-
quarto_render("theme/gt.qmd", quiet = TRUE)
29-
expect_true(file.exists("theme/gt.html"))
30-
unlink("theme/gt.html")
22+
.render(test_path("theme/gt.qmd"))
3123
})
3224

33-
3425
test_that("render plotly-r", {
35-
skip_if_no_quarto()
36-
quarto_render("theme/plotly-r.qmd", quiet = TRUE)
37-
expect_true(file.exists("theme/plotly-r.html"))
38-
unlink("theme/plotly-r.html")
26+
.render(test_path("theme/plotly-r.qmd"))
3927
})
4028

41-
4229
test_that("render thematic", {
43-
skip_if_no_quarto()
44-
quarto_render("theme/thematic.qmd", quiet = TRUE)
45-
expect_true(file.exists("theme/thematic.html"))
46-
unlink("theme/thematic.html")
30+
.render(test_path("theme/thematic.qmd"))
4731
})
48-

0 commit comments

Comments
 (0)