import { test, expect } from "@playwright/test"; import { writeFile } from "node:fs/promises"; test("production analyzer matches the reviewed screenshot corpus", async ({ page }, testInfo) => { const fixture = process.env.FIXTURE_ID; await page.goto(fixture ? `/fixture.html?fixture=${encodeURIComponent(fixture)}` : "/fixture.html"); const result = await page.evaluate(() => window.__fixtureRun); await writeFile(testInfo.outputPath("fixture-report.json"), JSON.stringify(result, null, 2)); const artifacts = await page.evaluate(() => window.__fixtureArtifacts); for (const [fixtureId, artifact] of Object.entries(artifacts)) { const images = [ ["overlay", artifact.preview], ...artifact.stages.map(({ key, image }) => [key, image]), ]; for (const [label, dataUrl] of images) { if (!dataUrl) continue; const [, encoded] = dataUrl.split(",", 2); const extension = dataUrl.startsWith("data:image/png") ? "png" : "jpg"; await writeFile( testInfo.outputPath(`${fixtureId}-${label}.${extension}`), Buffer.from(encoded, "base64"), ); } } expect(result.total).toBeGreaterThan(0); expect(result.completed).toBe(result.total); if (!fixture) expect(result.completed).toBe(17); expect(result.failures, result.failures.join("\n")).toEqual([]); });