From 9c875628c92e91ab4b5c9c9ffba9dd6cd63bd409 Mon Sep 17 00:00:00 2001 From: Evan Worley Date: Wed, 7 Dec 2011 13:57:32 -0800 Subject: [PATCH 1/5] Changing runParallel behavior to run all the tests in the suite, even if one fails. This fixes an issue where it would only report the first failure --- bin/expresso | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/bin/expresso b/bin/expresso index fdad22c..0769cdd 100755 --- a/bin/expresso +++ b/bin/expresso @@ -957,11 +957,15 @@ Test.prototype.runSerial = function(callback) { Test.prototype.runParallel = function() { var test = this; - test.fn(function(fn) { - test.on('exit', function() { - fn(test.assert); - }); - }, test.assert); + try { + test.fn(function(fn) { + test.on('exit', function() { + fn(test.assert); + }); + }, test.assert); + } catch (err) { + test.failure(err); + } }; /** From 8453e632b1647252cdb0adeed693284e8e9a8623 Mon Sep 17 00:00:00 2001 From: Evan Worley Date: Wed, 7 Dec 2011 14:11:27 -0800 Subject: [PATCH 2/5] Updating runSerial to also run all tests in the suite before reporting --- bin/expresso | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/bin/expresso b/bin/expresso index 0769cdd..d906664 100755 --- a/bin/expresso +++ b/bin/expresso @@ -937,7 +937,11 @@ Test.prototype.runSerial = function(callback) { if (++dots % 25 === 0) console.log(); test.setup(function() { if (test.fn.length < 1) { - test.fn(); + try { + test.fn(); + } catch (err) { + test.failure(err); + } test.teardown(callback); } else { var id = setTimeout(function() { @@ -950,7 +954,12 @@ Test.prototype.runSerial = function(callback) { test.report(); }); }; - test.fn(test.callback); + + try { + test.fn(test.callback); + } catch (err) { + test.failure(err); + } } }); }; From fbd3e860fd560cba3140ce99eb3cfd8c57459760 Mon Sep 17 00:00:00 2001 From: Evan Worley Date: Wed, 7 Dec 2011 14:38:37 -0800 Subject: [PATCH 3/5] Only calling test.callback() in assertResponse if it has a callback methods (has multiple tests) --- bin/expresso | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/bin/expresso b/bin/expresso index d906664..4f94511 100755 --- a/bin/expresso +++ b/bin/expresso @@ -528,7 +528,11 @@ assert.response = function(server, req, res, msg) { test.success(msg); } catch (err) { test.failure(err); - test.callback(); + + // Tests only have callbacks when there is more than one test + if (typeof test.callback === "function") { + test.callback(); + } } finally { // Remove our token. var idx = test._pending.indexOf(token); From 0f558d9232f070650b322f0a7e7c52d5523f5609 Mon Sep 17 00:00:00 2001 From: Evan Worley Date: Tue, 13 Dec 2011 15:21:56 -0800 Subject: [PATCH 4/5] Adding onResponse handler to properly decrement server.__pending to allow nested assert.response calls --- bin/expresso | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/bin/expresso b/bin/expresso index 4f94511..93b52f1 100755 --- a/bin/expresso +++ b/bin/expresso @@ -453,7 +453,7 @@ assert.response = function(server, req, res, msg) { headers: req.headers }); - var check = function() { + var onResponse = function() { if (--server.__pending === 0) { server.close(); server.__listening = false; @@ -463,7 +463,7 @@ assert.response = function(server, req, res, msg) { // Timeout if (requestTimeout) { timer = setTimeout(function() { - check(); + onResponse(); delete req.timeout; test.failure(new Error(msg + 'Request timed out after ' + requestTimeout + 'ms.')); }, requestTimeout); @@ -476,6 +476,8 @@ assert.response = function(server, req, res, msg) { response.setEncoding(encoding); response.on('data', function(chunk) { response.body += chunk; }); response.on('end', function() { + onResponse(); + if (timer) clearTimeout(timer); try { // Assert response body @@ -542,9 +544,6 @@ assert.response = function(server, req, res, msg) { // Someone else took our token. This is an error. test.failure(new Error('Request succeeded, but token vanished: ' + msg)); } - - // Potentially shut down the server. - check(); } }); }); From d3cfcfd6d30ee2294eb4b46bd3718e37f7c29fb8 Mon Sep 17 00:00:00 2001 From: Evan Worley Date: Tue, 13 Dec 2011 15:54:06 -0800 Subject: [PATCH 5/5] Fixing use of wrong assert --- bin/expresso | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/expresso b/bin/expresso index 93b52f1..862a44b 100755 --- a/bin/expresso +++ b/bin/expresso @@ -381,7 +381,7 @@ assert.length = function(val, n, msg) { * @param {String} msg */ assert.response = function(server, req, res, msg) { - var test = assert._test; + var test = this._test; // Callback as third or fourth arg var callback = typeof res === 'function'