test.command.helpSubCommand.customFlags.js
This file
Path
test/test.command.helpSubCommand.customFlags.js
65 lines · 1.4 KiB · JavaScript
Last changed by
Fix tests for subcommand help with parent now includedJohn Geebefore adoption01e865c
History of this fileTake it
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566var program = require('../'), sinon = require('sinon').sandbox.create(), should = require('should');
sinon.stub(process, 'exit');sinon.stub(process.stdout, 'write');
// Test that subcommands inherit the help flags// but can also override help flagsprogram .helpOption('-i, --ihelp', 'foo foo');
program .command('child') .option('--gender', 'specific gender of child') .action((cmd) => { console.log('Childsubcommand...'); });
program .command('family') .helpOption('-h, --help') .action((cmd) => { console.log('Familysubcommand...'); });
// Test argumentsvar expectedCommandHelpInformation = [ 'Usage: test child [options]', '', 'Options:', ' --gender specific gender of child', ' -i, --ihelp foo foo', ''].join('\n');
program.parse(['node', 'test', 'child', '-i']);
process.stdout.write.called.should.equal(true);
var output = process.stdout.write.args[0];output[0].should.equal(expectedCommandHelpInformation);
// Test other commandsinon.restore();
sinon.stub(process, 'exit');sinon.stub(process.stdout, 'write');
var expectedFamilyCommandHelpInformation = [ 'Usage: test family [options]', '', 'Options:', ' -h, --help foo foo', ''].join('\n');
program.parse(['node', 'test', 'family', '-h']);
process.stdout.write.called.should.equal(true);
var output2 = process.stdout.write.args[0];output2[0].should.equal(expectedFamilyCommandHelpInformation);
sinon.restore();