jacquardSnapshot

← snapshot

2321 bytes
import { chromium } from "@playwright/test";

const BASE = "http://localhost:3000";
const API = "http://localhost:8787";

const repos = await (await fetch(`${API}/api/repos`)).json();
const slug = repos.repos.find(r => r.decisions.unsettled > 0)?.slug ?? repos.repos[0].slug;
const log = await (await fetch(`${API}/api/repos/${slug}/log?ref=main&limit=1`)).json();
const snap = log.entries?.[0]?.id ?? log.head?.id;
const decs = await (await fetch(`${API}/api/repos/${slug}/decisions`)).json();
const dec = (decs.decisions ?? []).find(d => d.state === "unsettled") ?? decs.decisions?.[0];

const other = repos.repos.map(r => r.slug).find(s => s !== slug);
const routes = [
  "/", "/new", "/registry", "/lab",
  `/repos/${slug}`,
  `/repos/${slug}/log`,
  `/repos/${slug}/decisions`,
  `/repos/${slug}/promote`,
  `/repos/${slug}/refs`,
  snap ? `/repos/${slug}/snapshots/${snap}` : null,
  snap ? `/repos/${slug}/snapshots/${snap}/tree` : null,
  `/repos/${slug}/diff`,
  dec ? `/repos/${slug}/decisions/${dec.id}` : null,
  other ? `/repos/${other}` : null,
  other ? `/repos/${other}/promote` : null,
  other ? `/repos/${other}/decisions` : null,
  other ? `/repos/${other}/diff` : null,
].filter(Boolean);

const browser = await chromium.launch();
const page = await browser.newPage({ viewport: { width: 1440, height: 950 }, colorScheme: "dark" });
let bad = 0;
for (const r of routes) {
  const errs = [];
  const onErr = m => { if (m.type() === "error") errs.push(m.text()); };
  const onPageErr = e => errs.push(`pageerror: ${e.message}`);
  page.on("console", onErr);
  page.on("pageerror", onPageErr);
  const resp = await page.goto(BASE + r, { waitUntil: "networkidle" });
  await page.waitForTimeout(900);
  const text = (await page.evaluate(() => document.body.innerText)).trim();
  page.off("console", onErr); page.off("pageerror", onPageErr);
  const status = resp?.status() ?? 0;
  const ok = status === 200 && text.length > 120 && errs.length === 0;
  if (!ok) bad++;
  console.log(`${ok ? "  ok" : "FAIL"}  ${String(status).padEnd(3)} ${String(text.length).padStart(5)}ch  ${r}`);
  for (const e of [...new Set(errs)].slice(0, 3)) console.log(`        ! ${e.slice(0, 140)}`);
}
console.log(`\nrepo: ${slug}   routes: ${routes.length}   failing: ${bad}`);
await browser.close();
process.exit(bad ? 1 : 0);