|
| 1 | +#!/usr/bin/env node |
| 2 | +/** |
| 3 | + * Capture documentation screenshots for the Dream Progress panel. |
| 4 | + * |
| 5 | + * The dev server must already be running at the URL passed in via PREVIEW_URL |
| 6 | + * (defaults to http://localhost:5178). The /dream-progress showcase route is |
| 7 | + * DEV-only and renders three variants of the panel against mock data. |
| 8 | + * |
| 9 | + * Usage: |
| 10 | + * PREVIEW_URL=http://localhost:5178 OUT_DIR=../../docs/screenshots/live-dream-progress \ |
| 11 | + * node scripts/screenshot-dream-progress.mjs |
| 12 | + */ |
| 13 | +import { mkdir } from "node:fs/promises"; |
| 14 | +import path from "node:path"; |
| 15 | +import { fileURLToPath } from "node:url"; |
| 16 | +import { chromium } from "@playwright/test"; |
| 17 | + |
| 18 | +const __filename = fileURLToPath(import.meta.url); |
| 19 | +const __dirname = path.dirname(__filename); |
| 20 | + |
| 21 | +const PREVIEW_URL = process.env.PREVIEW_URL ?? "http://localhost:5178"; |
| 22 | +const OUT_DIR = path.resolve( |
| 23 | + __dirname, |
| 24 | + process.env.OUT_DIR ?? "../../../docs/screenshots/live-dream-progress", |
| 25 | +); |
| 26 | + |
| 27 | +async function main() { |
| 28 | + await mkdir(OUT_DIR, { recursive: true }); |
| 29 | + const browser = await chromium.launch(); |
| 30 | + const context = await browser.newContext({ |
| 31 | + viewport: { width: 1440, height: 900 }, |
| 32 | + deviceScaleFactor: 2, |
| 33 | + colorScheme: "dark", |
| 34 | + }); |
| 35 | + const page = await context.newPage(); |
| 36 | + |
| 37 | + // Seed localStorage with a fake instance so the root redirect doesn't kick |
| 38 | + // us to the settings page. The showcase doesn't actually make any network |
| 39 | + // requests — it renders against in-memory mock data. |
| 40 | + await page.addInitScript(() => { |
| 41 | + localStorage.setItem( |
| 42 | + "openconcho:instances", |
| 43 | + JSON.stringify({ |
| 44 | + instances: [ |
| 45 | + { |
| 46 | + id: "inst_dev_demo", |
| 47 | + name: "Demo (mock)", |
| 48 | + baseUrl: "http://localhost:9999", |
| 49 | + token: "", |
| 50 | + }, |
| 51 | + ], |
| 52 | + activeId: "inst_dev_demo", |
| 53 | + }), |
| 54 | + ); |
| 55 | + }); |
| 56 | + |
| 57 | + await page.goto(`${PREVIEW_URL}/dream-progress`, { waitUntil: "networkidle" }); |
| 58 | + await page.waitForSelector('[data-testid="dream-progress-panel"]'); |
| 59 | + // Let framer-motion entrance animations settle. |
| 60 | + await page.waitForTimeout(600); |
| 61 | + |
| 62 | + // Full showcase — top-to-bottom view of all three variants. |
| 63 | + await page.screenshot({ |
| 64 | + path: path.join(OUT_DIR, "overview.png"), |
| 65 | + fullPage: true, |
| 66 | + }); |
| 67 | + |
| 68 | + // Variant: idle |
| 69 | + { |
| 70 | + const handle = await page.locator("section").nth(0); |
| 71 | + await handle.scrollIntoViewIfNeeded(); |
| 72 | + await page.waitForTimeout(150); |
| 73 | + await handle.screenshot({ path: path.join(OUT_DIR, "idle.png") }); |
| 74 | + } |
| 75 | + |
| 76 | + // Variant: active (with per-session breakdown) |
| 77 | + { |
| 78 | + const handle = await page.locator("section").nth(1); |
| 79 | + await handle.scrollIntoViewIfNeeded(); |
| 80 | + await page.waitForTimeout(150); |
| 81 | + await handle.screenshot({ path: path.join(OUT_DIR, "active.png") }); |
| 82 | + } |
| 83 | + |
| 84 | + // Variant: stalled (>30m without forward progress) |
| 85 | + { |
| 86 | + const handle = await page.locator("section").nth(2); |
| 87 | + await handle.scrollIntoViewIfNeeded(); |
| 88 | + await page.waitForTimeout(150); |
| 89 | + await handle.screenshot({ path: path.join(OUT_DIR, "stalled.png") }); |
| 90 | + } |
| 91 | + |
| 92 | + await browser.close(); |
| 93 | + console.log(`Saved screenshots to ${OUT_DIR}`); |
| 94 | +} |
| 95 | + |
| 96 | +main().catch((err) => { |
| 97 | + console.error(err); |
| 98 | + process.exit(1); |
| 99 | +}); |
0 commit comments