highland-process
Version:
Utility that lets you turn a process into a highland stream.
55 lines (48 loc) • 1.31 kB
JavaScript
var _ = require('highland'),
assert = require('chai').assert,
exec = require('child_process').exec,
spawn = require('child_process').spawn,
from = require('../index').from;
describe('from', function() {
it('works', function(done) {
var echo = spawn('echo', ['hello how are you?']);
from(echo)
.split()
.pull(function(error, value) {
assert.isNull(error);
// we get back a buffer
assert.equal(value.toString('utf8'), 'hello how are you?');
done();
});
});
it('passes errors', function(done) {
var ls = spawn('ls', ['nonexistent']),
errorCalled = 0;
from(ls)
.errors(function(error, push) {
errorCalled++;
assert.match(error.message, /No such file or directory/);
})
.apply(function() {
assert.equal(errorCalled, 1);
done();
});
});
it('splits errors by newline', function(done) {
var errors = exec('>&2 printf "error\\nerror2"');
errorCalled = 0;
from(errors)
.errors(function(error, push) {
errorCalled++;
if (errorCalled === 1) {
assert.equal(error.message, 'error');
} else {
assert.equal(error.message, 'error2');
}
})
.apply(function() {
assert.equal(errorCalled, 2);
done();
});
});
});