1 | import { toMatchImageSnapshot } from 'jest-image-snapshot';
|
2 | import { defaultImageSnapshotConfig } from './config';
|
3 | import { puppeteerTest } from './puppeteerTest';
|
4 | expect.extend({ toMatchImageSnapshot });
|
5 | export const imageSnapshot = (customConfig = {}) => {
|
6 | const config = { ...defaultImageSnapshotConfig, ...customConfig };
|
7 | const { getMatchOptions, getScreenshotOptions, beforeScreenshot, afterScreenshot } = config;
|
8 | return puppeteerTest({
|
9 | ...config,
|
10 | async testBody(page, options) {
|
11 | expect.hasAssertions();
|
12 | const element = await beforeScreenshot(page, options);
|
13 | const image = await (element || page).screenshot(getScreenshotOptions(options));
|
14 | await afterScreenshot({ image, context: options.context });
|
15 | expect(image).toMatchImageSnapshot(getMatchOptions(options));
|
16 | },
|
17 | });
|
18 | };
|