/** * Shared helpers for the Freezmo browser suites. * * The suites run against a locally running production build: * npm run build && systemctl --user restart freezmo * npm run test:e2e * * The browser is the system Playwright Chromium (CHROME env var wins), so * nothing is downloaded and nothing lives outside the repo. */ import { chromium } from "playwright-core"; import { spawn } from "node:child_process"; import { existsSync, readdirSync, readFileSync } from "node:fs"; import { createRequire } from "node:module"; import os from "node:os"; import path from "node:path"; export const BASE = process.env.FREEZMO_URL || "http://127.0.0.1:3207"; export const REPO = path.resolve(new URL("..", import.meta.url).pathname); /** * Where suites that spawn their own `next start` instances run from. Defaults * to the repo the tests live in; scripts/deploy.sh points it at the release * checkout so the pre-switch e2e run is hermetic. */ export const SPAWN_CWD = process.env.FREEZMO_SPAWN_CWD || REPO; /* ------------------------------------------------------------------ */ /* Browser */ /* ------------------------------------------------------------------ */ export function resolveChrome() { if (process.env.CHROME && existsSync(process.env.CHROME)) return process.env.CHROME; const roots = [ path.join(os.homedir(), ".cache", "ms-playwright"), path.join(os.homedir(), "Library", "Caches", "ms-playwright"), ]; const binaries = [ "chrome-linux64/chrome", "chrome-linux/chrome", "chrome-mac-arm64/Google Chrome for Testing.app/Contents/MacOS/Google Chrome for Testing", "chrome-mac/Google Chrome for Testing.app/Contents/MacOS/Google Chrome for Testing", "chrome-mac/Chromium.app/Contents/MacOS/Chromium", ]; for (const root of roots.filter((dir) => existsSync(dir))) { const dirs = readdirSync(root) .filter((entry) => /^chromium-\d+$/.test(entry)) .sort((a, b) => Number(b.split("-")[1]) - Number(a.split("-")[1])); for (const dir of dirs) { for (const sub of binaries) { const candidate = path.join(root, dir, sub); if (existsSync(candidate)) return candidate; } } } throw new Error( "No Chromium found. Set CHROME=/path/to/chrome, or install one with `npx playwright install chromium`.", ); } export const CHROME = resolveChrome(); export async function launchBrowser() { return chromium.launch({ executablePath: CHROME, /* The podcast player plays generated audio through an