-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
feat: add --fail-hook-affected-tests option to report skipped tests as failed #5519
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
base: main
Are you sure you want to change the base?
feat: add --fail-hook-affected-tests option to report skipped tests as failed #5519
Conversation
|
|
Hmm, I think we can ignore the CLA issue as the non-signer is AI :D |
|
I'll review this in more detail sometime in the next ~7 days :) |
5dee260 to
37acdb2
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #5519 +/- ##
=======================================
Coverage 93.69% 93.69%
=======================================
Files 57 57
Lines 4391 4440 +49
Branches 850 861 +11
=======================================
+ Hits 4114 4160 +46
- Misses 277 280 +3 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
mark-wiemer
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall looks OK, just requesting some renames for clarity. I'll check the coverage and make sure I can repro this one locally as it's a big change. Fortunately we should be able to include this in 12.0.0-beta-1 :)
test/integration/fixtures/hooks/before-each-hook-error-with-fail-affected.fixture.js
Outdated
Show resolved
Hide resolved
test/integration/fixtures/hooks/before-each-hook-error-with-fail-affected.fixture.js
Outdated
Show resolved
Hide resolved
test/integration/fixtures/hooks/before-hook-error-with-fail-affected.fixture.js
Outdated
Show resolved
Hide resolved
test/integration/fixtures/hooks/before-each-hook-error-with-fail-affected.fixture.js
Outdated
Show resolved
Hide resolved
test/integration/fixtures/hooks/before-hook-error-with-fail-affected.fixture.js
Outdated
Show resolved
Hide resolved
…s failed When `before()` or `beforeEach()` hooks fail, Mocha currently only reports the hook failure and silently skips affected tests. This makes it difficult to track test coverage and understand the full impact of hook failures. This change introduces a new CLI option `--fail-hook-affected-tests` that, when enabled, reports all tests affected by hook failures as failed instead of silently skipping them. Changes: - Added --fail-hook-affected-tests boolean CLI option - Implemented failAffectedTests() method in Runner to fail all affected tests - Updated hook() method to call failAffectedTests when hooks fail - Added failHookAffectedTests option to Mocha class - Added integration tests for both before() and beforeEach() hook failures - All affected tests now receive descriptive error messages indicating which hook caused them to be skipped Fixes mochajs#4392
- Extract error message creation into createHookSkipError() helper function to eliminate duplication across three locations - Simplify recursive forEach call in failAffectedTests() - Update test fixture and suite descriptions to use backticks for clarity (e.g., 'error in `before` hook')
ade4687 to
9fe8493
Compare
|
Took me a minute to remember I needed to actively add the |
JoshuaKGoldberg
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally looking good - the approach is solid and respects existing patterns. Great! 🙌
Requesting changes on the [Bug] around throwing non-Error values. Otherwise we're looking pretty good to merge soon.
@mark-wiemer shall we back-port this to v11?
- Fix JSDoc placement for failHookAffectedTests and failZero - Handle non-Error thrown values in createHookSkipError - Add tests for null, undefined, and other non-Error throws Addresses review comments from @JoshuaKGoldberg: - Separated JSDoc for failHookAffectedTests from failZero docs - Added proper handling for falsy and non-Error exceptions using createInvalidExceptionError and thrown2Error patterns - Added comprehensive test coverage for edge cases 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
|
@JoshuaKGoldberg Thanks for the thorough review! I've addressed both of your comments in the latest commit (c171cf1): Re: [Docs] JSDoc placement - Fixed! The JSDoc now correctly documents Re: [Bug] Non-Error handling - Great catch! The
This follows the existing patterns from All tests are passing, including the 2 new integration tests specifically for non-Error handling. ✅ |
JoshuaKGoldberg
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. One little touchup but we can always apply this before merging. Thanks! ⭐
Co-authored-by: Josh Goldberg ✨ <[email protected]>
|
@akshah123 looks like your latest commit broke some stuff, please review the failed checks. @JoshuaKGoldberg happy to port this back to v11, created #5580 |
When
before()orbeforeEach()hooks fail, Mocha currently only reports the hook failure and silently skips affected tests. This makes it difficult to track test coverage and understand the full impact of hook failures.This change introduces a new CLI option
--fail-hook-affected-teststhat, when enabled, reports all tests affected by hook failures as failed instead of silently skipping them.Changes:
Fixes #4392
PR Checklist
status: accepting prsOverview