-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.test.js
129 lines (98 loc) · 3.02 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
const {spawn} = require('child_process')
const test = require('tape')
const run = async args => {
const stderr = []
const stdout = []
return new Promise(resolve => {
const cli = spawn('./cli.js', args)
cli.stderr.on('data', data => {
stderr.push(data.toString())
})
cli.stdout.on('data', data => {
stdout.push(data.toString())
})
cli.on('close', code => {
resolve({stderr, stdout, code})
})
})
}
test('cli, when using same tree', async assert => {
const message = 'diff result must be empty'
const actual = await run(['./fixtures/source', './fixtures/source'])
const expected = {stderr: [], stdout: [], code: 0}
assert.deepEqual(actual, expected, message)
assert.end()
})
test('cli, when using distinct tree', async assert => {
const message = 'diff result must be empty'
const actual = await run(['./fixtures/source', './fixtures/target'])
const expected = {stderr: [], stdout: [], code: 0}
assert.deepEqual(actual, expected, message)
assert.end()
})
test('cli, when using tree with missing files', async assert => {
const message = 'diff result must be empty'
const actual = await run(['./fixtures/source', './fixtures/target/a'])
const expected = {
stderr: [],
stdout: [
[
'00.txt',
'03.txt',
'04.txt',
'05.txt',
'06.txt',
'07.txt',
'08.txt',
'09.txt'
].join('\n')
],
code: 0
}
assert.deepEqual(actual, expected, message)
assert.end()
})
test('cli, when using invalid source directory', async assert => {
const message = 'should return an error'
const actual = await run(['./fixtures/invalid', './fixtures/target'])
const expected = {
stderr: ['invalid path provided "./fixtures/invalid" (ENOENT)'],
stdout: [],
code: 1
}
assert.deepEqual(actual, expected, message)
assert.end()
})
test('cli, when using invalid target directory', async assert => {
const message = 'should return an error'
const actual = await run(['./fixtures/source', './fixtures/invalid'])
const expected = {
stderr: ['invalid path provided "./fixtures/invalid" (ENOENT)'],
stdout: [],
code: 1
}
assert.deepEqual(actual, expected, message)
assert.end()
})
test('cli, when using file as source directory', async assert => {
const message = 'should return an error'
const actual = await run(['./fixtures/file.txt', './fixtures/target'])
const expected = {
stderr: ['invalid path provided "./fixtures/file.txt"; given file, expected directory (ENOTDIR)'],
stdout: [],
code: 1
}
assert.deepEqual(actual, expected, message)
assert.end()
})
test('cli, when using file as target directory', async assert => {
const message = 'should return an error'
const actual = await run(['./fixtures/source', './fixtures/file.txt'])
const expected = {
stderr: ['invalid path provided "./fixtures/file.txt"; given file, expected directory (ENOTDIR)'],
stdout: [],
code: 1
}
assert.deepEqual(actual, expected, message)
assert.end()
})