Skip to content

Commit b7396f5

Browse files
committed
test(cli): add basic cli integration tests
1 parent 90b7288 commit b7396f5

File tree

5 files changed

+88
-3
lines changed

5 files changed

+88
-3
lines changed

@commitlint/cli/cli.js

100644100755
File mode changed.

@commitlint/cli/cli.test.js

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import path from 'path';
2+
import test from 'ava';
3+
import execa from 'execa';
4+
import stream from 'string-to-stream';
5+
6+
const here = path.join.bind(null, __dirname);
7+
8+
const SIMPLE = here('fixtures/simple');
9+
const EXTENDS_ROOT = here('fixtures/extends-root');
10+
11+
const cli = (input = '', args = [], opts = {}) => {
12+
const c = execa(here('cli.js'), args, {
13+
capture: ['stdout'],
14+
cwd: opts.cwd
15+
});
16+
stream(input).pipe(c.stdin);
17+
return c;
18+
};
19+
20+
test('should throw when called without [input]', t => {
21+
t.throws(cli(), /Expected a raw commit/);
22+
});
23+
24+
test('should reprint input from stdin', async t => {
25+
const actual = await cli('foo: bar');
26+
t.true(actual.stdout.includes('foo: bar'));
27+
});
28+
29+
test('should produce no success output with --quiet flag', async t => {
30+
const actual = await cli('foo: bar', ['--quiet']);
31+
t.is(actual.stdout, '');
32+
t.is(actual.stderr, '');
33+
});
34+
35+
test('should produce no success output with -q flag', async t => {
36+
const actual = await cli('foo: bar', ['-q']);
37+
t.is(actual.stdout, '');
38+
t.is(actual.stderr, '');
39+
});
40+
41+
test('should succeed for input from stdin without rules', async t => {
42+
const actual = await cli('foo: bar');
43+
t.is(actual.code, 0);
44+
});
45+
46+
test('should fail for input from stdin with rule from rc', async t => {
47+
const actual = await t.throws(cli('foo: bar', [], {cwd: SIMPLE}));
48+
t.true(actual.stdout.includes('scope must not be one of [foo]'));
49+
t.is(actual.code, 1);
50+
});
51+
52+
test('should fail for input from stdin with rule from js', async t => {
53+
const actual = await t.throws(cli('foo: bar', ['--extends', './commitlint'], {cwd: EXTENDS_ROOT}));
54+
t.true(actual.stdout.includes('scope must not be one of [foo]'));
55+
t.is(actual.code, 1);
56+
});
57+
58+
test('should produce no error output with --quiet flag', async t => {
59+
const actual = await t.throws(cli('foo: bar', ['--quiet'], {cwd: SIMPLE}));
60+
t.is(actual.stdout, '');
61+
t.is(actual.stderr, '');
62+
t.is(actual.code, 1);
63+
});
64+
65+
test('should produce no error output with -q flag', async t => {
66+
const actual = await t.throws(cli('foo: bar', ['-q'], {cwd: SIMPLE}));
67+
t.is(actual.stdout, '');
68+
t.is(actual.stderr, '');
69+
t.is(actual.code, 1);
70+
});
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = {
2+
rules: {
3+
'type-enum': [2, 'never', ['foo']]
4+
}
5+
};
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"rules": {
3+
"type-enum": [2, "never", ["foo"]]
4+
}
5+
}

@commitlint/cli/package.json

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,14 @@
88
"scripts": {
99
"build": "exit 0",
1010
"clean": "exit 0",
11-
"test": "exit 0",
11+
"test": "ava",
1212
"prepublish": "npm test"
1313
},
14+
"ava": {
15+
"files": [
16+
"cli.test.js"
17+
]
18+
},
1419
"engines": {
1520
"node": ">=4"
1621
},
@@ -34,7 +39,7 @@
3439
"license": "MIT",
3540
"devDependencies": {
3641
"ansi-styles": "3.1.0",
37-
"ava": "0.18.2",
42+
"ava": "^0.18.2",
3843
"babel-cli": "6.18.0",
3944
"babel-plugin-add-module-exports": "0.2.1",
4045
"babel-plugin-istanbul": "4.1.3",
@@ -44,7 +49,7 @@
4449
"babel-preset-stage-0": "6.16.0",
4550
"babel-register": "6.24.1",
4651
"cross-env": "5.0.1",
47-
"execa": "0.6.3",
52+
"execa": "^0.7.0",
4853
"globby": "6.1.0",
4954
"has-ansi": "3.0.0",
5055
"nyc": "10.3.2",

0 commit comments

Comments
 (0)