61 lines
2.3 KiB
JavaScript
61 lines
2.3 KiB
JavaScript
// G0/G4 · Playwright 截图矩阵——亲验渲染,不再纯靠代码推理
|
|
// 用法: node scripts/shot.mjs [--demo-only]
|
|
// 产物: shots/{page}-{theme}.png + shots/demo-{theme}.png
|
|
import { chromium } from 'playwright'
|
|
import { mkdirSync } from 'node:fs'
|
|
|
|
const BASE = process.env.SHOT_BASE ?? 'http://127.0.0.1:5173'
|
|
const DEMO = 'file:///data/go-sms/docs/design/demo-c-aurora.html'
|
|
const OUT = new URL('../shots/', import.meta.url).pathname
|
|
mkdirSync(OUT, { recursive: true })
|
|
|
|
const PAGES = [
|
|
['home', '/home'],
|
|
['account', '/account'],
|
|
['sms-batch', '/sms/batch'],
|
|
['channel', '/channel'],
|
|
['sms-downlink-detail', '/sms/downlink-detail'],
|
|
]
|
|
|
|
const browser = await chromium.launch()
|
|
const ctx = await browser.newContext({ viewport: { width: 1440, height: 900 } })
|
|
const page = await ctx.newPage()
|
|
|
|
async function shotApp(name, path, dark) {
|
|
await page.goto(BASE + path, { waitUntil: 'networkidle' })
|
|
await page.evaluate((d) => {
|
|
localStorage.setItem('gosms_dark', d ? '1' : '0')
|
|
document.documentElement.classList.toggle('dark', d)
|
|
}, dark)
|
|
await page.waitForTimeout(900) // stagger 入场动画走完
|
|
await page.screenshot({ path: `${OUT}${name}-${dark ? 'dark' : 'light'}.png` })
|
|
console.log(`✓ ${name}-${dark ? 'dark' : 'light'}.png`)
|
|
}
|
|
|
|
if (!process.argv.includes('--demo-only')) {
|
|
// 登录(mock:admin/admin123)
|
|
await page.goto(BASE + '/login', { waitUntil: 'networkidle' })
|
|
await page.getByTestId('login-username').fill('admin')
|
|
await page.getByTestId('login-password').fill('admin123')
|
|
await page.getByTestId('login-submit').click()
|
|
await page.waitForURL('**/home', { timeout: 15000 })
|
|
await page.screenshot({ path: `${OUT}login-after.png` })
|
|
console.log('✓ login-after.png')
|
|
for (const [name, path] of PAGES) {
|
|
await shotApp(name, path, true)
|
|
await shotApp(name, path, false)
|
|
}
|
|
}
|
|
|
|
// demo 基准(同视口,便于 ui_diff_check 对照)
|
|
const dpage = await browser.newPage({ viewport: { width: 1440, height: 900 } })
|
|
await dpage.goto(DEMO, { waitUntil: 'networkidle' })
|
|
await dpage.waitForTimeout(900)
|
|
await dpage.screenshot({ path: `${OUT}demo-dark.png` })
|
|
await dpage.locator('#themeBtn').click()
|
|
await dpage.waitForTimeout(400)
|
|
await dpage.screenshot({ path: `${OUT}demo-light.png` })
|
|
console.log('✓ demo-dark.png / demo-light.png')
|
|
|
|
await browser.close()
|