IF Commons GitHub

surfaces/cli/reporter

Written to: 4 requirements: 4 proved, 0 partly, 0 failing, 0 with no test recorded. 0004-headless-cli FR-003, 0004-headless-cli FR-004, 0004-headless-cli FR-005, 0004-headless-cli FR-007

The calm reporter (commons headless 0004-headless-cli FR-003, FR-005, FR-007): what a command tells while it runs, drawn as a person wants to read it. Quiet on success and loud on a problem: a line for a phase only when it has something to see (a green step line is for --verbose), every item only with --verbose, the problems kept for the closing block, and the whole run, every item and every problem, in the run's log whatever the mode. On a terminal a phase in progress is one line redrawn in place (a spinner, a progress bar, what it is doing now); anywhere else there are only the final lines, with no control character in them.

import { Reporter } from "./reporter.ts";
const written: string[] = [];
const r = new Reporter({ look: { tty: false, colour: false, emoji: false, columns: 80 }, verbosity: "calm", write: (t) => written.push(t), now: () => 0 });
r.progress({ kind: "phase", name: "Packages" });
r.progress({ kind: "done", result: "86 installed" });
r.close();
written.join(""); // "": a phase that went well is no line in calm

Source: commons/headless/src/surfaces/cli/reporter.ts

1 of 2 exports are imported by a test of the run. A test that imports an export may not call it or check what it returns.

ReporterOptionstypeno test imports it
type ReporterOptions = {
  readonly look: Look;
  readonly verbosity: Verbosity;
  /** Where the screen text goes (the error stream). */
  readonly write: (text: string) => void;
  readonly now: () => number;
  readonly log?: RunLog;
  /** Redraws the line in progress; used only on a terminal. */
  readonly timer?: TimerPort;
  /** What watches the run. */
  readonly events?: RunEvents;
};

What a reporter is made from.

Reporterclass
class Reporter

The reporter of one run.

MemberTypeWhat it is
problemsProblem[]Every problem told, in order.
outcomesstring[]Every line the run wanted seen.
hintsHint[]Every hint told.
progressProgressThe Progress to give the command.
handle(event: ProgressEvent) => voidTells the reporter what the command is doing.
close() => voidEnds the phase in progress and the line drawn for it; nothing is drawn after this.

Imported by 9 tests of the run (9 passed, 0 failed): the library's results

Titles, headings, exports, tables, columns and requirements. Esc closes.