-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscreenshot.spec.ts
64 lines (50 loc) · 1.57 KB
/
screenshot.spec.ts
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import {toMatchImageSnapshot} from "jest-image-snapshot"
import puppeteer, {Browser, Page} from "puppeteer"
import opts from "./config"
import { sync } from "globby"
import {basename} from "path"
expect.extend({toMatchImageSnapshot})
const {
launch,
goto,
waitFor,
viewport,
screenshot,
outFolder,
ext
} = opts
, {env} = process
let browser: Browser, page :Page
beforeAll(async () => {
browser = await puppeteer.launch(launch)
page = await browser.newPage()
})
afterAll(async () => {
await page.close()
await browser.close()
})
sync(`${outFolder}/*${ext}`, {absolute: true})
.forEach((filePath) => {
const fileBase = basename(filePath, ext)
it(fileBase, async () => {
await page.goto(`file://${filePath}`, goto)
waitFor && await page.waitFor(waitFor)
viewport && await page.setViewport(viewport)
const screenshotData = await page.screenshot(screenshot)
expect(screenshotData).toMatchImageSnapshot({
"customSnapshotIdentifier": fileBase,
"dumpDiffToConsole": true,
"failureThresholdType": "percent",
"failureThreshold": +(env.npm_config_threshold ?? ''),
"blur": +(env.npm_config_blur ?? '')
})
})
})
/** @see https://github.com/microsoft/playwright/issues/3509#issuecomment-675441299 */
it.skip("pdf https://bugs.chromium.org/p/chromium/issues/detail?id=761295", async () => {
// await page.goto(`file://${baseName}.pdf`, goto)
// const screenshotData = await page.screenshot(screenshot)
// expect(screenshotData).toMatchImageSnapshot( {
// "customSnapshotIdentifier": `${fileName}-pdf`
// })
})