mocha: --watch and --recursive command line parameters not executing tests correctly on Windows

Setup

Tested with node 6.2.2 (https://nodejs.org/dist/v6.2.2/node-v6.2.2-x64.msi) and current master build (v7.0.0-pre) built with MinGW 64 compiler on Windows 8.1 npm install mocha -g installs mocha 2.5.3 with warnings

npm WARN deprecated jade@0.26.3: Jade has been renamed to pug, please install the latest version of pug instead of jade npm WARN deprecated minimatch@0.3.0: Please update to minimatch 3.0.2 or higher to avoid a RegExp DoS issue

Going through walkthrough https://www.codementor.io/nodejs/tutorial/unit-testing-nodejs-tdd-mocha-sinon Same results executing in a DOS prompt, or a MinGW64 console.

Steps

Running mocha tests --recursive --watch --colors where tests is a root level directory containing tests. Correctly runs tests initially.

CartSummary √ getSubtotal() should return 0 if no items are passed in √ getSubtotal() should return the sum of the price * quantity of the items

2 passing (6ms)

Then edit a test file to introduce non-breaking change. Output appends

0 passing (0ms)

Any subsequent edits go ignored.

Expected Behaviour

Changes to test files to trigger execution. Subsequent edits to be noticed.

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 2
  • Comments: 26 (13 by maintainers)

Most upvoted comments

For those having issues, please try passing a glob instead of the --recursive flag, and let me know if you have success:

# quotes are necessary
mocha "tests/**/*.js" --watch

UPDATE: Those may need to be backslashes? Try both. Enclosing the globspec in double-quotes means that the glob module will parse it; otherwise your shell would (whatever it is)

I also have problem! windows 8.1 pro only one index.js file in src/test

Button
√ should show the given text
√ should handle the click event

2 passing (63ms)

0 passing (0ms)

But may be this small tip could be usefull: if run the same from Git Bash (for windows) everything works properly.

Thanks @ScottFreeCode the --watch-extensions jsx did the trick, here’s the complete command line.

mocha --watch-extensions jsx --watch --require 'test/javascript/helpers/includes.jsx' 'test/javascript/helpers/browser' 'app/javascript/bundles/**/*.spec.jsx'

I also have such issue on windows. npm version 3.10.3 node version 6.3.1 mocha version 3.0.2

I am having the same issue. I do not have this issue on Mac setup. Debugging through it, it looks like the initial root suite is created with no tests, but with suites with tests, and then on “rerun”, cloning the root suite does not copy the other suites, and no tests are added, so nothing runs on reRun. Not sure why this is only happening on Windows.

As with #2330, I’d suggest using a purpose-built tool for watching. Mocha’s built-in “watch” functionality is limited. Such functionality really deserves something which can support multiple platforms and edge cases.