Skip to content
Myr

help.longestCommandTermLength.test.js

This file

Path

tests/help.longestCommandTermLength.test.js

52 lines · 2.0 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–52why, 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('longestSubcommandTermLength', () => {7 test('when no commands then returns zero', () => {8 const program = new commander.Command();9 const helper = new commander.Help();10 expect(helper.longestSubcommandTermLength(program, helper)).toEqual(0);11 });1213 test('when command and no help then returns length of term', () => {14 const sub = new commander.Command('sub');15 const program = new commander.Command();16 program17 .addHelpCommand(false)18 .addCommand(sub);19 const helper = new commander.Help();20 expect(helper.longestSubcommandTermLength(program, helper)).toEqual(helper.subcommandTerm(sub).length);21 });2223 test('when command with arg and no help then returns length of term', () => {24 const sub = new commander.Command('sub <file)');25 const program = new commander.Command();26 program27 .addHelpCommand(false)28 .addCommand(sub);29 const helper = new commander.Help();30 expect(helper.longestSubcommandTermLength(program, helper)).toEqual(helper.subcommandTerm(sub).length);31 });3233 test('when multiple commands then returns longest length', () => {34 const longestCommandName = 'alphabet-soup <longer_than_help>';35 const program = new commander.Command();36 program37 .addHelpCommand(false)38 .command('before', 'desc')39 .command(longestCommandName, 'desc')40 .command('after', 'desc');41 const helper = new commander.Help();42 expect(helper.longestSubcommandTermLength(program, helper)).toEqual(longestCommandName.length);43 });4445 test('when just help command then returns length of help term', () => {46 const program = new commander.Command();47 program48 .addHelpCommand(true);49 const helper = new commander.Help();50 expect(helper.longestSubcommandTermLength(program, helper)).toEqual('help [command]'.length);51 });52});