-
Notifications
You must be signed in to change notification settings - Fork 935
/
Copy pathcli.test.js
73 lines (61 loc) · 2.17 KB
/
cli.test.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import path from 'path';
import test from 'ava';
import execa from 'execa';
import stream from 'string-to-stream';
const here = path.join.bind(null, __dirname);
const SIMPLE = here('fixtures/simple');
const EXTENDS_ROOT = here('fixtures/extends-root');
const EMPTY = here('fixtures/empty');
const cli = (input = '', args = [], opts = {}) => {
const c = execa(here('cli.js'), args, {
capture: ['stdout'],
cwd: opts.cwd
});
stream(input).pipe(c.stdin);
return c;
};
test('should throw when called without [input]', t => {
t.throws(cli(), /Expected a raw commit/);
});
test('should reprint input from stdin', async t => {
const actual = await cli('foo: bar', [], {cwd: EMPTY});
t.true(actual.stdout.includes('foo: bar'));
});
test('should produce no success output with --quiet flag', async t => {
const actual = await cli('foo: bar', ['--quiet'], {cwd: EMPTY});
t.is(actual.stdout, '');
t.is(actual.stderr, '');
});
test('should produce no success output with -q flag', async t => {
const actual = await cli('foo: bar', ['-q'], {cwd: EMPTY});
t.is(actual.stdout, '');
t.is(actual.stderr, '');
});
test('should succeed for input from stdin without rules', async t => {
const actual = await cli('foo: bar', [], {cwd: EMPTY});
t.is(actual.code, 0);
});
test('should fail for input from stdin with rule from rc', async t => {
const actual = await t.throws(cli('foo: bar', [], {cwd: SIMPLE}));
t.true(actual.stdout.includes('scope must not be one of [foo]'));
t.is(actual.code, 1);
});
test('should fail for input from stdin with rule from js', async t => {
const actual = await t.throws(
cli('foo: bar', ['--extends', './extended'], {cwd: EXTENDS_ROOT})
);
t.true(actual.stdout.includes('scope must not be one of [foo]'));
t.is(actual.code, 1);
});
test('should produce no error output with --quiet flag', async t => {
const actual = await t.throws(cli('foo: bar', ['--quiet'], {cwd: SIMPLE}));
t.is(actual.stdout, '');
t.is(actual.stderr, '');
t.is(actual.code, 1);
});
test('should produce no error output with -q flag', async t => {
const actual = await t.throws(cli('foo: bar', ['-q'], {cwd: SIMPLE}));
t.is(actual.stdout, '');
t.is(actual.stderr, '');
t.is(actual.code, 1);
});