Mocha: Not all tests are run using npm test vs global mocha

Created on 22 Jun 2016  路  8Comments  路  Source: mochajs/mocha

I have this code in package.json-scripts:

"test": "NODE_ENV=test mocha --compilers js:babel-core/register --require babel-polyfill --require ignore-styles src/**/*.spec.js --recursive"

Only tests at this dir (I have tests in other subdirs of src/client/components aswell) are picked up (11 tests)

If I run this code in bash: (the same code as above):

NODE_ENV=test mocha --compilers js:babel-core/register --require babel-polyfill --require ignore-styles src/**/*.spec.js --recursive

It picks up all my tests (12)

If I add a new test in src/lib (where my picked up tests are), it is picked up, if I add it in a deeper directory, it is not picked up

I am using mocha@^2.5.3 locally and globally (-g)

If I change the globbing pattern to **/*.spec.js, every test is picked up (including node_modules)

Am I doing something wrong here?

Most helpful comment

I solved it. And to me, it's a big #wtf

If I encapsulate the globbing pattern in single quotes, it works as expected globally and locally:

NODE_ENV=test mocha --compilers js:babel-core/register --require babel-polyfill --require ignore-styles 'src/**/*.spec.js' --recursive

Any explanation for this?

All 8 comments

I solved it. And to me, it's a big #wtf

If I encapsulate the globbing pattern in single quotes, it works as expected globally and locally:

NODE_ENV=test mocha --compilers js:babel-core/register --require babel-polyfill --require ignore-styles 'src/**/*.spec.js' --recursive

Any explanation for this?

I was going to suggest double-checking that the pattern in both cases uses /**/ and not /*/, but differences between the JS Glob and shell expansion was my other hunch.

Wew, thanks for posting solution, I didn't know that it uses sh either.

Doesn't src/**/*.spec.js _imply_ a recursive glob?

@boneskull well, yeah, that was a bit iffy tbh. The information I gathered from the documentation did not help (probs to much coffee) at that time, so I tried everything. I have removed it from my code atm.

@phun-ky Well, please follow up if you add it back and try using _just_ the glob. I know some people like to put tests beside source files. Gonna close this for now. Thanks!

Tried with just the glob, works :)

Was this page helpful?
0 / 5 - 0 ratings