runInBudget

tcmts.cli.test.e2e.suites.runInBudget · #w67wio2y · term · runs on the server

uses node:child_process

tcm test in dir, in a budget of slots slots (in slotsDir), its output (stdout and stderr) as it came.

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

export const testInBudget = (dir: string, slotsDir: string, slots: number, log: string) => {
  // (not in this suite's slot, as what this runs would be: in a budget of their own)
  const { TCM_SUITE_SLOT: _, ...outer } = plainEnv();
  const env = { ...outer, TCM_SLOTS: String(slots), TCM_SLOTS_DIR: slotsDir, SLOT_LOG: log };
  return new Promise<{ status: number | null; out: string }>((resolve) => {
    const c = spawn(process.execPath, [tcmBin(), "test"], { cwd: dir, env });
    let out = "";
    c.stdout.setEncoding("utf8").on("data", (d: string) => (out += d));
    c.stderr.setEncoding("utf8").on("data", (d: string) => (out += d));
    c.on("close", (status) => resolve({ status, out: strip(out) }));
  });
}

uses

used by