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(
test_file = character(),
name = NULL,
auto_numbered = TRUE,
variant = shinytest2::platform_variant(),
fps = 5
)
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
namepassed 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 anameonly toshinytest2::AppDriver$new()(recommended), and then invoke severalshinytest2::AppDriver$expect_snapshot(), they resulting snapshots will all have the same name, appended by a counter from000to999. IfFALSE, any filename{name}*.pngwill be selected. You may need to setFALSEif you pass a name toshinytest2::AppDriver$expect_snapshot()directly.- variant
If not-
NULL, results will be saved in_snaps/{variant}/{test}/{name}. This allows you to create different snapshots for different scenarios, like different operating systems or different R versions.Note that there's no way to declare all possible variants up front which means that as soon as you start using variants, you are responsible for deleting snapshot variants that are no longer used. (testthat will still delete all variants if you delete the test.)
- fps
frames per second. Ignored if
delayis notNULL.- ...
Arguments passed on to
magick::image_animatedelaydelay after each frame, in 1/100 seconds. Must be length 1, or number of frames. If specified, then
fpsis ignored.loophow many times to repeat the animation. Default is infinite.
disposea frame disposal method from dispose_types()
optimizeoptimize the
gifanimation 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()ifnameis supplied.
Value
For image_animate_snaps() A magick-image.
For image_write_snaps(), path to the (merged) screenshots.
Functions
snaps2fig(): Save screenshots toman/figuresand return relative path from there.snaps2md(): Save screenshots toman/figuresand return markdown image markup, to be inserted in roxygen2 documentation.snaps2rd(): Save screenshots toman/figuresand return R documentation image markup, to be inserted in R documentation. For a custom roxygen2 tag with equivalent functionality, 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