Skip to content

fix(cli): keep grep-excluded tests out of the hook-failure cascade [v10] - #400

Open
harshit-browserstack wants to merge 4 commits into
mainfrom
fix/SDK-8298-rerun-reporting-v10
Open

harshit-browserstack wants to merge 4 commits into
mainfrom
fix/SDK-8298-rerun-reporting-v10

Conversation

@harshit-browserstack

Copy link
Copy Markdown
Collaborator

What is this about?

Port of #398 (v9) to main / 10.x.

When a before/beforeEach/afterEach hook fails, or mocha bail fires, reportSuiteSkipped reports every test in the suite whose state is undefined — as skipped, or as failed when mocha's failHookAffectedTests is on (the @wdio/mocha-framework 10 default). Mocha leaves tests rejected by --mochaOpts.grep in exactly that state, so in a grep rerun every grep-excluded test in the suite was reported and replaced its earlier result on the dashboard.

This change excludes tests rejected by the active mochaOpts.grep / fgrep / invert from the cascade — both the CLI cascade (cli/skipReporter.ts) and the legacy cascade used when the CLI binary is not running (insights-handler.ts). A string grep is compiled by the project's own Mocha (Mocha.prototype.grep), so the cascade uses exactly the pattern the runner applies; a RegExp grep is used as-is; fgrep is a substring match applied after grep, as in Mocha. If Mocha cannot be resolved or the pattern does not compile, the cascade keeps today's behaviour. Tests the grep selected but a failed hook dropped are still reported. The only conflict with main was the failHookAffectedTests setup in the service.ts constructor; both are kept.

Note: mocha 12's failAffectedTests marks every remaining test in the suite failed, grep-excluded ones included, so the local spec reporter lists them as failing. With this change the dashboard keeps their earlier result instead.

Testing (@wdio/cli 10.2.0, @wdio/mocha-framework 10.2.0, mocha 12.0.3, Node 24.22.1; first run, then a rerun with --spec + --mochaOpts.grep '<one test>' attached to the same build, with a failing beforeEach in the rerun):

  • Before (10.0.1, CLI flow): the 4 grep-excluded tests show failed after the rerun, although they passed in the first run.
  • After (CLI flow): the 4 excluded tests keep passed; the grep-selected test dropped by the hook is failed.
  • Legacy path (CLI binary forced to fail to start): before → all 5 tests failed; after → the 4 excluded tests keep passed, the hook-dropped test is failed.
  • Not run locally: lint / type-check / unit tests (the workspace could not install this repo's dependencies); CI runs them. The end-to-end verification used the published 10.0.1 bundle with this change applied.

Related Jira task/s

SDK-8298

Release (mandatory for every PR — required for the ready-for-review label)

Version bump: (required — tick exactly one)

  • minor (backwards-compatible feature)
  • patch (bug fix or other small change)

Release notes type: (optional)

  • New Feature
  • Bug Fix
  • Other Improvement

Release notes (customer-facing): (optional but encouraged)

  • Fixed tests excluded by mochaOpts.grep being reported as skipped or failed when a hook failed during the run.

Release notes (internal): (required — engineer-facing; what actually changed / why)

  • reportSuiteSkipped (hook-failure and bail cascades) and the legacy insights-handler hook cascade now skip tests rejected by the active mochaOpts.grep/fgrep/invert; mocha leaves those tests with state === undefined, the same as tests a failed hook dropped.

Checklist

  • Ready to review
  • Has it been tested locally?

PR Validations

Run Tests: Comment RUN_TESTS to trigger sanity tests.

🤖 Generated with Claude Code

harshit-browserstack and others added 4 commits December 1, 2026 17:29
…DK-8298)

When a before/after-each hook fails or mocha bail fires, reportSuiteSkipped
reports every test whose state is undefined as skipped. Mocha leaves tests
its grep rejected in that same state and never reports them, so a
--mochaOpts.grep rerun marked every excluded test as skipped, replacing its
first-run result on the dashboard.

Exclude tests that the active mochaOpts.grep / fgrep / invert rejects,
compiled the same way Mocha 10 does. Tests the grep selected but a failed
hook dropped are still reported.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…-8298)

insights-handler's hook-failure cascade, used when the CLI binary is not
running, had the same `state === undefined` check and still reported
grep-excluded tests as TestRunSkipped. Reuse isExcludedByGrep there.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…de (SDK-8298)

Building a RegExp from mochaOpts.grep in the service duplicated Mocha's
conversion and needed a non-literal RegExp. fgrep is now a substring
match, and a string grep is compiled by the project's own Mocha
(Mocha.prototype.grep), so the cascade uses exactly the pattern the runner
applies. If Mocha cannot be resolved, the cascade keeps today's behaviour.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

  • Source mode: Auto (fallback from Default branch)
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Central YAML (base), Organization UI (inherited), Workspace UI (inherited); Enforced overrides: Organization
  • Review profile: ASSERTIVE
  • Plan: Enterprise
  • Run ID: 10128655-7271-4e49-8fe7-547a8cbd8545

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@github-actions

github-actions Bot commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

🔴 SDK PR Review gate is red. Pending:

  • The SDK PR Review Agent has not been run on the current head commit yet — run the SDK PR Review Agent (its verdict is advisory; this gate only requires that it ran on the latest commit).

It turns green once the SDK PR Review Agent has run on the current head commit (any verdict — the gate only requires that the review ran). A native reviewer approval is separately required by branch protection before merge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant