nyc: NYC output is empty with mocha installed globally
Extracted from #822 I experience no coverage output when both nyc and mocha installed globally (in fact, only mocha installation plays role). Reproducible repo is here Env: Windows 7 Node 10.15.1 Nyc 13.3.0 Mocha 6.0.2
D:\Projects\nyc-test>nyc mocha
√ should have tests
1 passing (39ms)
----------|----------|----------|----------|----------|-------------------|
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
----------|----------|----------|----------|----------|-------------------|
All files | 0 | 0 | 0 | 0 | |
----------|----------|----------|----------|----------|-------------------|
D:\Projects\nyc-test>npm i mocha
(...) skipped
D:\Projects\nyc-test>nyc node_modules\.bin\mocha
√ should have tests
1 passing (39ms)
----------|----------|----------|----------|----------|-------------------|
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
----------|----------|----------|----------|----------|-------------------|
All files | 100 | 100 | 100 | 100 | |
stub.js | 100 | 100 | 100 | 100 | |
----------|----------|----------|----------|----------|-------------------|
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 1
- Comments: 27 (7 by maintainers)
Commits related to this issue
- corect coverage settings Issule simal to https://github.com/istanbuljs/nyc/issues/1308 (i'm using nvm) Thanks to https://github.com/istanbuljs/nyc/issues/1029#issuecomment-524607893, mainly — committed to rustymotors/server by drazisil 3 years ago
- Logs cleanups (#856) * add service field to tcpmanager logs * add correct type to logger * corect service name for logger * formatting * corect coverage settings Issule simal to https:... — committed to rustymotors/server by drazisil 3 years ago
Same issue , While Running

nyc mocha
But while Running
nyc node_modules/.bin/mocha
``
After maaaany hours of debugging I finally found the problem. It’s the
cmd
andshell
files and spawn-wrap.They check if the node executable is in the same directory as they are, when they are installed as modules they work because there’s no node executable there and it then relies on using the one in the PATH, but it’s there when installed globally.
That’s not a problem on Unix because it uses a symbolic link to the JS file. Unless you use a Windows installation on Unix, then you have the same bug.
My solution right now is to patch
spawn-wrap
with this:It’s a very dirty solution honestly but haven’t put much effort.
Please retest using nyc 15 which replaces spawn-wrap with another method of wrapping child processes.
Can confirm @marek629 solution works for me. In my case, I just need to change from
to