Skip to content

Commit a84a959

Browse files
committed
Test that articles are built reproducible by default
1 parent 595b41f commit a84a959

File tree

4 files changed

+28
-1
lines changed

4 files changed

+28
-1
lines changed

Diff for: tests/testthat/_snaps/build-articles.md

+7
Original file line numberDiff line numberDiff line change
@@ -121,3 +121,10 @@
121121
Reading vignettes/html-deps.Rmd
122122
Writing articles/html-deps.html
123123

124+
# output is reproducible by default, i.e. 'seed' is respected
125+
126+
Code
127+
cat(output)
128+
Output
129+
## [1] 0.080750138 0.834333037 0.600760886 0.157208442 0.007399441
130+

Diff for: tests/testthat/assets/articles/vignettes/random.Rmd

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
title: "Random"
3+
---
4+
5+
```{r, repro}
6+
runif(5L)
7+
```

Diff for: tests/testthat/test-build-articles.R

+13
Original file line numberDiff line numberDiff line change
@@ -215,3 +215,16 @@ test_that("check doesn't include getting started vignette", {
215215

216216
expect_error(data_articles_index(pkg), NA)
217217
})
218+
219+
test_that("output is reproducible by default, i.e. 'seed' is respected", {
220+
pkg <- local_pkgdown_site(test_path("assets/articles"))
221+
suppressMessages(build_article(pkg = pkg, name = "random"))
222+
223+
output <- xml2::read_html(file.path(pkg$dst_path, "articles/random.html")) %>%
224+
rvest::html_node("div.contents > pre") %>%
225+
rvest::html_text() %>%
226+
# replace line feeds with whitespace to make output platform independent
227+
gsub("\r", "", .)
228+
229+
expect_snapshot(cat(output))
230+
})

Diff for: tests/testthat/test-check.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ test_that("fails if article index incomplete", {
1414
pkg <- local_pkgdown_site(test_path("assets/articles"), meta = "
1515
articles:
1616
- title: Title
17-
contents: [starts_with('html'), standard, toc-false, widget]
17+
contents: [starts_with('html'), random, standard, toc-false, widget]
1818
")
1919
expect_snapshot(check_pkgdown(pkg), error = TRUE)
2020
})

0 commit comments

Comments
 (0)