Skip to content

Commit

Permalink
Merge pull request #1164 from ThinkR-open/a-bit-more-tests
Browse files Browse the repository at this point in the history
test: adding tests
  • Loading branch information
ColinFay authored Aug 16, 2024
2 parents a7b7a8b + aa5348c commit 63b1d1a
Show file tree
Hide file tree
Showing 19 changed files with 543 additions and 88 deletions.
6 changes: 0 additions & 6 deletions .github/workflows/render-rmarkdown-and-bump-version.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,6 @@ jobs:
needs: check

# Render READEME.md using rmarkdown
- name: Maybe bump dev version
if: github.ref == 'refs/heads/dev'
run: Rscript -e 'desc::desc_bump_version("patch")'
- name: Maybe bump master version
if: github.ref == 'refs/heads/master'
run: Rscript -e 'desc::desc_bump_version("minor")'
- name: render README
run: Rscript -e 'rmarkdown::render("README.Rmd", output_format = "md_document")'
- name: Commit Results
Expand Down
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: golem
Title: A Framework for Robust Shiny Applications
Version: 0.5.3
Version: 0.5.0
Authors@R: c(
person("Colin", "Fay", , "[email protected]", role = c("cre", "aut"),
comment = c(ORCID = "0000-0001-7343-1846")),
Expand Down
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
> Notes: the # between parenthesis referes to the related issue on GitHub, and the @ refers to an external contributor solving this issue.
> Notes: the # between parenthesis refers to the related issue on GitHub, and the @ refers to an external contributor solving this issue.
# 0.5.0

Expand Down
4 changes: 4 additions & 0 deletions R/bootstrap_rlang.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# For mocking purposes
rlang_is_interactive <- rlang::is_interactive

rlang_is_installed <- rlang::is_installed
8 changes: 5 additions & 3 deletions R/config.R
Original file line number Diff line number Diff line change
Expand Up @@ -220,13 +220,12 @@ get_current_config <- function(path = getwd()) {
}

if (!fs_file_exists(path_conf)) {
if (rlang::is_interactive()) {
if (rlang_is_interactive()) {
ask <- ask_golem_creation_upon_config(path_conf)
# Return early if the user doesn't allow
if (!ask) {
return(NULL)
}

fs_file_copy(
path = golem_sys("shinyexample/inst/golem-config.yml"),
new_path = fs_path(
Expand All @@ -247,7 +246,7 @@ get_current_config <- function(path = getwd()) {
"R/app_config.R"
),
"shinyexample",
golem::pkg_name()
golem::pkg_name(path = path)
)
# TODO This should also create the dev folder
} else {
Expand All @@ -265,6 +264,8 @@ get_current_config <- function(path = getwd()) {
)
}



ask_golem_creation_upon_config <- function(pth) {
msg <- paste0(
"The %s file doesn't exist.",
Expand All @@ -273,6 +274,7 @@ ask_golem_creation_upon_config <- function(pth) {
)
yesno(sprintf(msg, basename(pth)))
}

# This function changes the name of the
# package in app_config when you need to
# set the {golem} name
Expand Down
2 changes: 1 addition & 1 deletion R/install_dev_deps.R
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ dev_deps <- unique(
check_dev_deps_are_installed <- function() {
are_installed <- sapply(
dev_deps,
FUN = rlang::is_installed
FUN = rlang_is_installed
)
if (!all(are_installed)) {
message(
Expand Down
14 changes: 10 additions & 4 deletions R/test_helpers.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ expect_shinytaglist <- function(object) {
invisible(act$val)
}


testthat_expect_snapshot <- testthat::expect_snapshot

#' @export
#' @rdname testhelpers
#' @param ui output of an UI function
Expand All @@ -62,7 +65,7 @@ expect_html_equal <- function(
)
}

testthat::expect_snapshot(
testthat_expect_snapshot(
x = ui,
...
)
Expand All @@ -86,7 +89,7 @@ expect_running <- function(
testthat::skip_on_cran()

# Ok for now we'll get back to this
testthat::skip_if_not(interactive())
testthat::skip_if_not(rlang_is_interactive())

# Oh boy using testthat and processx is a mess
#
Expand Down Expand Up @@ -170,7 +173,7 @@ expect_running <- function(

if (go_for_pkgload) {
# Using pkgload because we can
shinyproc <- processx::process$new(
shinyproc <- processx_process(
command = r_,
c(
"-e",
Expand All @@ -179,7 +182,7 @@ expect_running <- function(
)
} else {
# Using the temps libPaths because we can
shinyproc <- processx::process$new(
shinyproc <- processx_process(
echo_cmd = TRUE,
command = r_,
c(
Expand All @@ -195,3 +198,6 @@ expect_running <- function(
testthat::expect_true(shinyproc$is_alive())
shinyproc$kill()
}


processx_process <- processx::process$new
3 changes: 2 additions & 1 deletion R/use_recommended.R
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ use_recommended_tests <- function(
fs_file_copy(
golem_sys(
"utils",
"test-golem-recommended.R")
"test-golem-recommended.R"
)
,
fs_path(pkg, "tests", "testthat"),
overwrite = TRUE
Expand Down
5 changes: 0 additions & 5 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@ golem_sys <- function(
)
}

# For testing purpose
rlang_is_interactive <- function() {
rlang::is_interactive()
}

create_if_needed <- function(
path,
type = c("file", "directory"),
Expand Down
12 changes: 12 additions & 0 deletions tests/testthat/_snaps/after_creation_msg.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,21 @@
body = tagList()
# add here other template arguments
)
Code
testthat::with_mocked_bindings(fs_path_abs = paste, {
after_creation_message_any_file("mypkg", "inst/app/www", "myhtml")
})
Output
File downloaded at inst/app/www/myhtml
Code
file_created_dance("inst/app/www", after_creation_message_sass, "mypkg",
"inst/app/www", "mysass", open_file = FALSE, open_or_go_to = FALSE)
Output
v File created at inst/app/www
Code
file_already_there_dance("inst/app/www", open_file = FALSE)
Output
v File already exists.
* Go to inst/app/www

7 changes: 7 additions & 0 deletions tests/testthat/_snaps/config.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# ask_golem_creation_upon_config works

Code
ask_golem_creation_upon_config("/home/golem")
Output
[1] "The golem file doesn't exist.\nIt's possible that you might not be in a {golem} based project.\nDo you want to create the {golem} files?"

Loading

0 comments on commit 63b1d1a

Please sign in to comment.