Retrieves screenshots from
testthat's _snaps/
directory.
If several files match dir_ls_snaps()
,
they are merged into an animated gif.
Usage
snaps2fig(
test_file = character(),
name = NULL,
auto_numbered = TRUE,
variant = shinytest2::platform_variant(),
fps = 5,
...
)
snaps2md(...)
snaps2rd(...)
dir_ls_snaps(
test_file = character(),
regexp = glue_regexp_snaps(),
variant = shinytest2::platform_variant()
)
image_animate_snaps(snaps = fs::path(), fps = 5, ...)
image_write_snaps(image, path = withr::local_tempfile())
Arguments
- test_file
Name of the test file, in which the snapshots are generated, without:
the extension
the
test-
prefix. If you're using testthat convention, this will be the name of the file inR/
, which you are currently testing.
- name
The
name
passed to shinytest2::AppDriver to be used for screenshots. Can beNULL
, for no filtering by name.- auto_numbered
If
TRUE
, filter for snapshot files automatically numbered according to the scheme used by shinytest2::AppDriver. If you pass aname
only toshinytest2::AppDriver$new()
(recommended), and then invoke severalshinytest2::AppDriver$expect_snapshot()
, they resulting snapshots will all have the same name, appended by a counter from000
to999
. IfFALSE
, any filename{name}*.png
will be selected. You may need to setFALSE
if you pass a name toshinytest2::AppDriver$expect_snapshot()
directly.- variant
If not-
NULL
, results will be saved in_snaps/{variant}/{test}/{name}.{ext}
. This allows you to create different snapshots for different scenarios, like different operating systems or different R versions.- fps
frames per second. Ignored if
delay
is notNULL
.- ...
Arguments passed on to
magick::image_animate
delay
delay after each frame, in 1/100 seconds. Must be length 1, or number of frames. If specified, then
fps
is ignored.loop
how many times to repeat the animation. Default is infinite.
dispose
a frame disposal method from dispose_types()
optimize
optimize the
gif
animation by storing only the differences between frames. Input images must be exactly the same size.
- regexp
A regular expression (e.g.
[.]csv$
) passed on togrep()
to filter paths.- snaps
Vector of file names, as returned by
dir_ls_snaps()
- image
magick image object returned by
image_read()
orimage_graph()
- path
Path to file to snapshot. Optional for
announce_snapshot_file()
ifname
is supplied.
Value
For image_animate_snaps()
A magick-image
.
For image_write_snaps()
, path to the (merged) screenshots.
Functions
snaps2fig()
: Save screenshots toman/figures
and return relative path from there.snaps2md()
: Save screenshots toman/figures
and return markdown image markup, to be inserted in roxygen2 documentation.snaps2rd()
: Save screenshots toman/figures
and return R documentation image markup, to be inserted in R documentation. For a custom roxygen2 tag with equivalent funcionality, seecrowInsertSnaps()
.dir_ls_snaps()
: List all testthat_snaps/
screenshots Finds all files for a variant, file and name.image_animate_snaps()
: Read in screenshot. If several, animate into a gif.image_write_snaps()
: Write out (merged) screenshots to new path.
Matching several screenshots
You can deposit several screenshots of a shiny app using
shinytest2::AppDriver in testing.
Use dir_ls_snaps()
to identify all the resulting images.
Typically used for consecutive screenshots.
See also
Other screenshot:
examples_app()
,
get_screenshot_args_attr()
,
get_screenshot_from_app()
,
glue_regexp_snaps()
,
tag_shiny