NYC output is empty

See original GitHub issue

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 |                   |
----------|----------|----------|----------|----------|-------------------|

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:31
  • Comments:34 (9 by maintainers)

github_iconTop GitHub Comments

34reactions
sibajeeraycommented, Jul 4, 2018

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

17reactions
75lbcommented, Jan 2, 2019

Maybe nyc doesn’t provide coverage inside the test files by default?

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 the instrument: 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).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Empty istanbul (nyc) report while coverage files are filled ...
I expect nyc report --cwd . to show the coverage result, but the report is always empty. Neither files nor coverage results are...
Read more >
Using Istanbul With Mocha
Istanbul is extensively tested with mocha, which we use for many of our own repos. At the end of the day, all you...
Read more >
istanbuljs/nyc - Gitter
hm I thought I tried that already which empty reports, I check it again then ... of the coverage output, and we're like...
Read more >
nyc | Yarn - Package Manager
If nyc fails to find a directory containing a package.json file, it will use the current working directory as the default project root...
Read more >
Ubuntu Manpage: nyc.js - istanbul command line interface
--nycrc-path specify an explicit path to find nyc configuration -t, --temp-dir directory to output raw coverage information to [string] [default: ".
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found