-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
61 lines (41 loc) · 1.6 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
import test from 'ava';
global.td = require('testdouble');
// TODO: break out helpers/before and after each, and tests per module, into separate files as number becomes significant
let testLog, entryPoint;
test.beforeEach(t => {
testLog = td.replace('./src/log').log;
entryPoint = require('./src/index');
});
test.afterEach(t => {
td.reset();
})
test ('entryPoint prints expected use of -g flag if improperly specified ', t => {
process.argv = [ '', '', '' ]
entryPoint();
td.verify(testLog("expected -g flag to specify github repo name"));
t.pass();
});
test ('entryPoint is a function', t => {
t.is(typeof entryPoint, 'function');
});
// Service Runner Tests
test ('servicerunner is a function', t => {
const serviceRunner = require('./src/utils/servicerunner');
t.is(typeof serviceRunner, 'function');
});
const command = 'test command to execute';
const location = 'some/dir';
const name = 'somename';
const terminalWindow = true;
const expectedCommandString = `echo "cd ${location} && ${command}" > ${name}.command; chmod +x ${name}.command; open ${name}.command;`;
test ('servicerunner executes and returns command string with correct incorporation of arguments', t => {
const stubExec = td.func();
td.when(stubExec(td.matchers.isA(String))).thenReturn({code: 0});
const testShell = td.replace('shelljs', {
exec: stubExec
});
const serviceRunner = require('./src/utils/servicerunner');
const returnedCommand = serviceRunner(command, location, name, terminalWindow);
t.is(returnedCommand, expectedCommandString);
td.verify(testShell.exec(expectedCommandString));
});