| 1 | import { chromium } from 'playwright'; |
| 2 | import { readFileSync, writeFileSync } from 'fs'; |
| 3 | |
| 4 | const SB = (process.env.SCRATCH || '/tmp/elffuss-test'); |
| 5 | const tpl = readFileSync(SB + '/og_template.html', 'utf8'); |
| 6 | const svgCode = readFileSync(new URL('../../elffuss-code/web/img/elffuss-code.svg', import.meta.url).pathname, 'utf8').replace(/`/g,'\\`'); |
| 7 | const svgClaw = readFileSync(new URL('../../elffuss-claw/web/img/elffuss.svg', import.meta.url).pathname, 'utf8').replace(/`/g,'\\`'); |
| 8 | const html = tpl.replace('__SVG_CODE__', svgCode).replace('__SVG_CLAW__', svgClaw); |
| 9 | writeFileSync(SB + '/og_built.html', html); |
| 10 | |
| 11 | const b = await chromium.launch(); |
| 12 | const ctx = await b.newContext({ viewport: { width: 1200, height: 630 }, deviceScaleFactor: 2 }); |
| 13 | const page = await ctx.newPage(); |
| 14 | for (const p of ['code','claw']) { |
| 15 | await page.goto('file://' + SB + '/og_built.html?p=' + p, { waitUntil: 'load' }); |
| 16 | await page.waitForFunction(() => window.__ready === true).catch(()=>{}); |
| 17 | await page.waitForTimeout(300); |
| 18 | const el = await page.$('.og'); |
| 19 | await el.screenshot({ path: `${SB}/og-${p}-en.png` }); |
| 20 | console.log('OK og-' + p + '-en.png'); |
| 21 | } |
| 22 | await b.close(); |