forked from tj/commander.js
/
test.command.allowUnknownOption.js
58 lines (46 loc) · 1.18 KB
/
test.command.allowUnknownOption.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/**
* Module dependencies.
*/
var program = require('../')
, sinon = require('sinon').sandbox.create()
, should = require('should');
var stubError = sinon.stub(console, 'error');
var stubExit = sinon.stub(process, 'exit');
program
.version('0.0.1')
.option('-p, --pepper', 'add pepper');
program.parse('node test -m'.split(' '));
stubError.callCount.should.equal(4);
// test subcommand
resetStubStatus();
program
.command('sub')
.action(function () {
});
program.parse('node test sub -m'.split(' '));
stubError.callCount.should.equal(4);
stubExit.calledOnce.should.be.true();
// command with `allowUnknownOption`
resetStubStatus();
program
.version('0.0.1')
.option('-p, --pepper', 'add pepper');
program
.allowUnknownOption()
.parse('node test -m'.split(' '));
stubError.callCount.should.equal(0);
stubExit.calledOnce.should.be.false();
// subcommand with `allowUnknownOption`
resetStubStatus();
program
.command('sub2')
.allowUnknownOption()
.action(function () {
});
program.parse('node test sub2 -m'.split(' '));
stubError.callCount.should.equal(0);
stubExit.calledOnce.should.be.false();
function resetStubStatus() {
stubError.reset();
stubExit.reset();
}