Skip to content

fix: no re-emit unhandledRejection for non-Mocha registred listener #5987

Open
mostafaNazari702 wants to merge 1 commit into
mochajs:mainfrom
mostafaNazari702:unhandled-rejection-reemit
Open

fix: no re-emit unhandledRejection for non-Mocha registred listener #5987
mostafaNazari702 wants to merge 1 commit into
mochajs:mainfrom
mostafaNazari702:unhandled-rejection-reemit

Conversation

@mostafaNazari702
Copy link
Copy Markdown
Contributor

PR Checklist

Overview

Current unhandledRejection handler used to remove itself and re-emit the event so node could apply its default behavior but this made user listeners to run twice when present.
this change skips the re-emit if any other unhandledRejection listener is registered thus preventing duplicates and in the same time keeping the existing no-listener behavior unchanged.

An integration test ensures user listeners are called exactly once.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 22, 2026

Codecov Report

❌ Patch coverage is 90.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 80.89%. Comparing base (6695fba) to head (c196dca).

Files with missing lines Patch % Lines
lib/runner.js 90.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5987      +/-   ##
==========================================
- Coverage   80.89%   80.89%   -0.01%     
==========================================
  Files          64       64              
  Lines        4602     4607       +5     
  Branches      976      976              
==========================================
+ Hits         3723     3727       +4     
- Misses        879      880       +1     

☔ View full report in Codecov by Sentry.
📢 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.

@mostafaNazari702 mostafaNazari702 changed the title fix: no re-emit unhandledRejection for non-Mocha registred listener fix: no re-emit unhandledRejection for non-Mocha registred listener May 22, 2026
@mostafaNazari702
Copy link
Copy Markdown
Contributor Author

Added only a space in the end of the PR title to re-run tests.

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: unhandledRejection events are re-emitted

1 participant