From caf96acb08ad8113f03299a939b4a45ef44ffa42 Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Thu, 31 May 2018 20:21:39 +0800 Subject: [PATCH] handle asynchronous test failures (#3164) --- test/mocha.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/test/mocha.js b/test/mocha.js index 503afd3d..5d65a5a2 100644 --- a/test/mocha.js +++ b/test/mocha.js @@ -55,8 +55,7 @@ process.nextTick(function run() { var elapsed = Date.now(); var timer; var done = function() { - clearTimeout(timer); - done = function() {}; + reset(); elapsed = Date.now() - elapsed; if (elapsed > task.limit) { throw new Error("Timed out: " + elapsed + "ms > " + task.limit + "ms"); @@ -73,6 +72,7 @@ process.nextTick(function run() { }, limit); }; task.timeout(task.limit); + process.on("uncaughtException", raise); task.call(task, done); } else { task.timeout = config.timeout; @@ -99,11 +99,16 @@ process.nextTick(function run() { } function raise(err) { - clearTimeout(timer); - done = function() {}; + reset(); task.titles.error = err; errors.push(task.titles); log_titles(console.log, task.titles, red('\u00D7 ')); process.nextTick(run); } + + function reset() { + clearTimeout(timer); + done = function() {}; + process.removeListener("uncaughtException", raise); + } }); -- 2.34.1