mochajs / mocha

☕️ simple, flexible, fun javascript test framework for node.js & the browser
https://mochajs.org
MIT License
22.63k stars 3.02k forks source link

Mocha 7.0.1 quits watching when all tests file are removed #4169

Open normanzb opened 4 years ago

normanzb commented 4 years ago

Prerequisites

Description

Mocha 7 quits watching process when the test folder is deleted

Steps to Reproduce

  1. Install mocha 7.0.1 npm i mocha@7.0.1 -D
  2. Create a simple test file in "test" folder
  3. Start mocha in watching mode: ./node_modules/.bin/mocha --watch
  4. 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

Additional Information

craigtaub commented 4 years ago

Is there a scenario where it is useful for mocha to continue watching here rather than quit? A lot has changed since v6 and the expected behaviour when no test files are found is to exit the current process, regardless of watch mode.

JoshuaKGoldberg commented 10 months ago

🤔 I can see an argument that Mocha being run in watch mode is an indication it's meant as a long-lived development utility. As in, you might start it, then write your tests.

cc @mochajs/maintenance-crew - I think we can consider this a bug and accepting PRs. What do you think?