startServerInfo

tcmts.cli.test.e2e.sync.startServerInfo · #uuix3lro · term · runs on the server

uses node:child_process

import type { Keep } from "#codebase/tcmts/cli/test/e2e/contributions";
import { plainEnv, tcmBin } from "#codebase/tcmts/cli/test/e2e/harness";
import { spawn } from "node:child_process";

export function startServerInfo(keep: Keep, dir: string, token: string, ...extra: string[]): Promise<{ url: string; fingerprint?: string }> {
  const child = keep(spawn(process.execPath, [tcmBin(), "serve", "--port", "0", "--token", token, ...extra], { cwd: dir, env: plainEnv() }));
  return new Promise((resolve, reject) => {
    let out = "";
    child.stdout.setEncoding("utf8").on("data", (d: string) => {
      out += d;
      const m = /url\s+(https?:\/\/[\d.]+:\d+)/.exec(out);
      const fp = /sha256 ([0-9A-F:]+)/.exec(out)?.[1];
      if (m && (!extra.includes("--tls") || fp)) resolve({ url: m[1]!, fingerprint: fp });
    });
    child.on("exit", (code) => reject(new Error(`server exited ${code}: ${out}`)));
  });
}

uses

used by