-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlostpixel.config.ts
60 lines (56 loc) · 1.59 KB
/
lostpixel.config.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
import type { Page } from 'playwright-core'
import { CustomProjectConfig } from 'lost-pixel'
import { join } from 'path'
import { readFileSync } from 'fs'
/**
* Hide 3rd party embeds.
*
* They're a distraction from 1st party diffs.
*/
async function hide3rdPartyEmbeds(page: Page) {
await page.addStyleTag({
content: `
.embed iframe,
.twitter-tweet iframe {
display: none !important;
}
`,
})
}
/**
* Parse the sitemap for all pages for visual regression testing to visit.
*
* The sitemap is an updated yet static list of all pages. "Parse" its XML with
* vanilla Node.js for the page URLs.
*/
function pagePaths(): string[] {
const siteUrl = 'https://johnkurkowski.com'
const sitemapXml = readFileSync(
join(__dirname, 'public', 'sitemap-0.xml'),
'utf-8',
)
const urlsRe = new RegExp(`${siteUrl}(/[^<]*)`, 'g')
return Array.from(sitemapXml.matchAll(urlsRe)).map(function ([, url]) {
return url.replaceAll('&', '&')
})
}
/**
* Id the pages by a friendlier, more uniform slug.
*/
function slugify(str: string): string {
const replaced = str.replaceAll('/', '-')
const stripped = replaced.replaceAll(/(^-+|-+$)/g, '')
return stripped ? stripped : 'index'
}
export const config: CustomProjectConfig = {
apiKey: process.env.LOST_PIXEL_API_KEY,
beforeScreenshot: async (page) => {
await hide3rdPartyEmbeds(page)
},
breakpoints: [414, 1280],
lostPixelProjectId: 'clud602ae10romo0e861bvpv2',
pageShots: {
pages: pagePaths().map((path) => ({ path, name: slugify(path) })),
baseUrl: 'http://172.17.0.1:9000',
},
}