Skip to content

Commit

Permalink
Test that articles are built reproducible by default
Browse files Browse the repository at this point in the history
  • Loading branch information
salim-b committed Mar 12, 2024
1 parent 595b41f commit 841d6d6
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 1 deletion.
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ Suggests:
rsconnect,
rstudioapi,
rticles,
rvest,
sass,
testthat (>= 3.1.3),
tools
Expand Down
7 changes: 7 additions & 0 deletions tests/testthat/_snaps/build-articles.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,10 @@
Reading vignettes/html-deps.Rmd
Writing articles/html-deps.html

# output is reproducible by default, i.e. 'seed' is respected

Code
cat(output)
Output
## [1] 0.080750138 0.834333037 0.600760886 0.157208442 0.007399441

7 changes: 7 additions & 0 deletions tests/testthat/assets/articles/vignettes/random.Rmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
title: "Random"
---

```{r, repro}
runif(5L)
```
13 changes: 13 additions & 0 deletions tests/testthat/test-build-articles.R
Original file line number Diff line number Diff line change
Expand Up @@ -215,3 +215,16 @@ test_that("check doesn't include getting started vignette", {

expect_error(data_articles_index(pkg), NA)
})

test_that("output is reproducible by default, i.e. 'seed' is respected", {
pkg <- local_pkgdown_site(test_path("assets/articles"))
suppressMessages(build_article(pkg = pkg, name = "random"))

output <- xml2::read_html(file.path(pkg$dst_path, "articles/random.html")) %>%
rvest::html_node("div.contents > pre") %>%
rvest::html_text() %>%
# replace line feeds with whitespace to make output platform independent
gsub("\r", "", .)

expect_snapshot(cat(output))
})
2 changes: 1 addition & 1 deletion tests/testthat/test-check.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ test_that("fails if article index incomplete", {
pkg <- local_pkgdown_site(test_path("assets/articles"), meta = "
articles:
- title: Title
contents: [starts_with('html'), standard, toc-false, widget]
contents: [starts_with('html'), random, standard, toc-false, widget]
")
expect_snapshot(check_pkgdown(pkg), error = TRUE)
})
Expand Down

0 comments on commit 841d6d6

Please sign in to comment.