Skip to content

Commit

Permalink
Add visual screenshot test
Browse files Browse the repository at this point in the history
  • Loading branch information
askirmas committed Aug 12, 2020
1 parent 00e4a26 commit f31cd2c
Show file tree
Hide file tree
Showing 8 changed files with 1,171 additions and 505 deletions.
Binary file modified Andrii_Kirmas.pdf
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 0 additions & 23 deletions cli/pdf.js

This file was deleted.

60 changes: 60 additions & 0 deletions cli/pdf.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import {toMatchImageSnapshot} from "jest-image-snapshot"
import puppeteer, {Browser, Page} from "puppeteer"

expect.extend({toMatchImageSnapshot})

const fileName = 'Andrii_Kirmas'
, cwd = process.cwd()

let browser: Browser, page :Page

beforeAll(async () => {
browser = await puppeteer.launch({
"args": ["--allow-file-access-from-files", "--enable-local-file-accesses "]
})
page = await browser.newPage()
})

it("web", async () => {
await page.goto(`file://${cwd}/index.html`, {
"waitUntil": "networkidle2"
})
await page.setViewport({ width: 1800, height: 980 })

const screenshot = await page.screenshot({
"fullPage": true,
"type": "png"
})

expect(screenshot).toMatchImageSnapshot( {
"customSnapshotIdentifier": `${fileName}-web`
})

if (process.env.npm_config_pdf_gen)
await page.pdf({
"path": `${cwd}/${fileName}.pdf`,
"format": "A4",
"printBackground": true,
"pageRanges": '1',
"scale": 0.70
})
})

it.skip("pdf https://bugs.chromium.org/p/chromium/issues/detail?id=761295", async () => {

await page.goto(`file://${cwd}/${fileName}.pdf`, {
"waitUntil": "networkidle2"
})

const screenshot = await page.screenshot({
"fullPage": true,
"type": "png"
})

expect(screenshot).toMatchImageSnapshot( {
"customSnapshotIdentifier": `${fileName}-pdf`
})
})


afterAll(async () => await browser.close())
4 changes: 4 additions & 0 deletions jest.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"preset": "ts-jest",
"testEnvironment": "node"
}
Loading

0 comments on commit f31cd2c

Please sign in to comment.