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 4 commits into
base: main
Choose a base branch
from
Open
Changes from all 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
Copy link
Member

Choose a reason for hiding this comment

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

[Testing] This change is missing test coverage. It's great that existing tests pass, but there should be a test added that shows Mocha acting appropriately when an a global fixture does reject.

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`.
* @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