Snapscreen
When you call snapshot(name)
it will take a screenshot at that point and store it under ./screenshots/actual
, it will compare it to the corresponding file under ./screenshots/expected
and return the number of pixels difference. If the difference is non-zero, a ${name}-diff.png
file will also be created highlighting the different pixels.
The expected/actual folders are automatically created if they don't exist. If there isn't a corresponding expected file (e.g. on first run), it will automatically be created too - i.e. there is zero set up.
To force update a screenshot on subsequent runs you can set the environment variable SNAPSHOTS
equal to the screenshot name, or set it to true
to overwrite all the expected screenshots.
const test = startup =
Additional Options
const snapshot = await page width = 1920 height = 1200 dir =
width
/height
: set the width/height of the screenshotsdir
: the base directory where thescreenshots
will be created, defaults to where the module is called fromupdate
: overwrite the expected file with the actual file, defaults to true if the environment variableSNAPSHOTS
is set totrue
or the name of the screenshot.fullPage
: take a full page screenshot rather than cropping to specific width/heightscrollX
/scrollY
: scroll to this position before taking the screenshot