printOutcomes
uses node:path
A line per test, and why each failure failed: its message, and what it printed. Brief (TCM_BRIEF=1, as the MCP
server's tools run commands), a failure is the start of its message and where it failed (the first place in the
codebase's own definitions, which tcm at names), with the rest in a file the report names.
import { bold, dim, green, red } from "#codebase/tcmts/cli/style"; import type { TestOutcome } from "#codebase/tcmts/cli/testing"; import fs from "node:fs"; import os from "node:os"; import path_1 from "node:path"; export function printOutcomes(outcomes: TestOutcome[], indent = " ") { const brief = process.env.TCM_BRIEF === "1"; for (const o of outcomes) { const { ok, message, output, ms } = o.result; // a failure as before, with nothing it runs changed since, is worth saying: a fix that didn't save shows as this const meta = dim( o.cached ? "(cached)" : `${ms}ms${o.failedBefore ? " (it failed last time too, and nothing it runs changed since)" : ""}`, ); console.log(`${indent}${ok ? green("✓") : red("✗")} ${ok ? o.path : bold(o.path)} ${meta}`); if (ok) continue; if (!brief) { for (const line of message.split("\n")) console.log(`${indent} ${red(line)}`); if (output) for (const line of output.split("\n")) console.log(`${indent} ${dim("│ " + line)}`); continue; } const lines = message.split("\n"); for (const line of lines.slice(0, 12)) console.log(`${indent} ${red(line)}`); if (lines.length > 12) console.log(`${indent} ${dim(`… ${lines.length - 12} more line(s)`)}`); const at = /\(?((?:[^\s()]*[\\/])?\.tcm[\\/]src[\\/][^\s():]+:\d+(?::\d+)?)\)?/.exec( `${message}\n${output ?? ""}`, )?.[1]; if (at) console.log(`${indent} ${dim(`at ${at}`)}`); const file = path_1.join(os.tmpdir(), `tcm-test-${o.path.replace(/[^\w.-]/g, "_")}.log`); fs.writeFileSync(file, `${message}\n\n${output ?? ""}`); console.log(`${indent} ${dim(`all of it: ${file}`)}`); } }
uses
- tcmts.cli.style.bold
- tcmts.cli.style.dim
- tcmts.cli.style.green
- tcmts.cli.style.red
- tcmts.cli.testing.TestOutcome