No coverage nyc mocha

Faraz picture Faraz · May 22, 2018 · Viewed 9.3k times · Source

I am just unable to figure out why test coverage is 0 even though test case is passing. I have a script in package.json:

"nyctest": "node --max_old_space_size=4096 node_modules/nyc/bin/nyc.js --reporter=text mocha"

When I run npm run nyctest

My test pass, but coverage is 0 percent.

enter image description here

Following is the test and the file is it testing:

test.js

var chai = require('chai');
var sinon = require('sinon');
var sinonChai = require('sinon-chai');
chai.should();
chai.use(sinonChai);
var application = require('../../../src/main/resources/static/js/components/app.js');

describe('sample return testing', function(){
    it('should return true', function(){
        application.sample.returnValue().should.equal(true);
    })
});

app.js

const sample = {
    returnValue: function () {
        return true;
    }
};

module.exports = {sample};

Appreciate any help.

Answer

Stéphane de Luca picture Stéphane de Luca · Aug 20, 2020

By August 2020: two things:

  1. You need to add de --all parameter.
  2. Preferably use the .nycrc file in order not to have large command line in your package.json as follows:

The minimal .nycrc file:

{
  "all": true,
  "include": [
    "test/**.js"
  ],
  "exclude": [
  ]
}