#!/usr/bin/env node /** * Opens a generated report in the default browser. * * node scripts/open-report.mjs the evidence report * node scripts/open-report.mjs playwright Playwright's own HTML report */ import { spawn } from 'node:child_process'; import { existsSync } from 'node:fs'; import { dirname, join, resolve } from 'node:path'; import { fileURLToPath } from 'node:url'; const ROOT = resolve(dirname(fileURLToPath(import.meta.url)), '..'); const which = process.argv[2] ?? 'evidence'; const target = which === 'playwright' ? join(ROOT, 'e2e', 'playwright-report', 'index.html') : join(ROOT, 'e2e', 'evidence-report', 'index.html'); if (!existsSync(target)) { console.error(`No report at ${target}\nRun the suite first: npm run test:e2e`); process.exit(1); } // Each platform has its own opener; none of them need a dependency. const [command, args] = process.platform === 'win32' ? ['cmd', ['/c', 'start', '', target]] : process.platform === 'darwin' ? ['open', [target]] : ['xdg-open', [target]]; spawn(command, args, { detached: true, stdio: 'ignore' }).unref(); console.log(`Opened ${target}`);