Debian Codegraph @

tests/testthat/test-test-shinyAppTemplate.R

raw
1 # testthat::skip_on_cran()
2 suppressWarnings(testthat::skip_if_not_installed("shinytest2"))
3 testthat::skip("Refactor test for next release")
4
5 # test all combos
6 make_combos <- function(...) {
7 args <- list(...)
8 combo_dt <- do.call(expand.grid, args)
9 lapply(apply(combo_dt, 1, unlist), unname)
10 }
11
12 combos <- unique(unlist(
13 recursive = FALSE,
14 list(
15 "all",
16 # expand.grid on all combos
17 make_combos("app", list(NULL, "module"), list(NULL, "rdir"), list(NULL, "tests")),
18 # Legacy values
19 list(list("app", "shinytest", "testthat"))
20 )
21 ))
22
23 for (combo in combos) {
24 combo_name <- paste0(combo, collapse = "_")
25 test_that(paste0("app template works with runTests: ", combo_name), {
26 random_folder <- paste0("shinyAppTemplate-", combo_name)
27 tempTemplateDir <- file.path(tempfile(), random_folder)
28 suppressMessages(shinyAppTemplate(tempTemplateDir, combo))
29 on.exit(unlink(tempTemplateDir, recursive = TRUE), add = TRUE)
30
31 if (any(c("all", "tests", "shinytest", "testthat") %in% combo)) {
32 suppressMessages(capture.output({
33 out <- runTests(tempTemplateDir, assert = FALSE)
34 }))
35 expect_snapshot(out)
36 } else {
37 expect_error(
38 suppressMessages(runTests(tempTemplateDir))
39 )
40 }
41 })
42 }