Skip to content

Commit

Permalink
.createStream() for tap output on the default harness
Browse files Browse the repository at this point in the history
  • Loading branch information
James Halliday committed Mar 4, 2014
1 parent de03633 commit 5d2cd63
Showing 1 changed file with 22 additions and 13 deletions.
35 changes: 22 additions & 13 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ var defined = require('defined');
var createDefaultStream = require('./lib/default_stream');
var Test = require('./lib/test');
var createResult = require('./lib/results');
var through = require('through');

var canEmitExit = typeof process !== 'undefined' && process
&& typeof process.on === 'function'
Expand All @@ -18,22 +19,30 @@ var nextTick = typeof setImmediate !== 'undefined'
exports = module.exports = (function () {
var harness;
var lazyLoad = function () {
if (!harness) harness = createExitHarness({
autoclose: !canEmitExit
});

return harness.apply(this, arguments);
return getHarness().apply(this, arguments);
};

lazyLoad.only = function () {
if (!harness) harness = createExitHarness({
autoclose: !canEmitExit
});

return harness.only.apply(this, arguments);
return getHarness.only.apply(this, arguments);
}


lazyLoad.createStream = function () {
if (!harness) {
var output = through();
getHarness({ stream: output });
return output;
}
return harness.createStream();
};

return lazyLoad

function getHarness (opts) {
if (!opts) opts = {};
opts.autoclose = !canEmitExit;
if (!harness) harness = createExitHarness(opts);
return harness;
}
})();

function createExitHarness (conf) {
Expand All @@ -43,7 +52,7 @@ function createExitHarness (conf) {
});

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

0 comments on commit 5d2cd63

Please sign in to comment.