api.js
1.6 KB
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
var noptify = require('..');
var assert = require('assert');
describe('API', function() {
it('returns an instanceof Noptify', function() {
assert.ok(noptify() instanceof noptify.Noptify);
});
it('is typically used like so', function() {
var program = noptify(['node', 'file.js', '-d', '--dirname', './', '-p', '3000', 'app.js', 'base.js'])
.option('debug', '-d', 'Enabled debug output', Boolean)
.option('dirname', 'The path to the output directory')
.option('port', '-p', 'The port you wish to listen on', Number)
// opts => nopt result
var opts = program.parse();
assert.deepEqual(opts, {
port: 3000,
debug: true,
dirname: './',
argv: {
remain: ['app.js', 'base.js'],
cooked: ['--debug', '--dirname', './', '--port', '3000', 'app.js', 'base.js'],
original: ['-d', '--dirname', './', '-p', '3000', 'app.js', 'base.js']
}
});
});
it('allows definitiion of shorthands separately', function() {
var opts = noptify(['node', 'file.js', '-lc'])
.option('line-comment', 'Ouputs with debugging information', Boolean)
.shorthand('lc', '--line-comment')
.parse();
assert.equal(opts['line-comment'], true);
});
// hmm, keep this one for the very last, or do another way, process exit
// prevent other tests from running
it.skip('outputs help and exit the process with --help', function() {
var program = noptify(['', '', '--help'])
assert.throws(function() {
throw new Error('parse() must be called for this to happen');
});
program.parse();
throw new Error('I\'m sad, I\'ll never throw :(');
});
});