From ad90739e9f1d6824ec55c990748f4c61c6d856c6 Mon Sep 17 00:00:00 2001 From: Raynos Date: Fri, 18 Jan 2013 15:04:00 -0800 Subject: [PATCH 1/3] Do not close renderer twice. The renderer was being closed a second time in the before exit logic which would cause the TAP end message to be printed twice. This only happens when using tape in node of course. --- index.js | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/index.js b/index.js index 2c5110ba..0a59f00d 100644 --- a/index.js +++ b/index.js @@ -24,50 +24,49 @@ 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) { onexit(function (code) { t._exit(); - out.close(); 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) { @@ -80,7 +79,7 @@ function createHarness (conf_) { }); pending.unshift.apply(pending, unshifts); } - + process.nextTick(function () { running = false; if (pending.length) return pending.shift()(); @@ -93,7 +92,7 @@ function createHarness (conf_) { }); } }; - + test.stream = out; return test; } From bd1db4ee2d6129dfad57187ea7ccdc1522178f6b Mon Sep 17 00:00:00 2001 From: Raynos Date: Fri, 18 Jan 2013 18:01:44 -0800 Subject: [PATCH 2/3] fix close bug --- index.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 0a59f00d..937b02b7 100644 --- a/index.js +++ b/index.js @@ -26,6 +26,7 @@ function createHarness (conf_) { var count = 0; var began = false; + var closed = false; var out = new Render(); var test = function (name, conf, cb) { @@ -36,6 +37,10 @@ function createHarness (conf_) { if (conf.exit !== false) { onexit(function (code) { t._exit(); + if (!closed) { + closed = true + out.close(); + } if (!code && !t._ok) process.exit(1); }); } @@ -83,7 +88,8 @@ function createHarness (conf_) { process.nextTick(function () { running = false; if (pending.length) return pending.shift()(); - if (count === 0) { + if (count === 0 && !closed) { + closed = true out.close(); } if (conf.exit !== false && canExit && !t._ok) { From 266684958a3f8e5ed9ed9436107a5940a2e1bb29 Mon Sep 17 00:00:00 2001 From: Raynos Date: Fri, 18 Jan 2013 18:33:39 -0800 Subject: [PATCH 3/3] whitespace back --- index.js | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/index.js b/index.js index 937b02b7..c75083e6 100644 --- a/index.js +++ b/index.js @@ -24,16 +24,16 @@ function createHarness (conf_) { var pending = []; var running = false; var count = 0; - + var began = false; var closed = 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) { onexit(function (code) { t._exit(); @@ -44,34 +44,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) { @@ -84,7 +84,7 @@ function createHarness (conf_) { }); pending.unshift.apply(pending, unshifts); } - + process.nextTick(function () { running = false; if (pending.length) return pending.shift()(); @@ -98,7 +98,7 @@ function createHarness (conf_) { }); } }; - + test.stream = out; return test; }