tests/testthat/test-themes.R

test_theme <- function(theme) {
  test_that(paste(theme, "theme"), {
    skip_if_not_pandoc()
    # don't run on cran because this is just to test after updates
    skip_on_cran()

    # work in a temp directory
    dir <- tempfile()
    dir.create(dir)
    oldwd <- setwd(dir)
    on.exit(setwd(oldwd), add = TRUE)

    # create a draft of a presentation
    testdoc <- "testdoc.Rmd"
    rmarkdown::draft(
      testdoc,
      system.file(
        "rmarkdown",
        "templates",
        "revealjs_presentation",
        package = "revealjs"
      ),
      create_dir = FALSE,
      edit = FALSE
    )

    # render it with the specified theme
    capture.output({
      output_file <- tempfile(fileext = ".html")
      output_format <- revealjs_presentation(theme = theme)
      rmarkdown::render(
        testdoc,
        output_format = output_format,
        output_file = output_file,
        quiet = TRUE
      )
      expect_true(file.exists(output_file))
    })
  })
}

# test all themes
sapply(revealjs:::revealjs_themes(), test_theme)

Try the revealjs package in your browser

Any scripts or data that you put into this service are public.

revealjs documentation built on April 3, 2025, 10:53 p.m.