Skip to content

Commit

Permalink
fix harness test
Browse files Browse the repository at this point in the history
  • Loading branch information
James Halliday committed May 4, 2013
1 parent 890382d commit fa706ae
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 21 deletions.
40 changes: 21 additions & 19 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,32 +22,34 @@ exports = module.exports = (function () {
};
})();

function createExitHarness () {
function createExitHarness (conf) {
if (!conf) conf = {};
var harness = createHarness();
var stream = harness.createStream();
stream.pipe(createDefaultStream());

var ended = false;
stream.on('end', function () { ended = true });

if (process.exit && process._getActiveHandles) {
var iv = setInterval(function () {
if (process._getActiveHandles().length > 1) return;

clearInterval(iv);
setTimeout(function () {
if (ended) return;
for (var i = 0; i < harness._tests.length; i++) {
var t = harness._tests[i];
t._exit();
}
}, 100);

setTimeout(function () {
process.exit(harness._exitCode);
}, 105);
});
}
if (conf.exit === false) return harness;
if (!process.exit || !process._getActiveHandles) return harness;

var iv = setInterval(function () {
if (process._getActiveHandles().length > 1) return;

clearInterval(iv);
setTimeout(function () {
if (ended) return;
for (var i = 0; i < harness._tests.length; i++) {
var t = harness._tests[i];
t._exit();
}
}, 100);

setTimeout(function () {
process.exit(harness._exitCode);
}, 105);
});
return harness;
}

Expand Down
4 changes: 2 additions & 2 deletions test/harness.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var test = require('../');
var harness = test.createHarness({ exit : false });
var test = require('tap').test;
var harness = require('../').createHarness({ exit: false });

// minimal write stream mockery
var collector = {
Expand Down

0 comments on commit fa706ae

Please sign in to comment.