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 16 commits into
base: main
Choose a base branch
from
Open
12 changes: 8 additions & 4 deletions lib/mocha.js
Original file line number Diff line number Diff line change
Expand Up @@ -881,7 +881,7 @@ Mocha.prototype.failZero = function (failZero) {
* @return {Mocha} this
* @chainable
*/
Mocha.prototype.passOnFailingTestSuite = function(passOnFailingTestSuite) {
Mocha.prototype.passOnFailingTestSuite = function (passOnFailingTestSuite) {
this.options.passOnFailingTestSuite = passOnFailingTestSuite === true;
return this;
};
Expand Down Expand Up @@ -1219,7 +1219,7 @@ 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
Expand All @@ -1229,8 +1229,12 @@ Mocha.prototype._runGlobalFixtures = async function _runGlobalFixtures(
fixtureFns = [],
context = {}
) {
for await (const fixtureFn of fixtureFns) {
await fixtureFn.call(context);
for (const fixtureFn of fixtureFns) {
try {
await fixtureFn.call(context);
} catch (err) {
console.error(err.stack);
Copy link
Member

Choose a reason for hiding this comment

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

[Functionality] This is a good start, but I think we'll want to do more than just log the error to the console. I think we'll want to mark the test as failed too. It's easy to miss console logs that don't change the exit code.

}
}
return context;
};
Expand Down
Loading