From dc45b4ddefa369985502f1d4dd4561bebd08d95e Mon Sep 17 00:00:00 2001 From: Barret Schloerke Date: Tue, 7 Jun 2022 10:25:42 -0400 Subject: [PATCH 1/5] Make `{globals}` an `Imports` instead of `Suggests`; Fixes #208 --- DESCRIPTION | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 655b7f7e..c5cf2e82 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -23,32 +23,32 @@ Depends: testthat (>= 3.1.2) Imports: R6 (>= 2.4.0), - chromote (>= 0.1.0), - fs, callr, - crayon, - rlang (>= 0.3.0), checkmate (>= 2.0.0), + chromote (>= 0.1.0), + crayon, ellipsis, + fs, + globals (>= 0.14.0), httr, jsonlite, pingr, + rlang (>= 0.3.0), rmarkdown, shiny, withr Suggests: diffobj, - globals (>= 0.14.0), ggplot2, - vdiffr (>= 1.0.0), + knitr, plotly, rstudioapi, shinyWidgets, shinytest (>= 1.5.1), shinyvalidate (>= 0.1.2), showimage, - knitr, - usethis + usethis, + vdiffr (>= 1.0.0) Config/Needs/check: rstudio/shiny Config/Needs/website: From 2506d5ea13978ad89764065abcea8e923f8dc30f Mon Sep 17 00:00:00 2001 From: Barret Schloerke Date: Tue, 7 Jun 2022 10:42:30 -0400 Subject: [PATCH 2/5] Add support for _not_ recording the screen size; Fixes #205 --- R/record-test.R | 3 +++ inst/internal/recorder/app.R | 4 ++++ man/record_test.Rd | 3 +++ 3 files changed, 10 insertions(+) diff --git a/R/record-test.R b/R/record-test.R index 4afa53ae..39268cff 100644 --- a/R/record-test.R +++ b/R/record-test.R @@ -35,6 +35,7 @@ #' * be recorded. #' #' See [`AppDriver`]`$set_inputs()` for more information. +#' @param record_screen_size If `TRUE`, the screen size will be recorded when initialized and changed. #' @param run_test If `TRUE`, `test_file` will be executed after saving the recording. #' @seealso [`test_app()`] #' @export @@ -52,6 +53,7 @@ record_test <- function( test_file = "test-shinytest2.R", open_test_file = rlang::is_interactive(), allow_no_input_binding = NULL, + record_screen_size = TRUE, run_test = TRUE ) { ellipsis::check_dots_empty() @@ -120,6 +122,7 @@ record_test <- function( shinytest2.seed = seed, shinytest2.shiny.args = shiny_args, shinytest2.test_file = test_file, + shinytest2.record_screen_size = isTRUE(record_screen_size), shinytest2.allow_no_input_binding = allow_no_input_binding ), # Make sure the recorder opens in an external browser diff --git a/inst/internal/recorder/app.R b/inst/internal/recorder/app.R index c10f67b1..0513c6fc 100644 --- a/inst/internal/recorder/app.R +++ b/inst/internal/recorder/app.R @@ -7,6 +7,7 @@ load_timeout <- getOption("shinytest2.load.timeout") start_seed <- getOption("shinytest2.seed") shiny_args <- getOption("shinytest2.shiny.args") save_file <- getOption("shinytest2.test_file") +record_screen_size <- getOption("shinytest2.record_screen_size") allow_no_input_binding <- getOption("shinytest2.allow_no_input_binding") if (is.null(target_url) || is.null(app)) { @@ -437,6 +438,9 @@ shinyApp( # If two setWindowSize events sandwich an outputEvent, # remove the first setWindowSize to_remove[length(to_remove) + 1] <- i - 2 + } else if (!record_screen_size && curr_event$type == "setWindowSize") { + # If we're not recording screen size, remove all setWindowSize events + to_remove[length(to_remove) + 1] <- i } } diff --git a/man/record_test.Rd b/man/record_test.Rd index 3311e23a..b1d79be7 100644 --- a/man/record_test.Rd +++ b/man/record_test.Rd @@ -14,6 +14,7 @@ record_test( test_file = "test-shinytest2.R", open_test_file = rlang::is_interactive(), allow_no_input_binding = NULL, + record_screen_size = TRUE, run_test = TRUE ) } @@ -51,6 +52,8 @@ bindings are recorded. See \code{\link{AppDriver}}\verb{$set_inputs()} for more information.} +\item{record_screen_size}{If \code{TRUE}, the screen size will be recorded when initialized and changed.} + \item{run_test}{If \code{TRUE}, \code{test_file} will be executed after saving the recording.} } \description{ From 8a9f293831ded18fb6c15d0df455523b6945b825 Mon Sep 17 00:00:00 2001 From: Barret Schloerke Date: Wed, 8 Jun 2022 15:11:33 -0400 Subject: [PATCH 3/5] Numeric values for datetime should be multiplied by 1k to turn into milliseconds --- inst/internal/recorder/app.R | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/inst/internal/recorder/app.R b/inst/internal/recorder/app.R index 0513c6fc..eb76269d 100644 --- a/inst/internal/recorder/app.R +++ b/inst/internal/recorder/app.R @@ -153,6 +153,16 @@ input_processors <- list( shiny.action = function(value) { structure("click", class = c("st2_click", "character")) }, + shiny.datetime = function(value) { + if (is.list(value)) { + value <- unlist(value, recursive = FALSE) + } + if (is.numeric(value)) { + # Turn seconds into milliseconds + value <- value * 1000 + } + input_processors$default(value) + }, shiny.fileupload = function(value) { # Extract filenames, then send to default processor From 17a03130736532d73b8416f0515cedf22f755d9d Mon Sep 17 00:00:00 2001 From: Barret Schloerke Date: Wed, 8 Jun 2022 15:11:53 -0400 Subject: [PATCH 4/5] Support an array of number or date string values when setting inputs --- inst/internal/js/shiny-tracer.js | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/inst/internal/js/shiny-tracer.js b/inst/internal/js/shiny-tracer.js index d81e6af6..4a5836b9 100644 --- a/inst/internal/js/shiny-tracer.js +++ b/inst/internal/js/shiny-tracer.js @@ -103,12 +103,26 @@ window.shinytest2 = (function() { }, "shiny.sliderInput": function(el, value) { - if (typeof(value) === "string" && - /\d\d\d\d-\d\d-\d\d/.test(value)) - { - return new Date(value).getTime(); + function update_date_string(x) { + if ( + ( + typeof(x) === "string" && + /\d\d\d\d-\d\d-\d\d/.test(x) + ) || + ( + typeof(x) === "number" + ) + ) { + return new Date(x).getTime(); + } else { + return x; + } + } + + if (value instanceof Array) { + return value.map(update_date_string); } else { - return value; + return update_date_string(value); } } }; From 843f36c3f8356892580cdb64dc649e5c6d42e8a7 Mon Sep 17 00:00:00 2001 From: Barret Schloerke Date: Wed, 8 Jun 2022 15:19:50 -0400 Subject: [PATCH 5/5] Update NEWS.md --- NEWS.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/NEWS.md b/NEWS.md index d790d778..d553c969 100644 --- a/NEWS.md +++ b/NEWS.md @@ -4,6 +4,14 @@ * Fix set of bugs found by @daattali including test files should be opened in the IDE after recording and test and replace missing images in the website (#199) +* Provide example workflows on how to use `rstudio/shinytest2/actions/test-app` GHA action (#217) + +* Make `{globals}` an `Imports` package, instead of a `Suggests` package (#223) + +* Add support for _not_ recording the screen size when recording a test (#223) + +* When setting a date time slider value, it can now handle array inputs properly. When recording a date time slider value, numeric values will not be recorded as milliseconds instead of seconds since epoch. (#223) + # shinytest2 0.1.0 * Initial release of package