highland-process
Version:
Utility that lets you turn a process into a highland stream.
42 lines (37 loc) • 1.1 kB
JavaScript
var _ = require('highland'),
assert = require('chai').assert,
spawn = require('child_process').spawn,
through = require('../index').through;
describe('through', function() {
it('works', function(done) {
var tee = spawn('tee');
_(['hello how are you?'])
.through(through(tee))
.pull(function(error, value) {
assert.isNull(error);
// we get back a buffer
assert.equal(value.toString('utf8'), 'hello how are you?');
done();
});
});
it('passes through errors', function(done) {
var isErrorPassed = false,
stream = _(function(push, next) {
push(null, 'hello');
push(new Error('find me!'));
push(null, ' bye');
push(null, _.nil);
}),
tee = spawn('tee');
stream
.through(through(tee))
.errors(function(error, push) {
isErrorPassed = error.message === 'find me!';
})
.toArray(function(results) {
assert.equal(results[0].toString('utf8'), 'hello bye');
assert.isTrue(isErrorPassed);
done();
});
});
});