Skip to content

fix: report test error when afterEach also fails on retry#5990

Open
mostafaNazari702 wants to merge 3 commits into
mochajs:mainfrom
mostafaNazari702:report-test-error-on-retry
Open

fix: report test error when afterEach also fails on retry#5990
mostafaNazari702 wants to merge 3 commits into
mochajs:mainfrom
mostafaNazari702:report-test-error-on-retry

Conversation

@mostafaNazari702

@mostafaNazari702 mostafaNazari702 commented May 22, 2026

Copy link
Copy Markdown
Contributor

PR Checklist

Overview

The fix wraps the retry-branch hookUp(AFTER_EACH, ...) callback so that if afterEach fails the original test error is still surfaced via self.fail(test, err) before forwarding the hook error to next.

I did not touch the normal retry flow: if afterEach succeeds, execution continues exactly as before.

Change is minimal and isolated to the retry path in lib/runner.js and does not affect: --retries 0 or successful retries or EVENT_TEST_RETRY ordering or non-retry EVENT_TEST_PASS behavior.

@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.15%. Comparing base (6695fba) to head (471edcd).
⚠️ Report is 21 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5990      +/-   ##
==========================================
- Coverage   80.89%   78.15%   -2.75%     
==========================================
  Files          64       63       -1     
  Lines        4602     4595       -7     
  Branches      976      978       +2     
==========================================
- Hits         3723     3591     -132     
- 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.

LGTM! Just the one question on test style discrepency?

Comment thread test/integration/retries.spec.js Outdated
failureMessages.indexOf("Error from after each") !== -1,
"expected the afterEach hook error to be reported, got: " +
JSON.stringify(failureMessages),
);

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.

[Testing] The other tests have more precise checks on the raw lines of output. Is there a reason you didn't go for that here?

@JoshuaKGoldberg JoshuaKGoldberg changed the title report test error when afterEach also fails on retry fix: report test error when afterEach also fails on retry Jun 7, 2026
mark-wiemer and others added 2 commits June 7, 2026 19:04
Co-authored-by: Josh Goldberg ✨ <github@joshuakgoldberg.com>
@mark-wiemer mark-wiemer self-assigned this Jun 8, 2026
@mark-wiemer mark-wiemer modified the milestone: Backlog Jun 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

🐛 Bug: Error from afterEach hides the original error from the test case when retries > 0

3 participants