Skip to content

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

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

fix: run all .only tests across different nesting levels#5878
mostafaNazari702 wants to merge 1 commit intomochajs: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.

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
@codecov
Copy link
Copy Markdown

codecov bot commented Apr 10, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.75%. Comparing base (e15bbda) to head (6896452).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5878      +/-   ##
==========================================
+ Coverage   89.71%   89.75%   +0.04%     
==========================================
  Files          64       64              
  Lines        4695     4694       -1     
  Branches      978      978              
==========================================
+ Hits         4212     4213       +1     
+ Misses        483      481       -2     

☔ View full report in Codecov by Sentry.
📢 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.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant