diff --git a/R/engine.R b/R/engine.R index 10c757e..a26cbdb 100644 --- a/R/engine.R +++ b/R/engine.R @@ -51,10 +51,6 @@ run_engine <- function(engine) { } kill_engine <- function(engine) { - # technically, if we are killing the engine, - # we don't want to close the - # publlisher because we might reuse it - #close(engine$publisher) kill_runner(engine) } diff --git a/TODO.md b/TODO.md index 055b1d0..e7704ba 100644 --- a/TODO.md +++ b/TODO.md @@ -15,3 +15,8 @@ ## 7 - Nanonext is currently only used because I want an async connection for the local webpage refresh. May not need to use nanonext, considering we fake the protocol on the JS side of things anyway + +## 8 + +- The CLI messages are a bit all over the place, and errors don't always cause +the progress bar to fail diff --git a/tests/testthat/helpers.R b/tests/testthat/helpers.R new file mode 100644 index 0000000..e88fca5 --- /dev/null +++ b/tests/testthat/helpers.R @@ -0,0 +1,12 @@ +new_test_engine <- function() { + new_engine( + config = new_config( + path = system.file("examples", "plumber.R", package = "hotwater") + ) + ) +} + +cleanup_test_engine <- function(engine) { + kill_engine(engine) + close(engine$publisher) +} diff --git a/tests/testthat/test-cli.R b/tests/testthat/test-cli.R index 13dc65f..f465a52 100644 --- a/tests/testthat/test-cli.R +++ b/tests/testthat/test-cli.R @@ -1,9 +1,5 @@ test_that("startup/teardown messages don't error", { - engine <- new_engine( - config = new_config( - path = system.file("examples", "plumber.R", package = "hotwater") - ) - ) + engine <- new_test_engine() expect_no_error( suppressMessages( buildup_engine(engine) @@ -14,4 +10,5 @@ test_that("startup/teardown messages don't error", { teardown_engine(engine) ) ) + cleanup_test_engine(engine) }) diff --git a/tests/testthat/test-engine.R b/tests/testthat/test-engine.R index 1c306ac..f2129a9 100644 --- a/tests/testthat/test-engine.R +++ b/tests/testthat/test-engine.R @@ -19,17 +19,15 @@ test_that("engine reuse", { ) ) ) + + cleanup_test_engine(engine) }) test_that("can kill engine", { - engine <- new_engine( - config = new_config( - path = system.file("examples", "plumber.R", package = "hotwater") - ) - ) + engine <- new_test_engine() new_runner(engine) kill_engine(engine) - expect_false(engine$runner$is_alive()) - # expect_true(engine$publisher$state == "closed") + + cleanup_test_engine(engine) }) \ No newline at end of file diff --git a/tests/testthat/test-middleware.R b/tests/testthat/test-middleware.R index ae5f2ec..27bc70c 100644 --- a/tests/testthat/test-middleware.R +++ b/tests/testthat/test-middleware.R @@ -17,11 +17,7 @@ test_that("middleware injection works", { }) test_that("middleware injection works with filters", { - engine <- new_engine( - new_config( - path = system.file("examples", "plumber.R", package = "hotwater") - ) - ) + engine <- new_test_engine() runner <- suppressMessages(callr::r_bg( function(config, middleware_filter) { plumber::pr(config$entry_path) |> @@ -48,15 +44,11 @@ test_that("middleware injection works with filters", { httr2::resp_status() expect_identical(resp, 200L) - kill_engine(engine) + cleanup_test_engine(engine) }) test_that("is_plumber_running works", { - engine <- new_engine( - new_config( - path = system.file("examples", "plumber.R", package = "hotwater") - ) - ) + engine <- new_test_engine() router <- suppressMessages(callr::r_bg( function(config) { plumber::pr(config$entry_path) |> @@ -78,20 +70,15 @@ test_that("is_plumber_running works", { } router$kill_tree() expect_lt(i, 20L, label = "loop iterations") - kill_engine(engine) + cleanup_test_engine(engine) }) test_that("autoreloader is attached", { - engine <- new_engine( - new_config( - path = system.file("examples", "plumber.R", package = "hotwater") - - ) - ) + engine <- new_test_engine() new_runner(engine) resp <- httr2::request(sprintf("localhost:%s", engine$config$port)) |> httr2::req_perform() |> httr2::resp_body_html() expect_true(grepl(resp, pattern = "