Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

--watch and --recursive command line parameters not executing tests correctly on Windows #2327

Closed
WaffleSouffle opened this issue Jun 22, 2016 · 26 comments
Labels
area: windows Windows-specific status: needs mcve a defect report needing more information; subject to closing due to inactivity

Comments

@WaffleSouffle
Copy link

WaffleSouffle commented Jun 22, 2016

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 [email protected]: Jade has been renamed to pug, please install the latest version of pug instead of jade
npm WARN deprecated [email protected]: 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.

@dasilvacontin
Copy link
Contributor

@WaffleSouffle what if you run mocha with less options, eg only --watch and try modifying tests/*.js?

@dasilvacontin
Copy link
Contributor

This appears to be a Windows only bug.

@dasilvacontin dasilvacontin added type: bug a defect, confirmed by a maintainer area: windows Windows-specific labels Jun 22, 2016
@boneskull
Copy link
Contributor

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.

@boneskull
Copy link
Contributor

@dasilvacontin Did you confirm this?

@dasilvacontin
Copy link
Contributor

@boneskull No, I don't have a Windows setup.

@ScottFreeCode
Copy link
Contributor

Just tried to reproduce this on Windows and was unable to do so. I will double-check the tutorial and see if there might be something I missed.

@ScottFreeCode
Copy link
Contributor

...Yeah, I'm not seeing anything different that should affect this. My test doesn't have Chai and stuff, but that shouldn't matter... right?... I've got this on Windows 8.1, same directory structure, same command, Mocha installed globally...

@jnields
Copy link

jnields commented Jul 19, 2016

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.

@dobryanskyy
Copy link

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

@boneskull
Copy link
Contributor

boneskull commented Aug 9, 2016

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)

@boneskull boneskull added the status: accepting prs Mocha can use your help with this one! label Aug 9, 2016
@boneskull
Copy link
Contributor

Any PR here should not grossly add to the level of complexity

@dobryanskyy
Copy link

@boneskull I've tried the workarounds you suggested both with slashes and backslashes with and without recursive flag and double/single quotes. None of that did help

@gurdiga
Copy link

gurdiga commented Aug 10, 2016

@WaffleSouffle @jnields @dobryanskyy Could you please prepare a minimal setup that demonstrates this issue? 🤔

I think this would greatly help to pinpoint the root cause. 🤓

@boneskull
Copy link
Contributor

@dobryanskyy adding to what @gurdiga wrote, please keep it minimal unless you can provide the entire thing. also using "Babel" or "bundling" is a relevant detail; please include those

@boneskull boneskull added unconfirmed and removed status: accepting prs Mocha can use your help with this one! labels Aug 12, 2016
@dobryanskyy
Copy link

@boneskull yes, I'm using babel for jsx and es6 transpilation.

@usulpro
Copy link

usulpro commented Sep 8, 2016

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.

@higimo
Copy link

higimo commented Jun 15, 2017

Windows 7, mocha 3.4.2, cmder
mocha ./test/ --compilers js:babel-core/register --compilers jsx:babel-register -w

0 passing (0ms)

upd: Git shell (from Github Desktop) don`t working.

@ScottFreeCode ScottFreeCode added the status: needs mcve a defect report needing more information; subject to closing due to inactivity label Jun 15, 2017
@stale
Copy link

stale bot commented Oct 17, 2017

I am a bot that watches issues for inactivity.
This issue hasn't had any recent activity, and I'm labeling it stale. In 14 days, if there are no further comments or activity, I will close this issue.
Thanks for contributing to Mocha!

@stale stale bot added the stale this has been inactive for a while... label Oct 17, 2017
@boneskull boneskull removed the stale this has been inactive for a while... label Oct 17, 2017
@boneskull
Copy link
Contributor

not stale

@DonGiulio
Copy link

DonGiulio commented Nov 30, 2017

having the same problem, on osx

this is my command line for running mocha:

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

if I touch the first file: test/javascript/helpers/browser tests get run, but only the first time I save, on further saves, they don't get run any more.

if I touch any of the app/javascript/bundles/**/*.spec.jsx they don't.

I've also tried with --recursive with no luck.

@higimo
Copy link

higimo commented Nov 30, 2017

@usulpro you use a symlink?

I have this problem when using symlink

2 passing (63ms)

0 passing (0ms)

@ScottFreeCode
Copy link
Contributor

Hi @DonGiulio, try adding --watch-extensions jsx and see if that fixes it.

@higimo Could you elaborate on your code's structure and how to create a symlink that will encounter this? I was under the impression that symlinks are treated the same both times, but I'd be interested to take a look at it. (And just to double-check I'm on the same page: Is this on Windows? With cmd, or another shell?)

@DonGiulio
Copy link

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'

@boneskull boneskull removed the type: bug a defect, confirmed by a maintainer label Dec 5, 2017
@boneskull
Copy link
Contributor

I don't think this is actionable.

@javahaxxor
Copy link

I have this issue on both OSX and Linux
screen shot 2017-12-12 at 09 34 48

@Moulde
Copy link

Moulde commented Oct 18, 2018

Adding --watch-extensions ts works for me too (on osx, visual studio code) 👍

mocha -r ts-node/register test/**/*.ts --reporter mochawesome --reporter-options reportDir=TestResults --watch --watch-extensions ts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: windows Windows-specific status: needs mcve a defect report needing more information; subject to closing due to inactivity
Projects
None yet
Development

No branches or pull requests