forked from mariocasciaro/spawned
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
42 lines (38 loc) · 1.23 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
var expect = require('chai').expect,
through2 = require('through2'),
Buffers = require("buffers"),
spawned = require('./index.js');
describe('spawned', function() {
it('should return out/err/combined streams', function(done) {
spawned('ps').then(function(res) {
expect(res.out, "out").to.match(new RegExp(process.pid));
expect(res.err, "err").to.be.empty;
expect(res.combined, "combined").to.match(new RegExp(process.pid));
done();
}).catch(done);
});
it('should stream stdout', function(done) {
var outBuff = new Buffers();
spawned('ps', [], {
out: through2(function(chunk, enc, cb) {
outBuff.push(chunk);
this.push(chunk);
cb();
}, function() {
expect(outBuff.toString('utf-8'), "out").to.match(new RegExp(process.pid));
done();
})
}).catch(done);
});
it('should reject promise in case of error', function(done) {
var outBuff = new Buffers();
spawned('grep', ['nosuchpattern', 'nosuchfile'])
.then(function(res) {
done(new Error("Should fail..."));
}).catch(function(err) {
expect(err.code).equal(2);
expect(err.err).to.match(/No such file/)
done();
}).catch(done);
});
});