feat: harden CAD showcase skill and delivery pipeline
This commit is contained in:
76
scripts/web_smoke_test.mjs
Normal file
76
scripts/web_smoke_test.mjs
Normal file
@@ -0,0 +1,76 @@
|
||||
#!/usr/bin/env node
|
||||
/** Browser smoke test for the served Three.js showcase viewer. */
|
||||
|
||||
import fs from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
|
||||
function arg(name, fallback = null) {
|
||||
const index = process.argv.indexOf(name);
|
||||
return index >= 0 && process.argv[index + 1] ? process.argv[index + 1] : fallback;
|
||||
}
|
||||
|
||||
const url = arg("--url");
|
||||
const out = arg("--out", "browser_smoke_report.json");
|
||||
const shots = arg("--screenshots-dir", "browser_smoke");
|
||||
if (!url) {
|
||||
throw new Error("Usage: web_smoke_test.mjs --url http://127.0.0.1:8188 --out report.json");
|
||||
}
|
||||
|
||||
let chromium;
|
||||
try {
|
||||
({ chromium } = await import("playwright"));
|
||||
} catch (error) {
|
||||
throw new Error("Missing Playwright. Install with: npm install -D playwright && npx playwright install chromium", { cause: error });
|
||||
}
|
||||
|
||||
await fs.mkdir(shots, { recursive: true });
|
||||
const browser = await chromium.launch({ headless: true });
|
||||
const consoleErrors = [];
|
||||
const pageErrors = [];
|
||||
const failedRequests = [];
|
||||
const checks = [];
|
||||
|
||||
async function inspect(viewport, name) {
|
||||
const page = await browser.newPage({ viewportSize: viewport });
|
||||
page.on("console", (message) => {
|
||||
if (message.type() === "error") consoleErrors.push(message.text());
|
||||
});
|
||||
page.on("pageerror", (error) => pageErrors.push(error.message));
|
||||
page.on("requestfailed", (request) => failedRequests.push(`${request.url()} ${request.failure()?.errorText || "failed"}`));
|
||||
await page.goto(url, { waitUntil: "networkidle", timeout: 60000 });
|
||||
await page.waitForSelector("#loading", { state: "hidden", timeout: 60000 });
|
||||
const selectors = ["#floor-controls", "#category-controls", "#explode", "#section", "#snapshot"];
|
||||
for (const selector of selectors) {
|
||||
const visible = await page.locator(selector).isVisible();
|
||||
checks.push({ name: `${name}:${selector}`, status: visible ? "PASS" : "FAIL" });
|
||||
}
|
||||
await page.waitForTimeout(1200);
|
||||
const before = await page.evaluate(() => window.__renders || 0);
|
||||
await page.waitForTimeout(1500);
|
||||
const after = await page.evaluate(() => window.__renders || 0);
|
||||
checks.push({ name: `${name}:idle-render`, status: after === before ? "PASS" : "FAIL", detail: `${before}->${after}` });
|
||||
await page.screenshot({ path: path.join(shots, `${name}.png`), fullPage: true });
|
||||
await page.close();
|
||||
}
|
||||
|
||||
try {
|
||||
await inspect({ width: 1440, height: 900 }, "desktop");
|
||||
await inspect({ width: 390, height: 844 }, "mobile");
|
||||
} finally {
|
||||
await browser.close();
|
||||
}
|
||||
|
||||
const failedChecks = checks.filter((item) => item.status === "FAIL");
|
||||
const status = failedChecks.length || consoleErrors.length || pageErrors.length || failedRequests.length ? "FAIL" : "PASS";
|
||||
const report = {
|
||||
status,
|
||||
detail: `${checks.length - failedChecks.length}/${checks.length} checks passed`,
|
||||
url,
|
||||
checks,
|
||||
console_errors: consoleErrors,
|
||||
page_errors: pageErrors,
|
||||
failed_requests: failedRequests,
|
||||
};
|
||||
await fs.writeFile(out, JSON.stringify(report, null, 2));
|
||||
process.stdout.write(`${JSON.stringify({ status, report: out })}\n`);
|
||||
if (status === "FAIL") process.exitCode = 3;
|
||||
Reference in New Issue
Block a user