Skip to content

Commit 9fa5a74

Browse files
committed
use .render in test to clean correctly
1 parent d2bc824 commit 9fa5a74

File tree

3 files changed

+15
-16
lines changed

3 files changed

+15
-16
lines changed

tests/testthat/helpers.R

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,6 @@ local_quarto_project <- function(
115115
"--output",
116116
output_file_forced
117117
)
118-
} else {
119-
NULL
120118
}
121119
expect_no_error(quarto_render(
122120
basename(input),
@@ -126,6 +124,12 @@ local_quarto_project <- function(
126124
...
127125
))
128126
out <- output_file %||% output_file_forced
127+
withr::defer(
128+
if (file.exists(out)) {
129+
unlink(out)
130+
},
131+
envir = .env
132+
)
129133
expect_true(file.exists(out))
130134
normalizePath(out)
131135
}
@@ -317,7 +321,7 @@ local_clean_state <- function(env = parent.frame()) {
317321
)
318322
}
319323

320-
local_clean_dot_quarto <- function(where = ".", env = parent.frame()) {
324+
local_clean_dot_quarto <- function(where = ".", .env = parent.frame()) {
321325
skip_if_not_installed("withr")
322326
skip_if_not_installed("fs")
323327
withr::defer(
@@ -328,7 +332,7 @@ local_clean_dot_quarto <- function(where = ".", env = parent.frame()) {
328332
fs::dir_delete(dot_quarto)
329333
}
330334
},
331-
envir = env
335+
envir = .env
332336
)
333337
}
334338

tests/testthat/test-theme.R

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ resource_dir <- function(input) {
1616
)
1717
}
1818

19-
local_render_theme_file <- function(input, env = parent.frame()) {
19+
local_render_theme_file <- function(input, .env = parent.frame()) {
2020
skip_if_not_installed("withr")
2121
skip_if_not_installed("fs")
22-
local_clean_dot_quarto(where = dirname(input), env = env)
22+
local_clean_dot_quarto(where = dirname(input), .env = .env)
2323
withr::defer(
2424
{
2525
# clean up output resource directory
@@ -28,54 +28,49 @@ local_render_theme_file <- function(input, env = parent.frame()) {
2828
fs::dir_delete(out_dir)
2929
}
3030
},
31-
envir = env
31+
envir = .env
3232
)
33+
.render(input, .env = .env)
3334
}
3435

3536
test_that("render flextable", {
3637
skip_if_not_installed("bslib")
3738
skip_if_not_installed("flextable")
3839
file <- theme_file("flextable.qmd")
3940
local_render_theme_file(file)
40-
.render(file)
4141
})
4242

4343
test_that("render ggiraph", {
4444
skip_if_not_installed("bslib")
4545
skip_if_not_installed("ggiraph")
4646
file <- theme_file("ggiraph.qmd")
4747
local_render_theme_file(file)
48-
.render(file)
4948
})
5049

5150
test_that("render ggplot2", {
5251
skip_if_not_installed("bslib")
5352
skip_if_not_installed("ggplot2")
5453
file <- theme_file("ggplot2.qmd")
5554
local_render_theme_file(file)
56-
.render(test_path(file))
5755
})
5856

5957
test_that("render gt", {
6058
skip_if_not_installed("bslib")
6159
skip_if_not_installed("gt")
6260
file <- theme_file("gt.qmd")
6361
local_render_theme_file(file)
64-
.render(file)
6562
})
6663

6764
test_that("render plotly-r", {
6865
skip_if_not_installed("bslib")
6966
skip_if_not_installed("plotly")
7067
file <- theme_file("plotly-r.qmd")
7168
local_render_theme_file(file)
72-
.render(file)
7369
})
7470

7571
test_that("render thematic", {
7672
skip_if_not_installed("bslib")
7773
skip_if_not_installed("thematic")
7874
file <- theme_file("thematic.qmd")
7975
local_render_theme_file(file)
80-
.render(file)
8176
})

tests/testthat/test-utils-extract.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ test_that("qmd_to_r_script() writes R file that renders", {
3434
skip_if_no_quarto("1.4.511")
3535
announce_snapshot_file(name = "purl.md")
3636
md_file <- xfun::with_ext(r_script, "md")
37-
quarto::quarto_render(
37+
.render(
3838
r_script,
39-
output_format = "markdown",
4039
output_file = basename(md_file),
41-
quiet = TRUE
40+
output_format = "markdown",
41+
.quiet = TRUE
4242
)
4343
expect_snapshot_file(
4444
path = md_file,

0 commit comments

Comments
 (0)