Skip to content
Myr

help.sortCommands.test.js

This file

Path

tests/help.sortCommands.test.js

29 lines · 1.1 KiB · JavaScript

Last changed by

Refactor help internals into separate interface/class (#1365)John Geebefore adoption19ae912

History of this file

Take it

Refactor help internals into separate interface/class (#1365)John Geebefore adoption19ae912

lines 1–29why, one step back
1const commander = require('../');
23// These are tests of the Help class, not of the Command help.4// There is some overlap with the higher level Command tests (which predate Help).56describe('sortSubcommands', () => {7 test('when unsorted then commands in order added', () => {8 const program = new commander.Command();9 program10 .command('ccc', 'desc')11 .command('aaa', 'desc')12 .command('bbb', 'desc');13 const helper = program.createHelp();14 const visibleCommandNames = helper.visibleCommands(program).map(cmd => cmd.name());15 expect(visibleCommandNames).toEqual(['ccc', 'aaa', 'bbb', 'help']);16 });1718 test('when sortSubcommands:true then commands sorted', () => {19 const program = new commander.Command();20 program21 .configureHelp({ sortSubcommands: true })22 .command('ccc', 'desc')23 .command('aaa', 'desc')24 .command('bbb', 'desc');25 const helper = program.createHelp();26 const visibleCommandNames = helper.visibleCommands(program).map(cmd => cmd.name());27 expect(visibleCommandNames).toEqual(['aaa', 'bbb', 'ccc', 'help']);28 });29});