testHelpCoversEveryCommand

tcmts.cli.help.testHelpCoversEveryCommand · #s25o6ekt · term

import { helps, routes, SECTIONS } from "#codebase/tcmts/cli/commands";
import { childrenOf, lookup, paramsOf, rootHelp } from "#codebase/tcmts/cli/help";
import assert from "node:assert/strict";
import { stripVTControlCharacters } from "node:util";

export const testHelpCoversEveryCommand = () => {
  const commands = Object.keys(routes());
  // every command has its help, and is in one section of `tcm help`, which lists it with its description
  assert.deepEqual(Object.keys(helps()).sort(), [...commands].sort());
  assert.deepEqual(SECTIONS.flatMap(([, names]) => names).sort(), [...commands].sort());
  const shown = stripVTControlCharacters(rootHelp());
  for (const c of commands)
    assert.match(shown, new RegExp(`^  ${c} +${RegExp.escape(helps()[c]!.description)}$`, "m"), c);
  // and every command, subcommand and parameter is described (by its own help, or the help many share)
  const described = (path: string[]) => {
    const r = lookup(path);
    assert.ok(r.description, `tcm ${path.join(" ")}`);
    for (const p of paramsOf(r)) assert.ok(p.description, `tcm ${path.join(" ")} ${p.name}`);
    for (const child of childrenOf(r)) described([...path, child.name]);
  };
  for (const c of commands) described([c]);
}

uses