Skip to content

Commit 03b4d87

Browse files
committed
screenshots: rewrite and enable linting
1 parent 1345493 commit 03b4d87

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

src/ci/screenshots.cjs src/ci/screenshots.ts

+8-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
/* eslint-disable */
2-
const fs = require('node:fs')
3-
const { chromium, devices } = require('playwright')
1+
import fs from 'node:fs'
2+
import { chromium, devices, type BrowserContext, type BrowserContextOptions } from 'playwright'
43

54
const baseUrl = process.argv[2]
65
const outDir = process.argv[3] || 'screenshots'
@@ -11,29 +10,29 @@ const endpoints = {
1110
SettingsActivity: '1d3dc3e03047b0c7/settings',
1211
}
1312

14-
async function takeScreenshots(deviceType, context) {
13+
async function takeScreenshots(deviceType: string, context: BrowserContext) {
1514
const page = await context.newPage()
1615
for (const [route, path] of Object.entries(endpoints)) {
1716
await page.goto(`${baseUrl}/${path}`, { waitUntil: 'networkidle' })
18-
await page.waitForTimeout(2000)
17+
await page.waitForTimeout(500)
1918
await page.screenshot({ path: `${outDir}/${route}-${deviceType}.playwright.png` })
2019
console.log(`${route}-${deviceType}.playwright.png`)
2120

2221
if (route === 'Login') {
23-
await page.click(`button:has-text('Try the demo')`, { waitUntil: 'networkidle' })
24-
await page.waitForTimeout(1000)
22+
await page.click('button:has-text(\'Try the demo\')')
23+
await page.waitForLoadState('networkidle')
2524
}
2625
}
2726
await page.close()
2827
}
2928

3029
async function main() {
31-
let executablePath = '/usr/bin/chromium'
30+
let executablePath: string | undefined = '/usr/bin/chromium'
3231
if (!fs.existsSync(executablePath)) executablePath = undefined
3332

3433
const browser = await chromium.launch({ executablePath, headless: true })
3534

36-
const contexts = [
35+
const contexts: [string, BrowserContextOptions][] = [
3736
['mobile', devices['iPhone 13']],
3837
['desktop', { viewport: { width: 1920, height: 1080 }}],
3938
]

0 commit comments

Comments
 (0)