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
Merge branch 'idmontie-feature/issue-47-add-version-help-message-override' into release/3.0.0John Geebefore adoptionafb8156
lines 1–28why, one step back1var program = require('../'),2 sinon = require('sinon').sandbox.create(),3 should = require('should');45sinon.stub(process, 'exit');6sinon.stub(process.stdout, 'write');78// Test that subcommands inherit the help flags9// but can also override help flags10program11 .helpOption('-i, --ihelp', 'foo foo');1213program14 .command('child')15 .option('--gender', 'specific gender of child')16 .action((cmd) => {17 console.log('Childsubcommand...');18 });1920program21 .command('family')22 .helpOption('-h, --help')23 .action((cmd) => {24 console.log('Familysubcommand...');25 });2627// Test arguments28var expectedCommandHelpInformation = [Fix tests for subcommand help with parent now includedJohn Geebefore adoption01e865c
line 29why, one step back29 'Usage: test child [options]',Merge branch 'idmontie-feature/issue-47-add-version-help-message-override' into release/3.0.0John Geebefore adoptionafb8156
lines 30–50why, one step back30 '',31 'Options:',32 ' --gender specific gender of child',33 ' -i, --ihelp foo foo',34 ''35].join('\n');3637program.parse(['node', 'test', 'child', '-i']);3839process.stdout.write.called.should.equal(true);4041var output = process.stdout.write.args[0];42output[0].should.equal(expectedCommandHelpInformation);4344// Test other command45sinon.restore();4647sinon.stub(process, 'exit');48sinon.stub(process.stdout, 'write');4950var expectedFamilyCommandHelpInformation = [Fix tests for subcommand help with parent now includedJohn Geebefore adoption01e865c
line 51why, one step back51 'Usage: test family [options]',Merge branch 'idmontie-feature/issue-47-add-version-help-message-override' into release/3.0.0John Geebefore adoptionafb8156
lines 52–65why, one step back52 '',53 'Options:',54 ' -h, --help foo foo',55 ''56].join('\n');5758program.parse(['node', 'test', 'family', '-h']);5960process.stdout.write.called.should.equal(true);6162var output2 = process.stdout.write.args[0];63output2[0].should.equal(expectedFamilyCommandHelpInformation);6465sinon.restore();