Skip to content

Commit

Permalink
show metadata with snaps
Browse files Browse the repository at this point in the history
closes #42
  • Loading branch information
maxheld83 committed Nov 21, 2024
1 parent 612c9cb commit ed0ec81
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 12 deletions.
37 changes: 28 additions & 9 deletions R/shiny2screenshot.R
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,9 @@ roxy_tag_parse.roxy_tag_crowInsertSnaps <- function(x) {
roxy_tag_rd.roxy_tag_crowInsertSnaps <- function(x, base_path, env) {
args <- as.list(x[["val"]])
if (length(args) >= 2) args[[3]] <- as.logical(args[[3]])
possible_names <- c("test_file", "name", "auto_numbered", "variant", "fps")
# this is fine because the order of arguments for tags is always the same
names(args) <- possible_names[1:length(args)]

Check warning on line 206 in R/shiny2screenshot.R

View workflow job for this annotation

GitHub Actions / Test, Check, Lint and Document Package (rlint)

file=R/shiny2screenshot.R,line=206,col=33,[seq_linter] 1:length(...) is likely to be wrong in the empty edge case. Use seq_along(...) instead.
roxygen2::rd_section(
type = "crowInsertSnaps",
value = rlang::exec(snaps2rd, !!!args)
Expand Down Expand Up @@ -285,15 +288,31 @@ snaps2md <- function(...) {
#' For a custom roxygen2 tag with equivalent funcionality,
#' see [crowInsertSnaps()].
#' @export
snaps2rd <- function(...) {
path <- snaps2fig(...)
paste0(
"{\\figure{",
path,
"}{options: width='100\\%' alt=",
snap_alt_text(),
"}}",
collapse = ""
snaps2rd <- function(test_file = character(),
name = NULL,
auto_numbered = TRUE,
variant = shinytest2::platform_variant(),
fps = 5) {
path <- snaps2fig(
test_file = test_file,
name = name,
auto_numbered = auto_numbered,
variant = variant,
fps = fps
)
glue::glue_collapse(
c(
glue::glue("{{name: \\code{{{name}}}, variant: \\code{{{variant}}}"),
paste0(
"\\figure{",
path,
"}{options: width='100\\%' alt=",
snap_alt_text(),
"}}",
collapse = ""
)
),
sep = " "
)
}

Expand Down
6 changes: 3 additions & 3 deletions tests/testthat/_snaps/shiny2screenshot.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
topic$get_section("crowInsertSnaps")
Output
\section{Screenshots from Tests}{
\if{html}{\figure{crow_screenshots/helpers/bins.gif}{options: width='100\%' alt=Screenshot from App}}\if{latex}{Screenshots cannot be shown in this output format.}}
\if{html}{name: \code{bins}, variant: \code{linux} \figure{crow_screenshots/helpers/bins.gif}{options: width='100\%' alt=Screenshot from App}}\if{latex}{Screenshots cannot be shown in this output format.}}

# roxy_tag_crowInsertSnaps: can be formatted with multiple tags joined
Expand All @@ -73,8 +73,8 @@
topic$get_section("crowInsertSnaps")
Output
\section{Screenshots from Tests}{
\if{html}{\figure{crow_screenshots/helpers/bins.gif}{options: width='100\%' alt=Screenshot from App}}
{\figure{crow_screenshots/helpers/bins.gif}{options: width='100\%' alt=Screenshot from App}}\if{latex}{Screenshots cannot be shown in this output format.}}
\if{html}{name: \code{bins}, variant: \code{linux} \figure{crow_screenshots/helpers/bins.gif}{options: width='100\%' alt=Screenshot from App}}
{name: \code{bins}, variant: \code{mac} \figure{crow_screenshots/helpers/bins.gif}{options: width='100\%' alt=Screenshot from App}}\if{latex}{Screenshots cannot be shown in this output format.}}

# snaps2fig and friends work: writes out markdown syntax
Expand Down

0 comments on commit ed0ec81

Please sign in to comment.