Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: improve error handling in global fixtures #5208 #5275

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
Open
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 18 additions & 10 deletions lib/mocha.js
Original file line number Diff line number Diff line change
Expand Up @@ -1219,21 +1219,29 @@ Mocha.prototype.runGlobalTeardown = async function runGlobalTeardown(
};

/**
* Run global fixtures sequentially with context `context`
* Run global fixtures sequentially with context `context`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TG199 this piece of feedback is still open

* @private
* @param {MochaGlobalFixture[]} [fixtureFns] - Fixtures to run
* @param {object} [context] - context object
* @returns {Promise<object>} context object
*/
Mocha.prototype._runGlobalFixtures = async function _runGlobalFixtures(
fixtureFns = [],
context = {}
) {
for await (const fixtureFn of fixtureFns) {
await fixtureFn.call(context);
}
return context;
};
Mocha.prototype._runGlobalFixtures = async function _runGlobalFixtures(
fixtureFns = [],
context = {}
) {
for (const fixtureFn of fixtureFns) {
try {
await fixtureFn.call(context);
} catch (err) {
if (this.runner) {
this.runner.failures += 1;
}
console.error('Global fixture error:', err.stack);

}
}
return context;
};

/**
* Toggle execution of any global setup fixture(s)
Expand Down
Loading