diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2018-05-31 20:21:39 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-05-31 20:21:39 +0800 |
commit | caf96acb08ad8113f03299a939b4a45ef44ffa42 (patch) | |
tree | a039032f475e67f9d53af29cec8f8e473543781e | |
parent | c76749084b613c765cff7a4e063e1cadb76dcc38 (diff) | |
download | tracifyjs-caf96acb08ad8113f03299a939b4a45ef44ffa42.tar.gz tracifyjs-caf96acb08ad8113f03299a939b4a45ef44ffa42.zip |
handle asynchronous test failures (#3164)
-rw-r--r-- | test/mocha.js | 13 |
1 files 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); + } }); |