1context("Includes")
2
3test_that("Includes work", {
4  r <- plumber$new("files/includes.R")
5
6  # When running, we setwd to the file's dir. Simulate that here.
7  cwd <- getwd()
8  on.exit( { setwd(cwd) } )
9  setwd("files")
10
11  res <- PlumberResponse$new()
12  val <- r$route(make_req("GET", "/"), res)
13  expect_equal(val$body, "test.txt content")
14  expect_equal(val$headers$`Content-type`, NULL)
15
16  res <- PlumberResponse$new()
17  val <- r$route(make_req("GET", "/html"), res)
18  expect_match(val$body, ".*<html.*</html>\\s*$")
19  expect_equal(val$headers$`Content-type`, "text/html; charset=utf-8")
20
21  # Skip these tests on some CRAN instances
22  if (rmarkdown::pandoc_available()){
23    res <- PlumberResponse$new()
24    val <- r$route(make_req("GET", "/md"), res)
25    expect_match(val$body, "<html.*<h2>R Output</h2>.*</html>\\s*$")
26    expect_equal(val$headers$`Content-type`, "text/html; charset=utf-8")
27
28    res <- PlumberResponse$new()
29    val <- r$route(make_req("GET", "/rmd"), res)
30    expect_match(val$body, "<html.*<img src=\"data:image/png;base64.*</html>\\s*$")
31    expect_equal(val$headers$`Content-type`, "text/html; charset=utf-8")
32  }
33})
34