Repository navigation
fix(cli): report tests behind a failed before hook as failed when Mocha fails them - #387
Closed
kamal-kaur04 wants to merge 2 commits into
Closed
kamal-kaur04 wants to merge 2 commits into
kamal-kaur04 wants to merge 2 commits into
Conversation
…ha fails them @wdio/mocha-framework 10 turns Mocha's failHookAffectedTests on by default, so tests behind a failed before/beforeEach hook are failed, not dropped. The hook cascade still reported them as skipped, and the reporter's later fail event for them is dropped, so Test Reporting showed skipped while CI showed failed. Report them as failed with the hook's error unless the user sets mochaOpts.failHookAffectedTests to false. afterEach failures and this.skip() hooks keep the skipped report. Applies to both the CLI cascade and the legacy insights cascade. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
|
4 of 7 tasks
Collaborator
Author
|
Combined into #388 with the other 10.x CLI follow-ups, so they review and release together. The commits are unchanged (cherry-picked onto current |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What is this about?
@wdio/mocha-framework10 turns on Mocha'sfailHookAffectedTestswhen the user leaves it unset. With it on, Mocha 12 marks the tests behind a failedbefore/beforeEachhook as failed, so CI reports them failed.The service still reported those tests as skipped. Its failed-hook cascade, in
afterHookon the CLI flow and in the insights handler off it, runs inside the hook wrapper, before Mocha marks the tests. Mocha's laterfailfor each test was then dropped, because the test had never started. So CI said failed and Test Reporting said skipped.Change
service.ts:_mochaFailHookAffectedTests: on for Mocha unlessmochaOpts.failHookAffectedTestsisfalse._hookAffectedTestsFailure()that returns the hook's result as a failure only when:this.skip()hook still reports the tests as skipped.cli/skipReporter.ts:reportSuiteSkipped/reportSkippedTesttake an optional failure and send it through the same event sequence instead of the skipped result. The existing result mapping turns it intofailedwith the error message, stack and type. The bail cascade calls this without a failure, so it is unchanged.insights-handler.ts(non-CLI path): with that failure, the affected tests are sent asTestRunFinishedwith the failure instead ofTestRunSkipped.failHookAffectedTests: false;Verification
service.test.ts: BEFORE_EACH / BEFORE_ALL fail with the hook error; optionfalse, AFTER_EACH and athis.skip()hook stay skipped; the non-CLI handoff.cli/skipReporter.test.ts: the failure propagates to nested suites.insights-handler.test.ts: finished-with-failure vs skipped.main. Full package suite: 58 files / 1,504 tests pass; build and lint clean.End to end on BrowserStack: WebdriverIO 10.2.0 (
@wdio/cli,@wdio/local-runner,@wdio/mocha-framework10.2.0, Mocha 12.0.3), CLI flow, Chrome on Windows 11, Test Reporting on. One spec with abeforeEachthat throws and 2 tests. The service was installed fromnpm packofmainand of this branch.mainqffjianrcxbd4nf3i2xdrulrbb1ww47qeg8ehh59cnxniqlqr4giogckdbaaygqzvymlezqazywlrqc8failHookAffectedTests: false0dwf0uec0f2i22op6vjeau14evhdddylx4r0ymatThere are no duplicate test rows, and both tests stay linked to the session.
Not covered end to end:
beforeEachfailing while running a test in a child suite (the cascade starts from the test's parent, as the skip cascade does);maxParallelContexts;Mocha
retriesbehaves as before.Related Jira task/s
Release (mandatory for every PR — required for the
ready-for-reviewlabel)Version bump: (required — tick exactly one)
Release notes type: (optional)
Release notes (customer-facing): (optional but encouraged)
before/beforeEachhook showing as skipped in Test Reporting. They are now reported as failed with the hook's error, matching WebdriverIO 10's defaultfailHookAffectedTests.Release notes (internal): (required — engineer-facing; what actually changed / why)
reportSuiteSkippedand the non-CLI insights handler) now reports BEFORE_ALL/BEFORE_EACH-affected tests as failed with the hook's result whenmochaOpts.failHookAffectedTestsis notfalse, to match Mocha 12 under@wdio/mocha-framework10. AFTER_EACH and the opt-out keep the skipped report.Checklist
PR Validations
Run Tests: Comment RUN_TESTS to trigger sanity tests.
🤖 Generated with Claude Code