Skip to content

fix: run all .only tests across different nesting levels - #5878

Open
mostafaNazari702 wants to merge 1 commit into
mochajs:mainfrom
mostafaNazari702:fix/only-across-nesting-levels
Open

fix: run all .only tests across different nesting levels#5878
mostafaNazari702 wants to merge 1 commit into
mochajs:mainfrom
mostafaNazari702:fix/only-across-nesting-levels

Conversation

@mostafaNazari702

Copy link
Copy Markdown
Contributor

PR Checklist

Overview

filterOnly() had a bug where using .only at different nesting levels
would cause nested .only tests to get dropped. For example:

describe('parent', function() {
    it.only('top-level', function() {});
    describe('child', function() {
        it.only('nested', function() {});
    });
});

Only "top-level" woud run -- "nested" was silently discarded because the
_onlyTests branch set this.suites = [], wiping out all child suites
regardless of weither they had .only content.

the fix moves the suite filtering logic out of the else branch so it always
runs. Child suites without any .only content still get pruned correctly.

@codecov

codecov Bot commented Apr 10, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 63.06%. Comparing base (5b27e3a) to head (a1ba87c).

Files with missing lines Patch % Lines
lib/suite.js 0.00% 6 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5878      +/-   ##
==========================================
+ Coverage   63.05%   63.06%   +0.01%     
==========================================
  Files          64       64              
  Lines        4942     4941       -1     
  Branches     1120     1120              
==========================================
  Hits         3116     3116              
+ Misses       1826     1825       -1     

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

@mark-wiemer

Copy link
Copy Markdown
Member

No major complaints at a glance, and the test failure is flaky. Thank you :) it will be some time before we're able to review all these PRs, we are focusing on converting from CJS to ESM right now to release Mocha 12 :)

@JoshuaKGoldberg JoshuaKGoldberg added the semver-major implementation requires increase of "major" version number; "breaking changes" label May 16, 2026

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

Yup, this looks great. Nicely done! 🔥

As Mark said, we're focusing on getting v12 out the door with minimal breaking changes. And this is a semver-major change. Which means it'll have to wait for v13.

@JoshuaKGoldberg JoshuaKGoldberg added the status: blocked Waiting for something else to be resolved label May 16, 2026
@mostafaNazari702
mostafaNazari702 force-pushed the fix/only-across-nesting-levels branch from 6896452 to 13bc79d Compare July 19, 2026 18:14
@mark-wiemer mark-wiemer added this to Mocha Sep 2, 2026
When a suite had both direct .only tests and nested suites containing
.only content deeper in the tree, filterOnly() discarded the nested
suites entirely. This happened because the _onlyTests branch set
this.suites = [] unconditionally.

Move suite filtering logic (via _onlySuites) out of the else branch so
it runs regardless of whether direct .only tests exist. Non-only child
suites without any .only descendants are still correctly removed.

Fixes mochajs#4836
@mostafaNazari702
mostafaNazari702 force-pushed the fix/only-across-nesting-levels branch from 13bc79d to a1ba87c Compare September 5, 2026 19:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

semver-major implementation requires increase of "major" version number; "breaking changes" status: blocked Waiting for something else to be resolved

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

🐛 Bug: Multiple .only should run all targeted tests even in a different context

3 participants