Skip to content

Commit d684f4c

Browse files
committed
Added test to check missing options
1 parent 1c51892 commit d684f4c

1 file changed

Lines changed: 53 additions & 0 deletions

File tree

‎test/cli.js‎

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
'use strict';
2+
3+
const chai = require('chai');
4+
const exec = require('child_process').exec;
5+
const path = require('path');
6+
7+
const expect = chai.expect;
8+
9+
describe('CLI', function() {
10+
describe('options', function() {
11+
12+
// Override environment.
13+
before(function() {
14+
process.env.NODE_ENV = null;
15+
});
16+
17+
after(function() {
18+
process.env.NODE_ENV = 'test';
19+
});
20+
21+
describe('--handler', function() {
22+
describe('missing value', function() {
23+
it('should return error', function(done) {
24+
testOption(['--handler'], function(stdout) {
25+
expect(stdout).to.match(/error: option '--handler <path>' argument missing/);
26+
done();
27+
});
28+
});
29+
});
30+
});
31+
32+
describe('--port', function() {
33+
describe('missing value', function() {
34+
it('should not return error', function(done) {
35+
testOption(['--port'], function(stdout) {
36+
expect(stdout).to.not.match(/error: option '--port <path>' argument missing/);
37+
done();
38+
});
39+
});
40+
});
41+
});
42+
});
43+
});
44+
45+
/**
46+
* Test Commander options in child process.
47+
*/
48+
function testOption(vals, callback) {
49+
const file = path.resolve('server.js');
50+
const args = vals.join(' ');
51+
52+
exec(`node '${file}' ${args}`, callback);
53+
}

0 commit comments

Comments
 (0)