help.sortCommands.test.js
This file
Path
tests/help.sortCommands.test.js
35 lines · 1.2 KiB · JavaScript
Last changed by
Switching to esm-only (#2464)John Geebefore adoptionf4bd470
History of this fileTake it
123456789101112131415161718192021222324252627282930313233343536import * as commander from '../index.js';import { test, describe } from 'node:test';import assert from 'node:assert/strict';
// These are tests of the Help class, not of the Command help.// There is some overlap with the higher level Command tests (which predate Help).
describe('Help.configureHelp({ sortSubcommands: true })', () => { test('when unsorted then commands in order added', () => { const program = new commander.Command(); program .command('ccc', 'desc') .command('aaa', 'desc') .command('bbb', 'desc'); const helper = program.createHelp(); const visibleCommandNames = helper .visibleCommands(program) .map((cmd) => cmd.name()); assert.deepEqual(visibleCommandNames, ['ccc', 'aaa', 'bbb', 'help']); });
test('when sortSubcommands:true then commands sorted', () => { const program = new commander.Command(); program .configureHelp({ sortSubcommands: true }) .command('ccc', 'desc') .command('aaa', 'desc') .command('bbb', 'desc'); const helper = program.createHelp(); const visibleCommandNames = helper .visibleCommands(program) .map((cmd) => cmd.name()); assert.deepEqual(visibleCommandNames, ['aaa', 'bbb', 'ccc', 'help']); });});