Bug: Mocha quits watching when all tests file are removed
Author: normanzbCreated Jan 27, 2020Updated Sep 17, 2026
Labelstype: bugstatus: accepting prssemver-minorarea: node.js
Prerequisites
- Checked that your issue hasn't already been filed by cross-referencing issues with the
faqlabel - Checked next-gen ES issues and syntax problems by using the same environment and/or transpiler configuration without Mocha to ensure it isn't just a feature that actually isn't supported in the environment in question or a bug in your code.
- 'Smoke tested' the code to be tested by running it outside the real test suite to get a better sense of whether the problem is in the code under test, your usage of Mocha, or Mocha itself
- Ensured that there is no discrepancy between the locally and globally installed versions of Mocha. You can find them with:
node node_modules/.bin/mocha --version(Local) andmocha --version(Global). We recommend that you not install Mocha globally.
Description
Mocha 7 quits watching process when the test folder is deleted
Steps to Reproduce
- Install mocha 7.0.1
npm i [email protected] -D - Create a simple test file in "test" folder
- Start mocha in watching mode:
./node_modules/.bin/mocha --watch - In another terminal window, remove "test" folder:
rm -r test
test.js file:
describe("test",() => {
it('logs', ()=>{console.log(1)})
})Expected behavior: [What you expect to happen] Mocha continues to watching newly added files if any, mocha doesn't quit the process.
Actual behavior: [What actually happens]
Mocha 7 quits with error message: "Error: No test files found: "test"" This is not an issue in mocha@6.
Reproduces how often: [What percentage of the time does it reproduce?] 100%
Versions
- The output of
mocha --versionandnode node_modules/.bin/mocha --version: 7.0.1 - The output of
node --version: v13.3.0 - Your operating system
- name and version: macOS 10.13.6 (17G5019)
- architecture (32 or 64-bit): 64
- Your shell (e.g., bash, zsh, PowerShell, cmd): bash
- Your browser and version (if running browser tests): none
- Any third-party Mocha-related modules (and their versions): none
- Any code transpiler (e.g., TypeScript, CoffeeScript, Babel) being used (and its version): none
Additional Information
Source: mochajs/mocha