Skip to content

fix: surface global setup/teardown errors with a non-zero exit code - #5994

Merged
mark-wiemer merged 4 commits into
mochajs:mainfrom
mostafaNazari702:global-fixture-error
Jun 8, 2026
Merged

mark-wiemer merged 4 commits into
mochajs:mainfrom
mostafaNazari702:global-fixture-error

Conversation

@mostafaNazari702

Copy link
Copy Markdown
Contributor

PR Checklist

Overview

When mochaGlobalSetup or mochaGlobalTeardown threw, the error escaped the runAsync(runner) promise chain and became an unhandled rejection. since there was no catch, "done" never ran, the failure never reached the runner, and mocha exited with code 0 while silently swallowing the error.

we now catch errors only at the runAsync boundary.
Normal runner errors are unchanged as before, only global fixture errors are handled here.

@codecov

codecov Bot commented May 22, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 78.12%. Comparing base (6695fba) to head (f5f71ed).
⚠️ Report is 19 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5994      +/-   ##
==========================================
- Coverage   80.89%   78.12%   -2.78%     
==========================================
  Files          64       63       -1     
  Lines        4602     4590      -12     
  Branches      976      977       +1     
==========================================
- Hits         3723     3586     -137     
- Misses        879     1004     +125     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@JoshuaKGoldberg JoshuaKGoldberg left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks great! Nicely done on the comprehensive tests.

Just leaving a few minor notes, nothing that would block merging if someone has a strong case against them. I'll leave this open for a bit in case Mark wants to review.

Comment thread lib/mocha.js Resolved
mark-wiemer and others added 3 commits June 7, 2026 17:56
Co-authored-by: Josh Goldberg ✨ <github@joshuakgoldberg.com>
Co-authored-by: Josh Goldberg ✨ <github@joshuakgoldberg.com>
@mark-wiemer

Copy link
Copy Markdown
Member

Known failures (both #6037 and #6036), merging :)

@mark-wiemer
mark-wiemer merged commit ad81ec6 into mochajs:main Jun 8, 2026
28 checks passed
@mostafaNazari702
mostafaNazari702 deleted the global-fixture-error branch August 10, 2026 08:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

🐛 Bug: Error in mochaGlobalTeardown is swallowed and exits with code 0

3 participants