Skip to content

fix: keep watching when the last test file is removed - #6355

Merged
mark-wiemer merged 1 commit into
mochajs:mainfrom
mostafaNazari702:watch-empty
Sep 19, 2026
Merged

mark-wiemer merged 1 commit into
mochajs:mainfrom
mostafaNazari702:watch-empty

Conversation

@mostafaNazari702

Copy link
Copy Markdown
Contributor

PR Checklist

Overview

mocha --watch quit as soon as it had no test files left so deleting or renaming your last spec file killed the watcher. Now it warns and runs nothing and keeps waiting then picks the tests back up when a file shows up again.

Two separate things were going on here. In serial mode it killed the process outright. With the --parallel flag the process actually survived and did not get terminated but it printed a raw stack trace and skipped the run because it tried to unload a test file that was no longer on disk. Fixed both since they were hit from the same action.

One nice thing about this is that running --watch in a project with no tests yet no longer exits straight away which fixes the case Josh raised in issue. A normal run without --watch is unchanged and it still shows the same error and exits with code 1.

@codecov

codecov Bot commented Sep 17, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 91.66667% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 63.42%. Comparing base (d59467a) to head (fbefb54).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
lib/nodejs/file-unloader.js 83.33% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6355      +/-   ##
==========================================
+ Coverage   63.38%   63.42%   +0.03%     
==========================================
  Files          64       64              
  Lines        4971     4979       +8     
  Branches     1102     1128      +26     
==========================================
+ Hits         3151     3158       +7     
- Misses       1820     1821       +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 mark-wiemer added status: needs review a maintainer should (re-)review this pull request status: blocked Waiting for something else to be resolved labels Sep 19, 2026
@mark-wiemer

Copy link
Copy Markdown
Member

Starting to think we may need to consider this a breaking change, I've reached out to @JoshuaKGoldberg . More details in backing issue.

@mark-wiemer mark-wiemer removed status: blocked Waiting for something else to be resolved status: needs review a maintainer should (re-)review this pull request labels Sep 19, 2026
@mark-wiemer

Copy link
Copy Markdown
Member

We agree this is a non-breaking change :)

@mark-wiemer
mark-wiemer merged commit 921c161 into mochajs:main Sep 19, 2026
101 of 102 checks passed

@h91860993-maker h91860993-maker left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Levae review

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: Mocha quits watching when all tests file are removed

3 participants