Skip to content

Commit 5d2cd63

Browse files
author
James Halliday
committed
.createStream() for tap output on the default harness
1 parent de03633 commit 5d2cd63

File tree

1 file changed

+22
-13
lines changed

1 file changed

+22
-13
lines changed

index.js

+22-13
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ var defined = require('defined');
22
var createDefaultStream = require('./lib/default_stream');
33
var Test = require('./lib/test');
44
var createResult = require('./lib/results');
5+
var through = require('through');
56

67
var canEmitExit = typeof process !== 'undefined' && process
78
&& typeof process.on === 'function'
@@ -18,22 +19,30 @@ var nextTick = typeof setImmediate !== 'undefined'
1819
exports = module.exports = (function () {
1920
var harness;
2021
var lazyLoad = function () {
21-
if (!harness) harness = createExitHarness({
22-
autoclose: !canEmitExit
23-
});
24-
25-
return harness.apply(this, arguments);
22+
return getHarness().apply(this, arguments);
2623
};
27-
24+
2825
lazyLoad.only = function () {
29-
if (!harness) harness = createExitHarness({
30-
autoclose: !canEmitExit
31-
});
32-
33-
return harness.only.apply(this, arguments);
26+
return getHarness.only.apply(this, arguments);
3427
}
35-
28+
29+
lazyLoad.createStream = function () {
30+
if (!harness) {
31+
var output = through();
32+
getHarness({ stream: output });
33+
return output;
34+
}
35+
return harness.createStream();
36+
};
37+
3638
return lazyLoad
39+
40+
function getHarness (opts) {
41+
if (!opts) opts = {};
42+
opts.autoclose = !canEmitExit;
43+
if (!harness) harness = createExitHarness(opts);
44+
return harness;
45+
}
3746
})();
3847

3948
function createExitHarness (conf) {
@@ -43,7 +52,7 @@ function createExitHarness (conf) {
4352
});
4453

4554
var stream = harness.createStream();
46-
var es = stream.pipe(createDefaultStream());
55+
var es = stream.pipe(conf.stream || createDefaultStream());
4756
if (canEmitExit) {
4857
es.on('error', function (err) { harness._exitCode = 1 });
4958
}

0 commit comments

Comments
 (0)