-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.hs.test.js
56 lines (51 loc) · 1.8 KB
/
util.hs.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
var mock = require('mock-require');
var assert = require('assert');
mock('hotshell', { item: function item(config) {
util.results.push(config);
}});
var util = require('./util.hs.js');
beforeEach(function() {
util.results = []
});
describe('util', function () {
describe('#confirm(config)', function () {
it('should wrap the command with a \'read\' and a \'if\' statement', function () {
var expected = {
key: 't',
desc: 'desc',
cmd: 'read -r -p "Are you sure? [y/n] " resp; if [[ $resp = y ]]; then cmd; fi'
};
validateConfig(expected, util.confirm({key: 't', desc: 'desc', cmd: 'cmd'}))
})
})
describe('#prompt(config)', function () {
it('should prefix the command with combinations of \'echo\' and \'read\' statements', function () {
var expected = {
key: 't',
desc: 'desc',
vars: [{name: 'n1', prompt: 'p1'}, {name: 'n2', prompt: 'p2'}],
cmd: 'echo -n \"p1: \"; read n1; echo -n \"p2: \"; read n2; cmd'
};
validateConfig(expected, util.prompt({
key: 't',
desc: 'desc',
vars: [{name: 'n1', prompt: 'p1'}, {name: 'n2', prompt: 'p2'}],
cmd: 'cmd'
}))
})
})
describe('#prompt(confirm(config, false))', function () {
it('should add only one item', function () {
util.prompt(util.confirm({
key: 't',
desc: 'desc',
cmd: 'cmd'
}, false))
assert.equal(1, util.results.length)
})
})
});
function validateConfig(expected, actual) {
assert.deepEqual(actual, expected);
assert.deepEqual(util.results, [expected]);
}