From 6fb2a69a3ace858428f926d52d7eb45c7f2e466b Mon Sep 17 00:00:00 2001 From: Gilad Oren Date: Wed, 1 Aug 2012 18:59:02 +0300 Subject: [PATCH] Stop test after first assertion failure, and handle exceptions thrown from callbacks --- lib/core.js | 6 ++++++ lib/types.js | 7 +------ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/core.js b/lib/core.js index 5281bc735..120c734e2 100644 --- a/lib/core.js +++ b/lib/core.js @@ -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); } diff --git a/lib/types.js b/lib/types.js index 2cdd1efc8..88398b540 100644 --- a/lib/types.js +++ b/lib/types.js @@ -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); }; };