Skip to content

Commit

Permalink
Stop test after first assertion failure, and handle exceptions thrown…
Browse files Browse the repository at this point in the history
… from callbacks
  • Loading branch information
gilad61 committed Aug 1, 2012
1 parent 95b0e8b commit 3a5e22e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
6 changes: 6 additions & 0 deletions lib/core.js
Expand Up @@ -65,6 +65,12 @@ exports.runTest = function (name, fn, opt, callback) {
var start = new Date().getTime();
var test = types.test(name, start, options, callback);

// Fail the test gracefully if an exception was thrown from a callback
process.removeAllListeners('uncaughtException');
process.on('uncaughtException', function (exception) {
test.done(exception);
});

try {
fn(test);
}
Expand Down
7 changes: 1 addition & 6 deletions lib/types.js
Expand Up @@ -79,12 +79,7 @@ var assertWrapper = function (callback) {
return function () {
var message = arguments[arity - 1];
var a = exports.assertion({method: new_method, message: message});
try {
assert[assert_method].apply(null, arguments);
}
catch (e) {
a.error = e;
}
assert[assert_method].apply(null, arguments);
callback(a);
};
};
Expand Down

0 comments on commit 3a5e22e

Please sign in to comment.