diff --git a/index.js b/index.js index b2b4a42c..9983a495 100644 --- a/index.js +++ b/index.js @@ -17,15 +17,15 @@ 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(); @@ -33,34 +33,34 @@ function createHarness (conf_) { if (!code && !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) { @@ -73,7 +73,7 @@ function createHarness (conf_) { }); pending.unshift.apply(pending, unshifts); } - + process.nextTick(function () { running = false; if (pending.length) return pending.shift()(); @@ -86,7 +86,7 @@ function createHarness (conf_) { }); } }; - + test.stream = out; return test; }