nyc: NYC output is empty
I have been trying for hours to find the problem here, but I can’t, I tried many things, this is my test file (unit-test.js
) inside projectRoot/test
var should = require('should');
var arr = [1, 2, 3];
function ap(ar) {
a = ar;
var L = a.length;
if (L > 1) {
a[L] = 4;
}
console.log(a);
return a;
}
describe('#indexOf()', function () {
it('should return -1 when the value is not present', function () {
if (arr.length > 1) {
should.equal(ap(arr)[3], 4);
//should.equal(arr[2],3);
}
});
});
And this is my package.json:
{
"name": "jsonave-test",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"lint": "eslint .",
"test": " mocha test/unit-test.js --check-leaks --recursive --exit",
"cover": "nyc npm test"
},
"author": "",
"license": "ISC",
"dependencies": {
"http": "0.0.0",
"jsonapter": "^2.0.3",
"jsonave": "0.0.3",
"moment": "^2.21.0",
"nock": "^9.2.3",
"should": "^13.2.1"
},
"devDependencies": {
"eslint": "^4.19.1",
"nyc": "^11.7.1"
}
}
when i run , the output shows coverage all 0% and no file name is mentioned, as shown below
$ npm run cover
> jsonave-test@1.0.0 cover C:\Users\h\WebstormProjects\jsonave-test
> nyc mocha
#indexOf()
[ 1, 2, 3, 4 ]
√ should return -1 when the value is not present
1 passing (0ms)
----------|----------|----------|----------|----------|-------------------|
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
----------|----------|----------|----------|----------|-------------------|
All files | 0 | 0 | 0 | 0 | |
----------|----------|----------|----------|----------|-------------------|
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 34
- Comments: 36 (9 by maintainers)
The problem is, Mocha is not exiting after its execution. So coverage report is unable to print as the execution is hold by mocha. In Script of package.json mention --exit after mocha. EX- nyc --reporter=html --reporter=text mocha --exit
OK, makes sense although I had the same empty results even when I tested separate files.
I figured out my issue. I discovered a
node_modules/.cache
directory - deleting this made my coverage report work again. The previous committer had set theinstrument: false
flag in the nyc config. I noticed this and suspected it could be causing the empty results issue so deleted the flag but nyc still produced empty results, hence my confusion (I didn’t know about the cache).I’m really confused by this because all I did to get your example repo working was remove
.nycrc
@75lb I added a second file to your repro, I get coverage when I do that:
lib.js:
test.js:
Result:
Maybe nyc doesn’t provide coverage inside the test files by default?
I have the same issue, reproduced on macOS High Sierra using node v6.14.4 and v11.4.0.
In an empty directory, install the deps.
Create this file
test.js
:Run mocha with nyc.
As you can see, the report is empty. Any ideas?
there are a variety of reasons why coverage might be blank, and this thread seems to not be related to one specific cause. I’m closing this issue, but folks should feel free to open issues more specific to the problems they’re bumping into; ideally with a minimal reproduction in a repo.
The --exit option did not work for me. Is there any alternate fixes for this
In my case the tests are within the src folder and i’m running nyc command like:
nyc mocha --recursive ./src
.The tests are passing but the coverage report is empty!
Thank you. This worked like a charm.
We should add to the troubleshooting steps to add
cache: false
somewhere in your nyc config when trying to reproduce. cc @bcoe [where do you think is best, the Issue template?]Is everyone in this thread satisfied enough to close this issue? Perhaps a PR for 👆? 😃
Hi had the same issue. mocha works correctly but nyc output and empty report.
@Antonius-S feel free to open an issue 👍 just want to make sure we’re very specific about how to reproduce; these catch all issues almost never get solved, because there are multiple causes of empty coverage.
The same issue. Reproduced with stub.js from this post and nyc installed globally. In my case issue seems to happen only with global mocha:
NB: Curiously, the presence of option “all” either in arguments or in
.nycrc
file seems to change some things a bit:though coverage info still weird.
lcov.info
when a call is correct (local mocha):lcov.info
for half-working call (global mocha & “all” option):I have a similar problem where I’m not able to view any tests in the coverage summary. So far, I have:
the flags I have specified are:
in the actual test script
run-vscode-integration-tests-with-top-level-extensions
I have:and my output is
It looks like it’s running all the tests using the node test script I provided and mocha is being invoked internally through the vscode ‘testrunner’, so I’m confused as to what’s going on. Additionally, I do see files generated in the
.nyc_output
folder but the files are empty, and thelcov.info
files have half data as well, so I’m assuming they aren’t writing correctly. I’m running these tests through vscode with typescript. Any help would be appreciated, thanks!I have not worked on that NYC since opening this issue, for those who still have their projects running, if @sibajeeray answer solves the issue, feel free to close it, else I will try something on it in the next couple of days.
So is that a bug in how nyc is processing the config file?