132 lines
5.2 KiB
JavaScript
132 lines
5.2 KiB
JavaScript
// Live browser check for the web client: serve the page, open it in headless
|
|
// Chrome, connect to a running Pipelines server through the page's own proxy,
|
|
// and capture what actually rendered.
|
|
//
|
|
// node test/ui-smoke.mjs [--port 8091] [--pipelines 127.0.0.1:8080] [--out DIR]
|
|
//
|
|
// This is the UI evidence a review stage produces: real screenshots of the
|
|
// rendered client, not a claim. It needs a running Pipelines server (the live one
|
|
// or a scratch one) and the installed Chrome; it has no npm dependencies.
|
|
import { spawn } from "node:child_process";
|
|
import { mkdir, rm } from "node:fs/promises";
|
|
import { tmpdir } from "node:os";
|
|
import { dirname, join, resolve } from "node:path";
|
|
import { fileURLToPath } from "node:url";
|
|
import { eventually, launchChrome } from "./browser.mjs";
|
|
|
|
const ROOT = resolve(dirname(fileURLToPath(import.meta.url)), "..");
|
|
|
|
function flag(argv, name, fallback) {
|
|
const i = argv.indexOf(name);
|
|
return i !== -1 && argv[i + 1] ? argv[i + 1] : fallback;
|
|
}
|
|
|
|
const port = Number(flag(process.argv, "--port", process.env.WEB_UI_PORT ?? 8091));
|
|
const pipelines = flag(process.argv, "--pipelines", process.env.PIPELINES_TARGET ?? "127.0.0.1:8080");
|
|
const out = resolve(
|
|
flag(process.argv, "--out", process.env.WEB_UI_OUT ?? join(tmpdir(), "pipelines-web-ui")),
|
|
);
|
|
|
|
const shots = [];
|
|
let serve = null;
|
|
let browser = null;
|
|
let page = null;
|
|
let failed = false;
|
|
|
|
function step(label) {
|
|
console.log(`• ${label}`);
|
|
}
|
|
|
|
try {
|
|
await mkdir(out, { recursive: true });
|
|
|
|
step(`serving web/ on 127.0.0.1:${port} (proxy /connect -> ${pipelines})`);
|
|
serve = spawn(process.execPath, ["serve.mjs", "--port", String(port), "--pipelines", pipelines], {
|
|
cwd: ROOT,
|
|
stdio: ["ignore", "pipe", "pipe"],
|
|
});
|
|
let serveLog = "";
|
|
serve.stdout.on("data", (chunk) => (serveLog += chunk.toString()));
|
|
serve.stderr.on("data", (chunk) => (serveLog += chunk.toString()));
|
|
await eventually(
|
|
async () => {
|
|
if (serve.exitCode != null) throw new Error(`serve.mjs exited: ${serveLog.trim().slice(-300)}`);
|
|
const res = await fetch(`http://127.0.0.1:${port}/`).catch(() => null);
|
|
return res?.ok;
|
|
},
|
|
{ what: "the page to be served" },
|
|
);
|
|
|
|
step("launching headless Chrome");
|
|
browser = await launchChrome({ width: 1440, height: 900 });
|
|
page = await browser.openPage(`http://127.0.0.1:${port}/`);
|
|
|
|
step("connecting the page to the server through its own proxy");
|
|
await page.fill("#url", `ws://127.0.0.1:${port}/connect`);
|
|
await page.click("#connectBtn");
|
|
await page.waitForSelector(".row-title", { timeout: 25000 });
|
|
await page.waitForText("connected", { timeout: 25000 });
|
|
const pipelineCount = await page.evaluate(
|
|
`document.querySelectorAll(".list button.row").length`,
|
|
);
|
|
if (!pipelineCount) throw new Error("connected but no pipelines rendered");
|
|
|
|
shots.push(await page.screenshot(`${out}/01-pipelines.png`));
|
|
console.log(` pipelines rendered: ${pipelineCount}`);
|
|
|
|
step("opening a pipeline detail");
|
|
await page.click(".list button.row");
|
|
await page.waitForSelector(".detail h2");
|
|
shots.push(await page.screenshot(`${out}/02-pipeline-detail.png`));
|
|
|
|
step("switching to Runs and opening a run detail");
|
|
await page.clickText("nav.tabs button.tab", "Runs");
|
|
await page.waitForSelector(".list button.row", { timeout: 25000 });
|
|
await page.click(".list button.row");
|
|
await page.waitForSelector(".detail h2", { timeout: 25000 });
|
|
shots.push(await page.screenshot(`${out}/03-run-detail.png`));
|
|
|
|
step("opening the Templates gallery");
|
|
await page.clickText("nav.tabs button.tab", "Templates");
|
|
await page.waitForSelector(".cards button.card", { timeout: 25000 });
|
|
shots.push(await page.screenshot(`${out}/04-templates-gallery.png`));
|
|
const templateCount = await page.evaluate(`document.querySelectorAll(".cards button.card").length`);
|
|
console.log(` templates rendered: ${templateCount}`);
|
|
|
|
step("opening a template detail (Summary)");
|
|
await page.click(".cards button.card");
|
|
await page.waitForSelector(".detail .tabstrip", { timeout: 25000 });
|
|
await page.waitForText("Key", { timeout: 25000 });
|
|
shots.push(await page.screenshot(`${out}/05-template-detail-summary.png`));
|
|
|
|
step("opening the template Source tab");
|
|
await page.clickText(".detail .tabstrip button.minitab", "Source");
|
|
await page.waitForText("Definition source", { timeout: 25000 });
|
|
shots.push(await page.screenshot(`${out}/06-template-source.png`));
|
|
|
|
console.log("\nUI SMOKE PASS");
|
|
for (const shot of shots) console.log(` ${shot}`);
|
|
} catch (error) {
|
|
failed = true;
|
|
console.error(`\nUI SMOKE FAIL: ${error.message}`);
|
|
if (page) {
|
|
try {
|
|
shots.push(await page.screenshot(`${out}/failure.png`));
|
|
console.error(` failure capture: ${shots.at(-1)}`);
|
|
console.error((await page.text()).split("\n").slice(0, 25).join("\n"));
|
|
} catch {
|
|
// the page may be gone; the error above is the real signal
|
|
}
|
|
}
|
|
} finally {
|
|
await page?.close().catch(() => {});
|
|
await browser?.close().catch(() => {});
|
|
serve?.kill("SIGTERM");
|
|
await eventually(async () => serve?.exitCode != null, { timeout: 5000, what: "serve exit" }).catch(
|
|
() => {},
|
|
);
|
|
if (!failed) await rm(`${out}/failure.png`, { force: true }).catch(() => {});
|
|
}
|
|
|
|
process.exit(failed ? 1 : 0);
|