mocha --watch doesn't work with v6.0.0

Created on 19 Feb 2019  路  12Comments  路  Source: mochajs/mocha

Prerequisites

  • [x] Checked that your issue hasn't already been filed by cross-referencing issues with the faq label
  • [ ] 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 (only tested in my machine, in the same project).
  • [x] 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) and mocha --version(Global). We recommend avoiding the use of globally installed Mocha. (N/A - no global version installed)

Description

mocha --watch doesn't detect the tests. Output: 0 passing (10 ms). It did in the 5.2.0 version.

Steps to Reproduce

Update to 6.0.0, write a test or use the ones you already have and try to execute the watcher. mocha will work, mocha --watch wont.

Expected behavior: [What you expect to happen]

  • mocha --watch detect the tests,
  • and executes every time a test or a src file change.

Actual behavior: [What actually happens]

  • mocha --watch doesn't detect any test.

Reproduces how often: [What percentage of the time does it reproduce?]

100%

Versions

  • The output of mocha --version and node node_modules/.bin/mocha --version: 6.0.0
  • The output of node --version: 11.9.0
  • The version and architecture of your operating system: Ubuntu 18.04.1 LTS, 4.15.0-45-generic x86_64
  • Your shell (bash, zsh, PowerShell, cmd, etc.): bash
  • Your browser and version (if running browser tests): N/A
  • Any other third party Mocha related modules (with versions): [email protected]
  • The code transpiler being used:

Additional Information

confirmed-bug

Most helpful comment

many thanks @plroebuck I created a plain vanilla repo with the same result. My sincere thanks to the mocha team. I know how hard it is to push out code 馃

All 12 comments

I can confirm that I am seeing similar issues. I just tried version 6 and the --watch is not working as it was in 5. I am working on a mac book pro. I pushed branch up to show the issue.

npm run test:watch-mocha

if you downgrade to mocha 5, watch will start working.

This is a typescript based project of my own but simpler pure JS projects have the same issue. I have updated the readme on this branch with instructions. I'm sure you may not need additional examples but here you are anyway.

Using Glen's repo, migrated all test related code into "test" directory.

$ DEBUG=mocha:watch mocha --require 'test/register.js' --watch 'src/**/*.ts' 'test/**/*.spec.ts' --extensions 'ts,js'

  0 passing (1ms)

  mocha:watch file /tmp/sample-node-typescript-module/src/foo.js +0ms
  mocha:watch file /tmp/sample-node-typescript-module/test/cmd/index.spec.js +2ms
  mocha:watch file /tmp/sample-node-typescript-module/test/register.js +0ms

Running this, I don't see any TypeScript files getting picked up (as though --watch-extensions was just ".js"). Adding JS files would increase output watched files.

Does it work for anyone on a vanilla JS project (i.e., no transpiling)?

many thanks @plroebuck I created a plain vanilla repo with the same result. My sincere thanks to the mocha team. I know how hard it is to push out code 馃

It doesn't work in my vanilla JS project neither, that's where I originally got the bug

@plroebuck only --watch-extensions and --extension are currently valid (not --extensions)

I'm having trouble reproducing any problems with @ghinks's repo. (thanks for the repo)

(the typescript repo, anyway)

OK, I can confirm a problem with the vanilla one

OK, I think I have a fix. unfortunately the watch stuff is tough to test.

see #3755

Sincere thanks

@plroebuck only --watch-extensions and --extension are currently valid (not --extensions)

Why the naming mismatch?
And why didn't I get an error using an invalid cmdline option?

Was this page helpful?
0 / 5 - 0 ratings