-
-
Notifications
You must be signed in to change notification settings - Fork 222
/
test-functional.js
151 lines (129 loc) · 4.97 KB
/
test-functional.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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
// Test basic usage of cli
var path = require('path');
var assert = require('assert');
var run = require('./utils').run;
var IS_WINDOWS = /^win/.test(process.platform);
// If true, output of commands are shown
var DEBUG_TESTS = process.env.DEBUG_TESTS === 'true';
var TEST_DIR = 'dir/';
// Abs path to test directory
var testDir = path.resolve(__dirname);
process.chdir(path.join(testDir, '..'));
describe('concurrently', function() {
this.timeout(5000);
it('help should be successful', () => {
return run('node ./src/main.js --help', {pipe: DEBUG_TESTS})
.then(function(exitCode) {
// exit code 0 means success
assert.strictEqual(exitCode, 0);
});
});
it('version should be successful', () => {
return run('node ./src/main.js -V', {pipe: DEBUG_TESTS})
.then(function(exitCode) {
assert.strictEqual(exitCode, 0);
});
});
it('two successful commands should exit 0', () => {
return run('node ./src/main.js "echo test" "echo test"', {pipe: DEBUG_TESTS})
.then(function(exitCode) {
assert.strictEqual(exitCode, 0);
});
});
it('at least one unsuccessful commands should exit non-zero', () => {
return run('node ./src/main.js "echo test" "nosuchcmd" "echo test"', {pipe: DEBUG_TESTS})
.then(function(exitCode) {
assert.notStrictEqual(exitCode, 0);
});
});
it('--kill-others should kill other commands if one dies', () => {
// This test would timeout if kill others option does not work
return run('node ./src/main.js --kill-others "sleep 1000" "echo test" "sleep 1000"', {pipe: DEBUG_TESTS})
.then(function(exitCode) {
assert.notStrictEqual(exitCode, 0);
});
});
it('--success=first should return first exit code', () => {
return run('node ./src/main.js -k --success first "echo test" "sleep 1000" ', {pipe: DEBUG_TESTS})
// When killed, sleep returns null exit code
.then(function(exitCode) {
assert.strictEqual(exitCode, 0);
});
});
it('--success=last should return last exit code', () => {
// When killed, sleep returns null exit code
return run('node ./src/main.js -k --success last "echo test" "sleep 1000" ', {pipe: DEBUG_TESTS})
.then(function(exitCode) {
assert.notStrictEqual(exitCode, 0);
});
});
it('&& nosuchcmd should return non-zero exit code', () => {
return run('node ./src/main.js "echo 1 && nosuchcmd" "echo 1 && nosuchcmd" ', {pipe: DEBUG_TESTS})
.then(function(exitCode) {
assert.strictEqual(exitCode, 1);
});
});
it('--prefix-colors should handle non-existent colors without failing', () => {
return run('node ./src/main.js -c "not.a.color" "echo colors"', {pipe: DEBUG_TESTS})
.then(function(exitCode) {
assert.strictEqual(exitCode, 0);
});
});
it('--argument-passthrough should pass arguments to each command', () => {
// TODO: How can we test this?
return run('node ./src/main.js --argument-passthrough "echo test1" "echo test2" -- --foo', {pipe: DEBUG_TESTS})
.then(function(exitCode) {
assert.strictEqual(exitCode, 0);
});
});
['SIGINT', 'SIGTERM'].forEach((signal) => {
if (IS_WINDOWS) {
console.log('IS_WINDOWS=true');
console.log('Skipping SIGINT/SIGTERM propagation tests ..');
return;
}
it('killing it with ' + signal + ' should propagate the signal to the children', function(done) {
var readline = require('readline');
var waitingStart = 2;
var waitingSignal = 2;
function waitForSignal(cb) {
if (waitingSignal) {
setTimeout(waitForSignal, 100);
} else {
cb();
}
}
run('node ./src/main.js "node ./test/support/signal.js" "node ./test/support/signal.js"', {
pipe: false,
callback: function(child) {
var rl = readline.createInterface({
input: child.stdout,
output: null
});
rl.on('line', function(line) {
if (DEBUG_TESTS) {
console.log(line);
}
// waiting for startup
if (/STARTED/.test(line)) {
waitingStart--;
}
if (!waitingStart) {
// both processes are started
child.kill(signal);
}
// waiting for signal
if (new RegExp(signal).test(line)) {
waitingSignal--;
}
});
}
}).then(function() {
waitForSignal(done);
});
});
});
});
function resolve(relativePath) {
return path.join(testDir, relativePath);
}