test.command.nohelp.js
This file
Path
test/test.command.nohelp.js
55 lines · 1.7 KiB · JavaScript
Last changed by
removed newline after options and commands headersJared Petersenbefore adoption2c20e91
History of this fileTake it
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556var program = require('../') , sinon = require('sinon').sandbox.create() , should = require('should');
sinon.stub(process, 'exit');sinon.stub(process.stdout, 'write');
program.command('mycommand [options]', 'this is my command');
program .command('anothercommand [options]') .action(function() { return; });
program.command('hiddencommand [options]', 'you won\'t see me', { noHelp: true });
program .command('hideagain [options]', null, { noHelp: true }) .action(function() { return; });
program.command('hiddencommandwithoutdescription [options]', { noHelp: true });
program.parse(['node', 'test']);
program.name.should.be.a.Function();program.name().should.equal('test');program.commands[0].name().should.equal('mycommand');program.commands[0]._noHelp.should.be.false();program.commands[1].name().should.equal('anothercommand');program.commands[1]._noHelp.should.be.false();program.commands[2].name().should.equal('hiddencommand');program.commands[2]._noHelp.should.be.true();program.commands[3].name().should.equal('hideagain');program.commands[3]._noHelp.should.be.true();program.commands[4].name().should.equal('hiddencommandwithoutdescription');program.commands[4]._noHelp.should.be.true();program.commands[5].name().should.equal('help');
sinon.restore();sinon.stub(process.stdout, 'write');program.outputHelp();
process.stdout.write.calledOnce.should.be.true();process.stdout.write.args.length.should.equal(1);
var output = process.stdout.write.args[0];
var expect = [ 'Commands:', ' mycommand [options] this is my command', ' anothercommand [options]', ' help [cmd] display help for [cmd]'].join('\n');output[0].indexOf(expect).should.not.be.equal(-1);