Skip to content

Commit

Permalink
suppress EPIPE but set the exit code to 1 so test results may be pipe…
Browse files Browse the repository at this point in the history
…d around to head/grep/tail
  • Loading branch information
James Halliday committed Nov 22, 2013
1 parent 9882d34 commit 1589695
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
9 changes: 8 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ function createExitHarness (conf) {
});

var stream = harness.createStream();
stream.pipe(createDefaultStream());
var es = stream.pipe(createDefaultStream());
if (canEmitExit) {
es.on('error', function (err) { harness._exitCode = 1 });
}

var ended = false;
stream.on('end', function () { ended = true });
Expand All @@ -54,6 +57,9 @@ function createExitHarness (conf) {
var _error;

process.on('uncaughtException', function (err) {
if (err && err.code === 'EPIPE' && err.errno === 'EPIPE'
&& err.syscall === 'write') return;

_error = err

throw err
Expand All @@ -73,6 +79,7 @@ function createExitHarness (conf) {
harness.close();
process.exit(code || harness._exitCode);
});

return harness;
}

Expand Down
6 changes: 4 additions & 2 deletions lib/default_stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ var combine = require('stream-combiner');
var split = require('split');

module.exports = function () {
return combine(split(), through(write));
var stream = combine(split(), through(write));
return stream;

function write (line) {
console.log(line);
try { console.log(line); }
catch (e) { stream.emit('error', e) }
}
};

0 comments on commit 1589695

Please sign in to comment.