Skip to content

Commit 4e82184

Browse files
authored
correctly clean up the theme file test rendering (#254)
1 parent fe87303 commit 4e82184

File tree

1 file changed

+46
-6
lines changed

1 file changed

+46
-6
lines changed

tests/testthat/test-theme.R

Lines changed: 46 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,38 +6,78 @@ skip_if_not_installed("withr")
66
# We need to install the package in a temporary library when we are in dev mode
77
install_dev_package()
88

9+
theme_file <- function(...) {
10+
test_path("theme", ...)
11+
}
12+
13+
resource_dir <- function(input) {
14+
theme_file(
15+
paste0(fs::path_ext_remove(basename(input)), "_files")
16+
)
17+
}
18+
19+
local_render_theme_file <- function(input, env = parent.frame()) {
20+
skip_if_not_installed("withr")
21+
withr::defer(
22+
{
23+
# clean up output resource directory
24+
out_dir <- resource_dir(input)
25+
if (fs::dir_exists(out_dir)) {
26+
fs::dir_delete(out_dir)
27+
}
28+
# clean up internal .quarto directory
29+
if (fs::dir_exists(".quarto")) {
30+
fs::dir_delete(".quarto")
31+
}
32+
},
33+
envir = env
34+
)
35+
}
36+
937
test_that("render flextable", {
1038
skip_if_not_installed("bslib")
1139
skip_if_not_installed("flextable")
12-
.render(test_path("theme/flextable.qmd"))
40+
file <- theme_file("flextable.qmd")
41+
local_render_theme_file(file)
42+
.render(file)
1343
})
1444

1545
test_that("render ggiraph", {
1646
skip_if_not_installed("bslib")
1747
skip_if_not_installed("ggiraph")
18-
.render(test_path("theme/ggiraph.qmd"))
48+
file <- theme_file("ggiraph.qmd")
49+
local_render_theme_file(file)
50+
.render(file)
1951
})
2052

2153
test_that("render ggplot2", {
2254
skip_if_not_installed("bslib")
2355
skip_if_not_installed("ggplot2")
24-
.render(test_path("theme/ggplot2.qmd"))
56+
file <- theme_file("ggplot2.qmd")
57+
local_render_theme_file(file)
58+
.render(test_path(file))
2559
})
2660

2761
test_that("render gt", {
2862
skip_if_not_installed("bslib")
2963
skip_if_not_installed("gt")
30-
.render(test_path("theme/gt.qmd"))
64+
file <- theme_file("gt.qmd")
65+
local_render_theme_file(file)
66+
.render(file)
3167
})
3268

3369
test_that("render plotly-r", {
3470
skip_if_not_installed("bslib")
3571
skip_if_not_installed("plotly")
36-
.render(test_path("theme/plotly-r.qmd"))
72+
file <- theme_file("plotly-r.qmd")
73+
local_render_theme_file(file)
74+
.render(file)
3775
})
3876

3977
test_that("render thematic", {
4078
skip_if_not_installed("bslib")
4179
skip_if_not_installed("thematic")
42-
.render(test_path("theme/thematic.qmd"))
80+
file <- theme_file("thematic.qmd")
81+
local_render_theme_file(file)
82+
.render(file)
4383
})

0 commit comments

Comments
 (0)