Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Running all tests in a suite before reporting #156

Open
wants to merge 5 commits into from

2 participants

@evanworley

These changes run all the tests in a suite before reporting. Previous the first assertion failure was reported and expresso stopped running tests. I believe it is more useful to report all the failures in the test, to prevent the developer from executing the run/fix loop many times.

@evanworley

Added one more fix which addresses an unchecked call to test.callback() in assertResponse. The problem is that test.callback only exists if the Test has multiple tests, otherwise it's null. The bad call to callback generates an exception which results in the http server not being shut down properly.

@evanworley

Two more fixes
1) Allowing nested assert.response by properly decrementing server.__pending
2) Fixing test failure reporting wrong test when running in parallel

@ericlathrop

This would be a big help.

@evanworley

Hi Eric,

It appears that expresso is mostly dead. We switched to Mocha (http://visionmedia.github.com/mocha/) a few months ago, and I'd suggest you do the same. Unless you want to maintain expresso :/

  • Evan
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Dec 7, 2011
  1. @evanworley

    Changing runParallel behavior to run all the tests in the suite, even…

    evanworley authored
    … if one fails. This fixes an issue where it would only report the first failure
  2. @evanworley
  3. @evanworley
Commits on Dec 13, 2011
  1. @evanworley

    Adding onResponse handler to properly decrement server.__pending to a…

    evanworley authored
    …llow nested assert.response calls
  2. @evanworley

    Fixing use of wrong assert

    evanworley authored
This page is out of date. Refresh to see the latest.
Showing with 30 additions and 14 deletions.
  1. +30 −14 bin/expresso
View
44 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'
@@ -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
@@ -528,7 +530,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);
@@ -538,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();
}
});
});
@@ -937,7 +940,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,18 +957,27 @@ Test.prototype.runSerial = function(callback) {
test.report();
});
};
- test.fn(test.callback);
+
+ try {
+ test.fn(test.callback);
+ } catch (err) {
+ test.failure(err);
+ }
}
});
};
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);
+ }
};
/**
Something went wrong with that request. Please try again.