| 1 |
|
| 2 |
test_that("devmode is not on while testing", { |
| 3 |
expect_equal(in_devmode(), FALSE) |
| 4 |
}) |
| 5 |
|
| 6 |
test_that("devmode can not be turned on while testing", { |
| 7 |
with_devmode(TRUE, { |
| 8 |
expect_equal(in_devmode(), FALSE) |
| 9 |
}) |
| 10 |
}) |
| 11 |
|
| 12 |
test_that("devmode can be turned on while _testing_ is disabled and check messages", { |
| 13 |
|
| 14 |
# TODO - Once a stable version of rlang lands with `options(rlib_message_verbosity)` functionality, |
| 15 |
# bump the rlang version in DESCRIPTION and remove these skip calls |
| 16 |
# Skip if *not* on CI; Inspired from `testthat::skip_on_ci()` |
| 17 |
skip_if(!isTRUE(as.logical(Sys.getenv("CI"))), "Not testing in CI") |
| 18 |
skip_if_not_installed("rlang", "0.4.11.9000") |
| 19 |
|
| 20 |
# disable all existing options |
| 21 |
withr::local_options(list( |
| 22 |
shiny.devmode = NULL, |
| 23 |
shiny.devmode.verbose = NULL, |
| 24 |
shiny.autoreload = NULL, |
| 25 |
shiny.minified = NULL, |
| 26 |
shiny.fullstacktrace = NULL, |
| 27 |
# force inform to always generate signal |
| 28 |
rlib_message_verbosity = "verbose" |
| 29 |
)) |
| 30 |
# "turn off" testing to allow for devmode to activate |
| 31 |
withr::local_envvar(list( |
| 32 |
TESTTHAT = "false" |
| 33 |
)) |
| 34 |
|
| 35 |
expect_equal(getOption("shiny.devmode", "default"), "default") |
| 36 |
expect_equal(getOption("shiny.devmode.verbose", "default"), "default") |
| 37 |
expect_equal(get_devmode_option("shiny.autoreload", "default"), "default") |
| 38 |
expect_equal(get_devmode_option("shiny.minified", "default"), "default") |
| 39 |
expect_equal(get_devmode_option("shiny.fullstacktrace", "default"), "default") |
| 40 |
|
| 41 |
with_devmode(TRUE, verbose = TRUE, { |
| 42 |
expect_equal(in_devmode(), TRUE) |
| 43 |
expect_message(devmode_inform("custom message here"), "shiny devmode - ") |
| 44 |
|
| 45 |
expect_devmode_option <- function(key, expected, msg, ...) { |
| 46 |
expect_message(val <- get_devmode_option(key, ...), msg) |
| 47 |
expect_equal(val, expected) |
| 48 |
} |
| 49 |
|
| 50 |
expect_devmode_option("shiny.autoreload", TRUE, "Turning on shiny autoreload") |
| 51 |
expect_devmode_option("shiny.minified", FALSE, "Using full shiny javascript file") |
| 52 |
expect_devmode_option("shiny.fullstacktrace", TRUE, "Turning on full stack trace") |
| 53 |
|
| 54 |
# local values can be overwritten |
| 55 |
expect_devmode_option("shiny.autoreload", "on", "Turning on shiny autoreload", devmode_default = "on") |
| 56 |
expect_devmode_option("shiny.autoreload", TRUE, "custom msg", devmode_message = "custom msg") |
| 57 |
|
| 58 |
}) |
| 59 |
|
| 60 |
}) |
| 61 |
|
| 62 |
|
| 63 |
test_that("no devmode side effects from testing", { |
| 64 |
expect_equal(in_devmode(), FALSE) |
| 65 |
}) |