Skip to content

Commit

Permalink
mocha v10: fix failure handling
Browse files Browse the repository at this point in the history
Fixes error:

   An error occurred while bailing: TypeError: Cannot read property 'forEach' of undefined
  • Loading branch information
alxndrsn committed Dec 31, 2023
1 parent 1cde95c commit 2187822
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
10 changes: 6 additions & 4 deletions bin/test-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ class RemoteRunner {
try {
var additionalProps = ['pass', 'fail', 'pending'].indexOf(event.name) === -1 ? {} : {
slow: event.obj.slow ? function () { return event.obj.slow; } : function () { return 60; },
fullTitle: event.obj.fullTitle ? function () { return event.obj.fullTitle; } : undefined
fullTitle: event.obj.fullTitle ? function () { return event.obj.fullTitle; } : undefined,
titlePath: event.obj.titlePath ? function () { return event.obj.titlePath; } : undefined,
};
var obj = Object.assign({}, event.obj, additionalProps);

Expand Down Expand Up @@ -123,9 +124,10 @@ class RemoteRunner {
handleFailed() {
if (bail) {
try {
this.handlers['end'].forEach(function (handler) {
handler();
});
const triggerHandler = handler => handler();
this.onceHandlers.get('end').forEach(triggerHandler);
this.onceHandlers.delete('end');
this.handlers.get('end').forEach(triggerHandler);
} catch (e) {
console.log('An error occurred while bailing:', e);
} finally {
Expand Down
3 changes: 2 additions & 1 deletion tests/integration/webrunner.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
title: obj.title,
duration: obj.duration,
slow: typeof obj.slow === 'function' ? obj.slow() : undefined,
fullTitle: typeof obj.fullTitle === 'function' ? obj.fullTitle() : undefined
fullTitle: typeof obj.fullTitle === 'function' ? obj.fullTitle() : undefined,
titlePath: typeof obj.titlePath === 'function' ? obj.titlePath() : undefined,
},
err: err && {
actual: err.actual,
Expand Down

0 comments on commit 2187822

Please sign in to comment.