|
| 1 | +// Spawns the warm process under each harness variant and reports whether its Chrome finished starting. |
| 2 | +import { spawn, execFileSync } from "node:child_process"; |
| 3 | +import { mkdtempSync, writeFileSync, readFileSync, existsSync } from "node:fs"; |
| 4 | +import { tmpdir } from "node:os"; |
| 5 | +import { join } from "node:path"; |
| 6 | +const cli = join(process.cwd(), "packages/cli"); |
| 7 | +const fx = mkdtempSync(join(tmpdir(), "fx-")); |
| 8 | +writeFileSync(join(fx, "index.html"), `<!doctype html><html><body><div data-composition-id="main" data-width="320" data-height="180" data-duration="1"><p>Warm</p></div><script>window.__timelines={main:{duration:()=>1,seek:()=>{},pause:()=>{}}};</script></body></html>`); |
| 9 | +const variants = []; |
| 10 | +for (const entry of ["tsx", "dist"]) for (const stdio of ["pipe", "ignore"]) for (const detached of [false, true]) for (const lad of ["inherit", "temp"]) variants.push({ entry, stdio, detached, lad }); |
| 11 | +for (const v of variants) { |
| 12 | + const log = join(mkdtempSync(join(tmpdir(), "dbg-")), "log.txt"); |
| 13 | + const env = { ...process.env, HF_WARM_DBG: log, HYPERFRAMES_NO_TELEMETRY: "1" }; |
| 14 | + if (v.lad === "temp") env.LOCALAPPDATA = mkdtempSync(join(tmpdir(), "lad-")); |
| 15 | + const args = v.entry === "tsx" ? ["--import", "tsx", "src/warmCheck.ts"] : ["dist/warmCheck.js"]; |
| 16 | + const start = Date.now(); |
| 17 | + const child = spawn(process.execPath, [...args, "60000", fx, "--json", "--no-browser-gpu", "--samples=1"], { |
| 18 | + cwd: cli, env, detached: v.detached, stdio: v.stdio === "pipe" ? ["ignore", "pipe", "pipe"] : "ignore", windowsHide: true, |
| 19 | + }); |
| 20 | + child.stdout?.on("data", () => {}); child.stderr?.on("data", () => {}); |
| 21 | + let result = "timeout"; |
| 22 | + while (Date.now() - start < 45_000) { |
| 23 | + const text = existsSync(log) ? readFileSync(log, "utf8") : ""; |
| 24 | + const m = text.match(/launched (true|false)/); |
| 25 | + if (m) { result = m[1] === "true" ? "LAUNCHED" : "FAILED"; break; } |
| 26 | + await new Promise((r) => setTimeout(r, 200)); |
| 27 | + } |
| 28 | + console.log(JSON.stringify(v), result, `${Date.now() - start} ms`); |
| 29 | + try { execFileSync("taskkill", ["/T", "/F", "/PID", String(child.pid)], { stdio: "ignore" }); } catch {} |
| 30 | + await new Promise((r) => setTimeout(r, 1000)); |
| 31 | +} |
0 commit comments