packRuns

tcmts.cli.suites.packRuns · #m4e2aqge · term · runs anywhere

Kept runs, by suite, as the codebase keeps them (its suites setting): each name a run executed is written once, and runs name them by index, since suites run much of the same code.

import type { SuiteRun } from "#codebase/tcmts/cli/suites";

export function packRuns(runs: Record<string, SuiteRun[]>): string {
  const names: string[] = [];
  const index = new Map<string, number>();
  const at = (name: string) => {
    let i = index.get(name);
    if (i === undefined) {
      i = names.length;
      names.push(name);
      index.set(name, i);
    }
    return i;
  };
  const packed = Object.fromEntries(
    Object.entries(runs)
      .filter(([, rs]) => rs.length > 0)
      .map(([slot, rs]) => [slot, rs.map((r) => ({ ...r, ran: r.ran.map(at) }))]),
  );
  return JSON.stringify({ names, runs: packed });
}

uses

used by