Skip to content

Commit

Permalink
handle asynchronous test failures (#3164)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexlamsl committed May 31, 2018
1 parent c767490 commit caf96ac
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions test/mocha.js
Expand Up @@ -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");
Expand All @@ -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;
Expand All @@ -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);
}
});

0 comments on commit caf96ac

Please sign in to comment.