testPsListsWhatsRunning
tcm ps lists a tcm start while it runs, with the app it runs, its branch and where it's listening; once it's
stopped, it isn't listed (its record went with it).
import { plainEnv, strip, tcmBin, withChildren } from "#codebase/tcmts/cli/test/e2e/harness"; import { setUp, waitFor } from "#codebase/tcmts/cli/test/e2e/prod"; import assert from "node:assert/strict"; import { spawn } from "node:child_process"; export const testPsListsWhatsRunning = () => withChildren(async (keep) => { const { dir, tcm, scratch } = setUp(); assert.match(strip(tcm("ps")), /nothing tcm runs is running on this codebase/); scratch(`// tcm: namespace app export function main() { document.querySelector("#app")!.textContent = "hello"; } `); tcm("add"); const child = keep( spawn(process.execPath, [tcmBin(), "start", "app.main", "--port", "0"], { cwd: dir, env: plainEnv(), }), ); let out = ""; child.stdout!.setEncoding("utf8").on("data", (d: string) => (out += d)); child.stderr!.setEncoding("utf8").on("data", (d: string) => (out += d)); await waitFor(() => /url\s+http:\/\/\S+/.test(out)); const url = /url\s+(http:\/\/\S+)/.exec(out)![1]!; const listed = strip(tcm("ps")); const line = listed.split("\n").find((l) => l.includes("start app.main")); assert.ok(line, listed); assert.ok(line.includes(String(child.pid)), listed); assert.ok(line.includes(url), listed); assert.match(line, /\bmain\b.*\bhttp/, listed); child.kill(); await new Promise((r) => child.once("exit", r)); assert.match(strip(tcm("ps")), /nothing tcm runs is running on this codebase/); })