From 74ad1868c0a86536a4059fa1c27cfee76418f198 Mon Sep 17 00:00:00 2001 From: Hadley Wickham Date: Tue, 23 Jan 2024 11:57:32 -0600 Subject: [PATCH] Better webfakes skipping (#385) And move to better home for helpers Closes #346 --- R/testthat.R => tests/testthat/helper.R | 6 ++++++ tests/testthat/test-form.R | 3 +-- tests/testthat/test-session.R | 2 +- 3 files changed, 8 insertions(+), 3 deletions(-) rename R/testthat.R => tests/testthat/helper.R (80%) diff --git a/R/testthat.R b/tests/testthat/helper.R similarity index 80% rename from R/testthat.R rename to tests/testthat/helper.R index 3eced45d..52a060bf 100644 --- a/R/testthat.R +++ b/tests/testthat/helper.R @@ -1,3 +1,9 @@ +local_test_app <- function(envir = parent.frame()) { + skip_if_not_installed("webfakes") + + webfakes::local_app_process(app_request(), .local_envir = envir) +} + app_request <- function() { req_json <- function(req, res) { out <- list( diff --git a/tests/testthat/test-form.R b/tests/testthat/test-form.R index 058b677c..ba41551c 100644 --- a/tests/testthat/test-form.R +++ b/tests/testthat/test-form.R @@ -188,8 +188,7 @@ test_that("handles no buttons", { }) test_that("can submit using three primary techniques", { - skip_if_not_installed("webfakes") - app <- webfakes::local_app_process(app_request()) + app <- local_test_app() html <- minimal_html('
diff --git a/tests/testthat/test-session.R b/tests/testthat/test-session.R index 36d5ce0f..e15eaf9c 100644 --- a/tests/testthat/test-session.R +++ b/tests/testthat/test-session.R @@ -86,7 +86,7 @@ test_that("can find link by position, content, css, or xpath", { }) test_that("can submit a form", { - app <- webfakes::local_app_process(app_request()) + app <- local_test_app() html <- minimal_html('