Skip to content

Commit

Permalink
Skip snapshots on R < 3.6
Browse files Browse the repository at this point in the history
  • Loading branch information
cpsievert committed Mar 17, 2021
1 parent 1c8832e commit 63b9efd
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 20 deletions.
11 changes: 0 additions & 11 deletions tests/testthat/helper.R
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,3 @@ rewire_namespace_handler <- function(pkgname, symbolname, value) {
}
}
}


# R3.6 changed the RNGkind() default. This restores the old default
# before calling set.seed() so we can have consistent random results
# across R versions.
with_private_seed <- function(x) {
kind <- RNGkind()
on.exit(do.call(RNGkind, as.list(kind)), add = TRUE)
suppressWarnings(RNGversion("3.5.0"))
withPrivateSeed(x)
}
27 changes: 18 additions & 9 deletions tests/testthat/test-tabPanel.R
Original file line number Diff line number Diff line change
@@ -1,20 +1,28 @@
# tabsetPanel() et al. use p_randomInt() to generate ids (which uses withPrivateSeed()),
# so we need to fix Shiny's private seed in order to make their HTML output deterministic
navlist_panel <- function(...) {
with_private_seed(set.seed(100))

withPrivateSeed(set.seed(100))
navlistPanel(...)
}
navbar_page <- function(...) {
with_private_seed(set.seed(100))
withPrivateSeed(set.seed(100))
navbarPage(...)
}
tabset_panel <- function(...) {
with_private_seed(set.seed(100))
withPrivateSeed(set.seed(100))
tabsetPanel(...)
}

expect_snapshot2 <- function(...) {
if (getRversion() < "3.6.0") {
skip("Skipping non-deterministic snapshots on R < 3.6")
}
expect_snapshot(...)
}

expect_snapshot_bslib <- function(x, ...) {
expect_snapshot(bslib_tags(x), ...)
expect_snapshot2(bslib_tags(x), ...)
}

# Simulates the UI tags that would be produced by
Expand All @@ -33,15 +41,16 @@ panels <- list(
)

test_that("tabsetPanel() markup is correct", {

default <- tabset_panel(!!!panels)
pills <- tabset_panel(
!!!panels, type = "pills", selected = "B",
header = div(class = "content-header"),
footer = div(class = "content-footer")
)
# BS3
expect_snapshot(default)
expect_snapshot(pills)
expect_snapshot2(default)
expect_snapshot2(pills)
# BS4
expect_snapshot_bslib(default)
expect_snapshot_bslib(pills)
Expand All @@ -51,14 +60,14 @@ test_that("tabsetPanel() markup is correct", {

test_that("navbarPage() markup is correct", {
nav_page <- navbar_page("Title", !!!panels)
expect_snapshot(nav_page)
expect_snapshot2(nav_page)
expect_snapshot_bslib(nav_page)
})

# navlistPanel() can handle strings, but the others can't
test_that("String input is handled properly", {
nav_list <- navlist_panel(!!!c(list("A header"), panels))
expect_snapshot(nav_list)
expect_snapshot2(nav_list)
expect_snapshot_bslib(nav_list)
expect_error(
tabsetPanel(!!!c(list("A header"), panels)),
Expand All @@ -73,7 +82,7 @@ test_that("Shiny.tag input produces a warning", {
# sensible (which is why we now throw a warning), but it's probably
# too late to change the behavior (it could break user code to do
# anything different)
expect_snapshot(tab_tags)
expect_snapshot2(tab_tags)
})

test_that("tabPanelBody validates it's input", {
Expand Down

0 comments on commit 63b9efd

Please sign in to comment.