testPublicServerStartsTheWebUiAhead
a public tcm serve starts its web UI as it starts listening, before anyone asks for it, so its first reader doesn't wait for its build
import { codebase, env, LIB, uiPage } from "#codebase/tcmts/cli/test/e2e/contributions"; import { strip, tcmBin, tempDir, withChildren } from "#codebase/tcmts/cli/test/e2e/harness"; import assert from "node:assert/strict"; import { spawn } from "node:child_process"; export const testPublicServerStartsTheWebUiAhead = async () => { const server = codebase(tempDir("contributions ahead"), "served"); server.write(LIB); server.tcm("add"); await withChildren(async (keep) => { const child = keep( spawn(process.execPath, [tcmBin(), "serve", "--port", "0", "--token", "tok", "--public"], { cwd: server.dir, env: env(), }), ); let out = ""; child.stdout.setEncoding("utf8").on("data", (d: string) => (out += d)); child.stderr.setEncoding("utf8").on("data", (d: string) => (out += d)); // (nothing asks for /forge/: the UI says it's listening by itself) const until = Date.now() + 120_000; let ui: RegExpExecArray | null = null; while (!(ui = /ui\s+url\s+(https?:\/\/[\d.]+:\d+)/.exec(strip(out))) && Date.now() < until) await new Promise((r) => setTimeout(r, 100)); assert.ok(ui, out); const url = /url\s+(https?:\/\/[\d.]+:\d+)/.exec(out)![1]!; const page = await uiPage(`${url}/forge/people`); assert.equal(page.status, 200, page.html); }); }