-
Notifications
You must be signed in to change notification settings - Fork 0
/
snapshots.ts
57 lines (41 loc) · 1.39 KB
/
snapshots.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
import { chromium, devices } from 'playwright'
import storybookIndexJson from './storybook-static/index.json'
const parallel = 8
;(async () => {
const stories = Object.values(storybookIndexJson.entries).filter(
({ type }) => type === 'story',
)
const browsers = await Promise.all(
[...new Array(parallel)].map(async () => await chromium.launch()),
)
await Promise.all(
stories.map(async (story, index) => {
const startTime = performance.now()
const browser = browsers[index % parallel]
const chrome = devices['Desktop Chrome']
const context = await browser.newContext({
locale: 'ja',
timezoneId: 'Asia/Tokyo',
viewport: chrome.viewport,
userAgent: chrome.userAgent,
})
const page = await context.newPage()
await page.goto(`http://localhost:5000/iframe.html?id=${story.id}`, {
waitUntil: 'domcontentloaded',
})
await page.waitForSelector('#storybook-root')
await page.screenshot({
path: `./screenshots/${story.id}.png`,
fullPage: true,
animations: 'disabled',
})
await context.close()
const endTime = performance.now()
console.log(
`[INFO] Saving screenshot for ${story.id} (${Math.floor(endTime - startTime)}ms)`,
)
}),
)
await Promise.all(browsers.map(async (browser) => await browser.close()))
process.exit(0)
})()