From 5551d5fa66465252aecfb0f40f863b514084df5c Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Thu, 1 Jan 2026 16:34:44 +0100 Subject: [PATCH] test(help): cover help output --- tests/help-output.test.ts | 51 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 tests/help-output.test.ts diff --git a/tests/help-output.test.ts b/tests/help-output.test.ts new file mode 100644 index 0000000..dc17792 --- /dev/null +++ b/tests/help-output.test.ts @@ -0,0 +1,51 @@ +import { describe, expect, it } from 'vitest'; +import { createProgram } from '../src/cli/program.js'; +import { createCliContext } from '../src/cli/shared.js'; + +describe('root help output', () => { + it('mentions shorthand + json and lists user commands', () => { + const ctx = createCliContext([]); + const program = createProgram(ctx); + let help = ''; + program.configureOutput({ + writeOut: (s) => { + help += s; + }, + writeErr: () => {}, + }); + program.outputHelp(); + + expect(help).toContain('following'); + expect(help).toContain('followers'); + expect(help).toContain('likes'); + + expect(help).toContain('bird '); + expect(help).toContain('--json'); + }); + + it('shows global options in subcommand help', () => { + const ctx = createCliContext([]); + const program = createProgram(ctx); + const cmd = program.commands.find((c) => c.name() === 'read'); + if (!cmd) { + throw new Error('Expected "read" command to be registered'); + } + + let help = ''; + const output = { + writeOut: (s) => { + help += s; + }, + writeErr: () => {}, + }; + program.configureOutput(output); + cmd.configureOutput(output); + + cmd.outputHelp(); + + expect(help).toContain('--auth-token'); + expect(help).toContain('--ct0'); + expect(help).toContain('--timeout'); + expect(help).toContain('--quote-depth'); + }); +});