From 30ef669aab484de5e9d4abadc49cdde37ff0f4f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Ver=C3=ADssimo?= <211358+averissimo@users.noreply.github.com> Date: Fri, 20 Dec 2024 09:18:02 +0000 Subject: [PATCH] TealAppDriver skips tests when shinytest2 or rvest are not installed (#1432) # Pull Request Part of https://github.com/insightsengineering/teal.modules.general/pull/774 See https://github.com/insightsengineering/teal.modules.general/pull/774#discussion_r1718027258 --- R/TealAppDriver.R | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/R/TealAppDriver.R b/R/TealAppDriver.R index 70eb0da6e9..f170e515a7 100644 --- a/R/TealAppDriver.R +++ b/R/TealAppDriver.R @@ -10,12 +10,15 @@ TealAppDriver <- R6::R6Class( # nolint: object_name. "TealAppDriver", inherit = { - if (!requireNamespace("shinytest2", quietly = TRUE)) { - stop("Please install 'shinytest2' package to use this class.") - } - if (!requireNamespace("rvest", quietly = TRUE)) { - stop("Please install 'rvest' package to use this class.") - } + lapply(c("testthat", "shinytest2", "rvest"), function(.x, use_testthat) { + if (!requireNamespace(.x, quietly = TRUE)) { + if (use_testthat) { + testthat::skip(sprintf("%s is not installed", .x)) + } else { + stop("Please install '", .x, "' package to use this class.", call. = FALSE) + } + } + }, use_testthat = requireNamespace("testthat", quietly = TRUE) && testthat::is_testing()) shinytest2::AppDriver }, # public methods ----