From c09c05d1701528ff88a18b7d9f88a0ae322861d3 Mon Sep 17 00:00:00 2001 From: Carson Date: Mon, 1 Feb 2021 16:32:22 -0600 Subject: [PATCH] Try running shinytest tests in background process; update testing dependencies --- .github/workflows/R-CMD-check.yaml | 4 +- tests/testthat/test-shinytest.R | 209 +++++++++++++++-------------- 2 files changed, 111 insertions(+), 102 deletions(-) diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index 4ab6a396..86d5eb5f 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -121,8 +121,8 @@ jobs: - name: Install testing dependencies run: | # TODO: remove me after next release cycle - remotes::install_github(c('rstudio/rmarkdown#1706', 'rstudio/bslib', 'yixuan/showtext')) - install.packages(c('shinytest', 'sf', 'ggthemes', 'patchwork', 'gridExtra', 'tinytex')) + remotes::install_github('rstudio/rmarkdown') + install.packages(c('shinytest', 'callr', 'sf', 'ggthemes', 'patchwork', 'gridExtra', 'tinytex')) tinytex::install_tinytex() shell: Rscript {0} diff --git a/tests/testthat/test-shinytest.R b/tests/testthat/test-shinytest.R index 31ced09d..fd62d082 100644 --- a/tests/testthat/test-shinytest.R +++ b/tests/testthat/test-shinytest.R @@ -1,100 +1,109 @@ -# context("shinytest") -# -# skip_on_cran() -# skip_if_not_installed("shinytest") -# skip_if_not_installed("ggplot2") -# skip_if_not_installed("lattice") -# # Run tests on release version of R -# skip_if_not(as.logical(Sys.getenv("SHINYTEST_RUN_TESTS", "true"))) -# -# -# # a la shinycoreci:::platform() -# shinytest_suffix <- function() { -# if (.Platform$OS.type == "windows") { -# return("win") -# } -# sys <- Sys.info()[["sysname"]] -# if (sys == "Darwin") { -# return("mac") -# } -# if (sys == "Linux") { -# return("linux") -# } -# stop("unknown platform") -# } -# -# expect_app_doppelganger <- function(appDir) { -# expect_pass <- getFromNamespace("expect_pass", "shinytest") -# testApp <- getFromNamespace("testApp", "shinytest") -# expect_pass(testApp(appDir, suffix = shinytest_suffix())) -# } -# -# -# test_that("Custom fonts with ragg", { -# skip_if_not_installed("ragg") -# expect_app_doppelganger("agg_png") -# }) -# -# test_that("runtime: shiny auto-theming", { -# skip_if_not(identical("win", shinytest_suffix())) -# expect_app_doppelganger("shiny_runtime") -# }) -# -# # The remaining tests rely on showtext to render custom fonts -# skip_if_not_installed("showtext") -# -# test_that("Auto theming in shiny works", { -# # These shiny apps currently use remote urls to import Google fonts -# skip_if_offline() -# skip_if_not(capabilities()[["aqua"]]) -# expect_app_doppelganger("auto_theme_shiny/base") -# expect_app_doppelganger("auto_theme_shiny/lattice") -# expect_app_doppelganger("auto_theme_shiny/ggplot2") -# expect_app_doppelganger("auto_theme_shiny/local_theme") -# expect_app_doppelganger("auto_theme_shiny/with_theme") -# }) -# -# test_that("Custom fonts with Cairo package", { -# skip_if_not_installed("Cairo") -# expect_app_doppelganger("CairoPNG") -# }) -# -# test_that("Custom fonts with quartz device", { -# skip_if_not(capabilities()[["aqua"]]) -# expect_app_doppelganger("quartz_png") -# }) -# -# test_that("Custom fonts with cairo capabilities", { -# skip_if_not(capabilities()[["cairo"]]) -# expect_app_doppelganger("cairo_png") -# # TODO: figure out why this is failing on mac -# skip_if_not(!identical(shinytest_suffix(), "mac")) -# expect_app_doppelganger("cairo_svg") -# }) -# -# # Remaining tests are rmarkdown specific -# skip_if_not_installed("rmarkdown") -# -# test_that("Auto theming in rmarkdown works", { -# skip_if_not(capabilities()[["aqua"]]) -# expect_app_doppelganger("auto_theme_rmd/darkly_rmd") -# }) -# -# test_that("Can render non-custom fonts in rmarkdown with quartz png", { -# skip_if_not(capabilities()[["aqua"]]) -# expect_app_doppelganger("quartz_png_rmd") -# }) -# -# test_that("Can render non-custom fonts in rmarkdown with CairoPNG", { -# skip_if_not_installed("Cairo") -# expect_app_doppelganger("CairoPNG_rmd") -# }) -# -# test_that("pdf_document compiles without error", { -# skip_if_not(!identical("win", shinytest_suffix())) -# outfile <- rmarkdown::render("pdf.Rmd", quiet = TRUE) -# expect_true(file.exists(outfile)) -# unlink(outfile) -# }) -# -# +context("shinytest") + +skip_on_cran() +skip_if_not_installed("shinytest") +skip_if_not_installed("callr") +skip_if_not_installed("ggplot2") +skip_if_not_installed("lattice") +# Run tests on release version of R +skip_if_not(as.logical(Sys.getenv("SHINYTEST_RUN_TESTS", "true"))) + +# a la shinycoreci:::platform() +shinytest_suffix <- function() { + if (.Platform$OS.type == "windows") { + return("win") + } + sys <- Sys.info()[["sysname"]] + if (sys == "Darwin") { + return("mac") + } + if (sys == "Linux") { + return("linux") + } + stop("unknown platform") +} + +test_app <- function(appDir) { + getFromNamespace("r", "callr")( + function(appDir, suffix) { + getFromNamespace("testApp", "shinytest")(appDir, suffix = suffix) + }, + list(appDir = appDir, suffix = shinytest_suffix()) + ) +} + +expect_app_doppelganger <- function(appDir) { + getFromNamespace("expect_pass", "shinytest")( + test_app(appDir) + ) +} + + +test_that("Custom fonts with ragg", { + skip_if_not_installed("ragg") + expect_app_doppelganger("agg_png") +}) + +test_that("runtime: shiny auto-theming", { + skip_if_not(identical("win", shinytest_suffix())) + expect_app_doppelganger("shiny_runtime") +}) + +# The remaining tests rely on showtext to render custom fonts +skip_if_not_installed("showtext") + +test_that("Auto theming in shiny works", { + # These shiny apps currently use remote urls to import Google fonts + skip_if_offline() + skip_if_not(capabilities()[["aqua"]]) + expect_app_doppelganger("auto_theme_shiny/base") + expect_app_doppelganger("auto_theme_shiny/lattice") + expect_app_doppelganger("auto_theme_shiny/ggplot2") + expect_app_doppelganger("auto_theme_shiny/local_theme") + expect_app_doppelganger("auto_theme_shiny/with_theme") +}) + +test_that("Custom fonts with Cairo package", { + skip_if_not_installed("Cairo") + expect_app_doppelganger("CairoPNG") +}) + +test_that("Custom fonts with quartz device", { + skip_if_not(capabilities()[["aqua"]]) + expect_app_doppelganger("quartz_png") +}) + +test_that("Custom fonts with cairo capabilities", { + skip_if_not(capabilities()[["cairo"]]) + expect_app_doppelganger("cairo_png") + # TODO: figure out why this is failing on mac + skip_if_not(!identical(shinytest_suffix(), "mac")) + expect_app_doppelganger("cairo_svg") +}) + +# Remaining tests are rmarkdown specific +skip_if_not_installed("rmarkdown") + +test_that("Auto theming in rmarkdown works", { + skip_if_not(capabilities()[["aqua"]]) + expect_app_doppelganger("auto_theme_rmd/darkly_rmd") +}) + +test_that("Can render non-custom fonts in rmarkdown with quartz png", { + skip_if_not(capabilities()[["aqua"]]) + expect_app_doppelganger("quartz_png_rmd") +}) + +test_that("Can render non-custom fonts in rmarkdown with CairoPNG", { + skip_if_not_installed("Cairo") + expect_app_doppelganger("CairoPNG_rmd") +}) + +test_that("pdf_document compiles without error", { + skip_if_not(!identical("win", shinytest_suffix())) + + + outfile <- rmarkdown::render("pdf.Rmd", quiet = TRUE) + expect_true(file.exists(outfile)) + unlink(outfile) +})