Skip to content

fix(cli): keep grep-excluded tests out of the skipped-test cascade - #398

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

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

Conversation

@harshit-browserstack

@harshit-browserstack harshit-browserstack commented Dec 1, 2026 •

Copy link
Copy Markdown
Collaborator

What is this about?

When a before/beforeEach/afterEach hook fails, or mocha bail fires, reportSuiteSkipped reports every test in the suite whose state is undefined as skipped. Mocha leaves tests rejected by --mochaOpts.grep in exactly that state (it skips them silently — no pending event), so in a grep rerun every grep-excluded test in the suite was reported as skipped 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, so the cascade's purpose is unchanged.

Testing (wdio 9.33.1, mocha 10.8.2, CLI flow; first run, then a rerun with --spec + --mochaOpts.grep '<one test>' attached to the same build, with a failing beforeEach in the rerun):

  • Before (9.39.4 and 9.44.4): the 4 grep-excluded tests show skipped after the rerun, although they passed in the first run and mocha reported 0 pending.
  • After: the 4 excluded tests keep passed; the grep-selected test dropped by the hook is still skipped.
  • Same grep rerun without a hook failure: unchanged (no skips) before and after.
  • Legacy path (CLI binary forced to fail to start): before → all 5 tests skipped; after → the 4 excluded tests keep passed, the hook-dropped test is skipped.
  • Exclusion decision compared with new Mocha(opts).options.grep (mocha 10.8.2) over plain, /re/flags, RegExp-object, fgrep, grep+fgrep, invert and invalid inputs: 54/54 identical.
  • 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 9.44.4 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 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 2 commits December 1, 2026 13:56
…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>
@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: 762373e5-ca1d-4c8d-8950-0b738bd5227c

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

…-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>
@harshit-browserstack

harshit-browserstack commented Dec 1, 2026 •

Copy link
Copy Markdown
Collaborator Author

✅ Good to go

File Status Reason
.changeset/pr-398.md ✅ All Clear Reviewed, no issues found
packages/browserstack-service/src/cli/skipReporter.ts ✅ All Clear Reviewed, no issues found
packages/browserstack-service/src/insights-handler.ts ✅ All Clear Reviewed, no issues found
packages/browserstack-service/src/service.ts ✅ All Clear Reviewed, no issues found

Change map (generated deterministically from the diff)

graph LR
  subgraph nwdio_service["wdio-service"]
    npackages_browserstack_service_src_cli_skipReporter_ts["skipReporter.ts<br/>~76 lines"]
    n_changeset_pr_398_md["pr-398.md<br/>~5 lines"]
    npackages_browserstack_service_src_service_ts["service.ts<br/>~5 lines"]
    npackages_browserstack_service_src_insights_handler_ts["insights-handler.ts<br/>~3 lines"]
  end
Loading

↻ This verdict comment is the review anchor — it's updated in place on each run (the gate posts its status separately).

— SDK PR Review Agent

…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>
@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.

1 similar comment
@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.

@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.

@github-actions

github-actions Bot commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

🟢 SDK PR Review gate is green — the SDK PR Review Agent has run on the current head commit (verdict: success).

This gate confirms a review ran on the latest commit. The verdict itself is advisory — read the findings and use your judgement; it does not block merge. A native GitHub reviewer approval is still separately required by branch protection before this PR can merge.

1 similar comment
@github-actions

github-actions Bot commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

🟢 SDK PR Review gate is green — the SDK PR Review Agent has run on the current head commit (verdict: success).

This gate confirms a review ran on the latest commit. The verdict itself is advisory — read the findings and use your judgement; it does not block merge. A native GitHub reviewer approval is still separately required by branch protection before this PR can 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.

2 participants