-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
76 lines (58 loc) · 1.55 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
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
74
75
76
import test from 'ava';
import {run, maybe, commit} from '.';
test('methods', t => {
t.truthy(run);
t.truthy(maybe);
t.truthy(commit);
});
test('run', async t => {
t.plan(5);
const runRes = await run('pwd');
t.is(runRes.code, 0);
t.is(runRes.succeed, true);
t.is(runRes.failed, false);
t.is(runRes.output, process.cwd() + '\n');
t.is(runRes.value, process.cwd());
});
test('run throw', async t => {
t.plan(4);
const error = await t.throws(run('invalidcommand'));
t.not(error.code, 0);
t.is(error.failed, true);
t.is(error.succeed, false);
});
test('maybe', async t => {
t.plan(6);
const maybeLs = await maybe('ls');
t.is(maybeLs.code, 0);
t.is(maybeLs.succeed, true);
t.is(maybeLs.failed, false);
const maybeFail = await maybe('ls /invalidpaths');
t.not(maybeFail.code, 0);
t.is(maybeFail.succeed, false);
t.is(maybeFail.failed, true);
});
test('commit', async t => {
t.plan(3);
const commitPass = await commit('ls');
t.is(commitPass.code, 0);
t.is(commitPass.succeed, true);
t.is(commitPass.failed, false);
});
test('output/value/values', async t => {
t.plan(3);
const echoTest = await maybe('echo "test"');
t.is(echoTest.output, 'test\n');
t.is(echoTest.value, 'test');
t.deepEqual(echoTest.values, ['test']);
});
test('output/value/values multiline', async t => {
t.plan(4);
const echoTest = await maybe('ls', {
cwd: './test/fixtures'
});
t.is(echoTest.code, 0);
t.is(echoTest.output, 'file1.txt\nfile2.txt\n');
t.is(echoTest.value, 'file1.txt\nfile2.txt');
t.deepEqual(echoTest.values, ['file1.txt', 'file2.txt']);
});