Skip to content

Commit 1023846

Browse files
committed
feat: allow to create a test file
1 parent 9bb40e6 commit 1023846

File tree

3 files changed

+79
-1
lines changed

3 files changed

+79
-1
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: pw
22
Title: Test your 'golem' Apps with 'Playwright'
3-
Version: 0.0.0.9011
3+
Version: 0.0.0.9012
44
Authors@R:
55
person("Colin", "Fay", , "contact@colinfay.me", role = c("aut", "cre"),
66
comment = c(ORCID = "0000-0001-7343-1846"))

R/pw-use_test.R

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#' Show the Playwright report
2+
#'
3+
#' @param name The name of the test to add (without .test.ts extension)
4+
#' @param where The path to the package
5+
#' @importFrom fs file_copy
6+
#' @importFrom withr with_dir
7+
#' @export
8+
pw_use_test <- function(
9+
name,
10+
where = golem::get_golem_wd()
11+
) {
12+
if (missing(name) || !is.character(name) || length(name) != 1) {
13+
stop("Please provide a single test name as a string.")
14+
}
15+
stop_if_npx_not_available()
16+
stop_if_playwright_skeleton_not_present(
17+
where = where
18+
)
19+
with_dir(
20+
where,
21+
{
22+
with_dir("tests", {
23+
with_dir("playwright", {
24+
file_copy(
25+
pw_sys_files(
26+
"default.test.ts"
27+
),
28+
sprintf(
29+
"%s.test.ts",
30+
name
31+
)
32+
)
33+
})
34+
})
35+
}
36+
)
37+
}

tests/testthat/test-pw-use_test.R

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
test_that("pw_use_test works", {
2+
temp_dir <- fs::path_temp(
3+
"pwtest"
4+
)
5+
unlink(
6+
temp_dir,
7+
recursive = TRUE
8+
)
9+
dir.create(
10+
file.path(
11+
temp_dir,
12+
"tests",
13+
"playwright"
14+
),
15+
recursive = TRUE
16+
)
17+
testthat::with_mocked_bindings(
18+
stop_if_npx_not_available = function(...) NULL,
19+
stop_if_playwright_skeleton_not_present = function(...) NULL,
20+
{
21+
pw_use_test(
22+
name = "my_test",
23+
where = temp_dir
24+
)
25+
}
26+
)
27+
expect_true(
28+
file.exists(
29+
fs::path(
30+
temp_dir,
31+
"tests",
32+
"playwright",
33+
"my_test.test.ts"
34+
)
35+
)
36+
)
37+
unlink(
38+
temp_dir,
39+
recursive = TRUE
40+
)
41+
})

0 commit comments

Comments
 (0)