-
Notifications
You must be signed in to change notification settings - Fork 140
/
spawn.test.js
executable file
·54 lines (45 loc) · 1.53 KB
/
spawn.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
var nodeio = require('../lib/node.io'),
processor = new nodeio.Processor(),
assert = require('assert');
function createJob(options, methods) {
if (typeof methods === 'undefined') {
methods = options;
options = {};
}
return new nodeio.Job(options, methods);
}
module.exports = {
'test job.spawn()': function() {
var job = createJob();
job.spawn('pwd', function(err, stdout, stderr) {
assert.isNull(err);
assert.equal(process.cwd()+'\n', stdout);
});
job.spawn('echo hello', function(err, stdout, stderr) {
assert.isNull(err);
assert.equal('hello\n', stdout);
});
//TODO: Test job.spawn(cmd, stdin)
job.spawn('badcommandxyz', function(err, stdout, stderr) {
assert.equal('Failed to start child process.', err);
});
},
'test job.exec()': function() {
var job = createJob();
job.exec('pwd', function(err, stdout, stderr) {
assert.isNull(err);
assert.equal(process.cwd()+'\n', stdout);
});
job.exec('echo hello', function(err, stdout, stderr) {
assert.isNull(err);
assert.equal('hello\n', stdout);
});
job.exec('badcommandxyz', function(err, stdout, stderr) {
assert.ok(err);
});
job.options.timeout = 1;
job.exec('sleep 2', function(err, stdout, stderr) {
assert.ok(err);
});
},
}