-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtest.js
43 lines (33 loc) · 1.31 KB
/
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
import test from 'ava';
import sinon from 'sinon';
import run from './cli';
/** @type {sinon.SinonSpy} */
let spawn;
test.before('fake spawn', () => {
spawn = sinon.fake((name, args) => args);
});
test.afterEach('reset fake', () => {
spawn.resetHistory();
});
test('runs first argument when in CI environment', t => {
run(['first', 'second'], true, spawn);
t.true(spawn.returned(['run', 'first']));
});
test('runs second argument when not in CI environment', t => {
run(['first', 'second'], false, spawn);
t.true(spawn.returned(['run', 'second']));
});
test('runs nothing if no second argument and not in CI environment', t => {
run(['first'], false, spawn);
t.false(spawn.called);
});
test('runs script with additional arguments if provided', t => {
run(['first', 'second', '--test', 'value'], true, spawn, 'npm');
t.true(spawn.lastCall.returned(['run', 'first', '--', '--test', 'value']));
run(['first', 'second', '--test', 'value'], false, spawn, 'npm');
t.true(spawn.lastCall.returned(['run', 'second', '--', '--test', 'value']));
run(['first', 'second', '--test', 'value'], true, spawn, 'yarn');
t.true(spawn.lastCall.returned(['run', 'first', '--test', 'value']));
run(['first', 'second', '--test', 'value'], false, spawn, 'yarn');
t.true(spawn.lastCall.returned(['run', 'second', '--test', 'value']));
});