Mocha: double asterisk not working on mac

Created on 15 May 2017  路  6Comments  路  Source: mochajs/mocha

I'm calling mocha with this line:
mocha --compilers js:babel-register --require ignore-styles --require babel-polyfill ./client/**/*.spec.js

It does work perfectly on windows machines, but on mac it only handles tests from the first level of directories, ie.
./client/dirA/testA.spec.js
but not test that are located deeper, ie.
./client/dirA/dirB/testB.spec.js

It looks like a bug, but for now I'm looking for a quick workaround for it.

faq

Most helpful comment

It's not so much a bug as a bad interaction between the conventions Mocha implements and the conventions your shell is configured to follow -- if you don't quote the path, the stars may be handled by the shell before the argument is even passed to Mocha, and some shells treat ** the same as * instead of using the multi-directory behavior (at least by default; might be configurable in "globstar" settings...).

The workaround at the project level is to use "./path/**/*.to.tests.js" instead of ./path/**/*.to.tests.js, which should work everywhere (since " is a valid argument quote on both Windows and Posixy shells).

All 6 comments

It's not so much a bug as a bad interaction between the conventions Mocha implements and the conventions your shell is configured to follow -- if you don't quote the path, the stars may be handled by the shell before the argument is even passed to Mocha, and some shells treat ** the same as * instead of using the multi-directory behavior (at least by default; might be configurable in "globstar" settings...).

The workaround at the project level is to use "./path/**/*.to.tests.js" instead of ./path/**/*.to.tests.js, which should work everywhere (since " is a valid argument quote on both Windows and Posixy shells).

Thanks, quotes solved the problem. I didn't know that shell preprocess that paths. Now it looks logical.

Glad we could help!

@ScottFreeCode
I'm wondering if there is a bug. I'm getting this error on both OSX and Linux:
screen shot 2017-12-12 at 18 29 33
screen shot 2017-12-12 at 18 31 32
screen shot 2017-12-12 at 18 33 29

MacOS comes with Bash version 3, not Bash version 4.

TMK, globbing works better on Bash version 4

If you take a closer look at the screenshots, the last two are taken in Linux. Glob or - - recursive, same result regardless of platform

Was this page helpful?
0 / 5 - 0 ratings

Related issues

enigmatic00 picture enigmatic00  路  3Comments

danielserrao picture danielserrao  路  3Comments

CADBOT picture CADBOT  路  3Comments

luoxi001713 picture luoxi001713  路  3Comments

Swivelgames picture Swivelgames  路  3Comments