-
Notifications
You must be signed in to change notification settings - Fork 319
/
all.test.js
56 lines (42 loc) · 1.74 KB
/
all.test.js
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
/**
* @jest-environment puppeteer
*/
const { fetch } = require('undici')
const { WebSocket } = require('ws')
const { allComponents, getFiles } = require('../../../lib/file-helper')
const configPaths = require('../../../config/paths.js')
const PORT = configPaths.ports.test
const baseUrl = 'http://localhost:' + PORT
describe('Visual regression via Percy', () => {
let percySnapshot
let componentsWithJavaScript
beforeAll(async () => {
// Polyfill fetch() detection, upload via WebSocket()
// Fixes Percy running in a non-browser environment
global.window = { fetch, WebSocket }
percySnapshot = require('@percy/puppeteer')
// Filter "JavaScript enabled" components only
componentsWithJavaScript = allComponents
// Get file listing per component
.map((component) => [component, getFiles(`${configPaths.components}${component}`)])
// Filter for "JavaScript enabled" via `${component}.mjs`
.filter(([component, entries]) => entries.includes(`${component}.mjs`))
// Component names only
.map(([component]) => component)
})
it('generate screenshots', async () => {
for (const component of allComponents) {
await page.setJavaScriptEnabled(true)
// Screenshot preview page (with JavaScript)
await page.goto(baseUrl + '/components/' + component + '/preview', { waitUntil: 'load' })
await percySnapshot(page, `js: ${component}`)
// Check for "JavaScript enabled" components
if (componentsWithJavaScript.includes(component)) {
await page.setJavaScriptEnabled(false)
// Screenshot preview page (without JavaScript)
await page.reload({ waitUntil: 'load' })
await percySnapshot(page, `no-js: ${component}`)
}
}
}, 120000)
})