/
install-test.js
64 lines (57 loc) · 1.28 KB
/
install-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
const t = require('tap')
const InstallTest = require('../../../lib/commands/install-test.js')
let installArgs = null
let installCalled = false
let testArgs = null
let testCalled = false
let installError = null
const installTest = new InstallTest({
exec: (cmd, args) => {
if (cmd === 'install') {
installArgs = args
installCalled = true
}
if (installError) {
throw installError
}
if (cmd === 'test') {
testArgs = args
testCalled = true
}
},
config: {
validate: () => {},
get: (key) => {
if (key === 'location') {
return 'project'
}
},
},
})
t.test('the install-test command', t => {
t.afterEach(() => {
installArgs = null
installCalled = false
testArgs = null
testCalled = false
installError = null
})
t.test('install and test', async t => {
await installTest.exec(['extra'])
t.equal(installCalled, true)
t.equal(testCalled, true)
t.match(installArgs, ['extra'])
t.match(testArgs, [])
})
t.test('install fails', async t => {
installError = new Error('test fail')
await t.rejects(
installTest.exec(['extra']),
'test fail'
)
t.equal(installCalled, true)
t.equal(testCalled, false)
t.match(installArgs, ['extra'])
})
t.end()
})