Skip to content

Commit

Permalink
NO MERGE CONFLICT
Browse files Browse the repository at this point in the history
  • Loading branch information
Raynos committed Dec 12, 2012
2 parents 19d7f88 + 359a67f commit 9241450
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,49 +16,53 @@ var canExit = typeof process !== 'undefined' && process
function createHarness (conf_) {
var pending = [];
var running = false;

var count = 0;

var began = false;
var out = new Render();

var test = function (name, conf, cb) {
count++;
var t = new Test(name, conf, cb);
if (!conf || typeof conf !== 'object') conf = conf_ || {};

if (conf.exit !== false && canEmitExit) {
process.on('exit', function (code) {
t._exit();
out.close();
if (code === 0 && !t._ok) process.exit(1);
});
}

process.nextTick(function () {
if (!out.piped) out.pipe(createDefaultStream());
if (!began) out.begin();
began = true;

var run = function () {
running = true;
out.push(t);
t.run();
};

if (running || pending.length) {
pending.push(run);
}
else run();
});

t.on('test', function sub (st) {
count++;
st.on('test', sub);
st.on('end', onend);
});

t.on('end', onend);

return t;

function onend () {
count--;
if (this._progeny.length) {
var unshifts = this._progeny.map(function (st) {
return function () {
Expand All @@ -73,14 +77,16 @@ function createHarness (conf_) {
process.nextTick(function () {
running = false;
if (pending.length) return pending.shift()();
out.close();
if (count === 0) {
out.close();
}
if (conf.exit !== false && canExit && !t._ok) {
process.exit(1);
}
});
}
};

test.stream = out;
return test;
}
Expand Down

0 comments on commit 9241450

Please sign in to comment.