83 lines
2.6 KiB
JavaScript
83 lines
2.6 KiB
JavaScript
import { chromium } from "playwright";
|
|
import { spawn, spawnSync } from "node:child_process";
|
|
import { mkdirSync } from "node:fs";
|
|
import { resolve } from "node:path";
|
|
import {
|
|
runOpinionRoundFocusRegression,
|
|
runParkedDraftSliceRegression,
|
|
runCaptionVisibilityRegression,
|
|
} from "./platform-feedback.mjs";
|
|
const output = resolve("local-data/test-results/platform-feedback");
|
|
mkdirSync(output, { recursive: true });
|
|
const media = resolve(output, "synthetic.mp4");
|
|
const generated = spawnSync("ffmpeg", [
|
|
"-v",
|
|
"error",
|
|
"-y",
|
|
"-f",
|
|
"lavfi",
|
|
"-i",
|
|
"color=c=black:s=160x90:r=10",
|
|
"-t",
|
|
"8",
|
|
"-c:v",
|
|
"libx264",
|
|
"-pix_fmt",
|
|
"yuv420p",
|
|
media,
|
|
]);
|
|
if (generated.status !== 0) throw Error("Cannot generate synthetic browser media");
|
|
const server = spawn(
|
|
process.execPath,
|
|
[
|
|
"node_modules/vite/bin/vite.js",
|
|
"--config",
|
|
"tests/browser/vite.platform-feedback.config.ts",
|
|
"--host",
|
|
"127.0.0.1",
|
|
"--port",
|
|
"5191",
|
|
"--strictPort",
|
|
],
|
|
{ stdio: ["ignore", "pipe", "pipe"], env: { ...process.env, CAPTURE_WORKBENCH_MOCK_VIDEO: media } },
|
|
);
|
|
let browser;
|
|
try {
|
|
const origin = "http://127.0.0.1:5191";
|
|
let ready = false;
|
|
for (let i = 0; i < 100; i++) {
|
|
try {
|
|
if ((await fetch(origin)).ok) {
|
|
ready = true;
|
|
break;
|
|
}
|
|
} catch {}
|
|
if (server.exitCode !== null) break;
|
|
await new Promise((r) => setTimeout(r, 100));
|
|
}
|
|
if (!ready) throw Error("Local synthetic fixture server did not start");
|
|
browser = await chromium.launch({
|
|
...(process.env.BROWSER_EXECUTABLE ? { executablePath: process.env.BROWSER_EXECUTABLE } : {}),
|
|
headless: true,
|
|
args: ["--no-proxy-server"],
|
|
});
|
|
const page = await browser.newPage({ viewport: { width: 1600, height: 1000 } });
|
|
page.setDefaultTimeout(5000);
|
|
page.on("pageerror", (error) => console.error("Fixture page error:", error.message));
|
|
page.on("console", (message) => {
|
|
if (message.type() === "error") console.error("Fixture console:", message.text());
|
|
});
|
|
const tab = {
|
|
goto: (url) => page.goto(url),
|
|
playwright: page,
|
|
pressKey: (_, key) => page.keyboard.press(key === "Return" ? "Enter" : key),
|
|
};
|
|
const which = process.argv[2];
|
|
if (!which || which === "rail") console.log(JSON.stringify(await runOpinionRoundFocusRegression(tab, origin)));
|
|
if (!which || which === "drafts") console.log(JSON.stringify(await runParkedDraftSliceRegression(tab, origin)));
|
|
if (!which || which === "captions") console.log(JSON.stringify(await runCaptionVisibilityRegression(tab, origin)));
|
|
} finally {
|
|
await browser?.close();
|
|
server.kill("SIGTERM");
|
|
}
|