-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathjest.utils.js
More file actions
39 lines (32 loc) · 961 Bytes
/
jest.utils.js
File metadata and controls
39 lines (32 loc) · 961 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import puppeteer from 'puppeteer';
import { resolve } from 'path';
import { toMatchImageSnapshot } from 'jest-image-snapshot';
expect.extend({ toMatchImageSnapshot });
const browserLaunchOptions = {
args: [
'--no-sandbox',
'--disable-setuid-sandbox',
'--disable-background-timer-throttling',
'--disable-backgrounding-occluded-windows',
'--disable-renderer-backgrounding'
]
};
export function testScreenshot(name, file) {
test(name, async () => {
const browser = await puppeteer.launch(browserLaunchOptions);
try {
const page = await browser.newPage();
await page.goto(`http://localhost:8080/tests/${file}`);
const image = await page.screenshot();
expect(image).toMatchImageSnapshot({
customSnapshotsDir: resolve(__dirname, 'reference_images'),
failureThreshold: 0.05,
failureThresholdType: 'percent'
});
await browser.close();
} catch (error) {
await browser.close();
throw error;
}
}, 30000);
}