help.visibleGlobalOptions.test.js
This file
Path
tests/help.visibleGlobalOptions.test.js
45 lines · 1.6 KiB · JavaScript
Last changed by
Merge branch 'master' into release/10.xJohn Geebefore adoption2bdd631
History of this fileTake it
Merge branch 'master' into release/10.xJohn Geebefore adoption2bdd631
lines 1–45why, one step back1const commander = require('../');23test('when default configuration then return empty array', () => {4 const program = new commander.Command();5 program6 .option('--global');7 const sub = program.command('sub');8 const helper = sub.createHelp();9 expect(helper.visibleGlobalOptions(program)).toEqual([]);10});1112test('when showGlobalOptions:true then return program options', () => {13 const program = new commander.Command();14 program15 .option('--global')16 .configureHelp({ showGlobalOptions: true });17 const sub = program.command('sub');18 const helper = sub.createHelp();19 const visibleOptionNames = helper.visibleGlobalOptions(sub).map(option => option.name());20 expect(visibleOptionNames).toEqual(['global']);21});2223test('when showGlobalOptions:true and program has version then return version', () => {24 const program = new commander.Command();25 program26 .configureHelp({ showGlobalOptions: true })27 .version('1.2.3');28 const sub = program.command('sub');29 const helper = sub.createHelp();30 const visibleOptionNames = helper.visibleGlobalOptions(sub).map(option => option.name());31 expect(visibleOptionNames).toEqual(['version']);32});3334test('when showGlobalOptions:true and nested commands then return combined global options', () => {35 const program = new commander.Command();36 program37 .configureHelp({ showGlobalOptions: true })38 .option('--global');39 const sub1 = program.command('sub1')40 .option('--sub1');41 const sub2 = sub1.command('sub2');42 const helper = sub2.createHelp();43 const visibleOptionNames = helper.visibleGlobalOptions(sub2).map(option => option.name());44 expect(visibleOptionNames).toEqual(['sub1', 'global']);45});