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.
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.
nyc is a command line tool for instrumenting code with Istanbul coverage (the successor to the istanbul command line tool). Let's see how we can't integrate nyc into our build and try it out!
Jest --coverage works for our unit tests and correctly reports coverage, so we will temporarily use Jest to cover unit tests and NYC to cover integration tests.
Mocha, a javascript test framework. So istanbul/nyc is a code coverage tool which works well with mocha, they are simple and easy tools that make testing easy. We can install mocha by typing this code in our terminal. We install istanbul with.
By August 2020: two things:
--all
parameter..nycrc
file in order to not have a long command line in your package.json
as follows:The minimal .nycrc
file:
{
"all": true,
"include": [
"test/**.js"
],
"exclude": []
}
You need to modify your nyctest
command with --all
flag, as follows:
"nyctest": "nyc --reporter=lcov --reporter=text-lcov --all -x \"./node_modules/*\" -x \"./coverage/*\" check-coverage --lines 10 --functions 90 npm run unittest"
So with --all
flag, all files are fetched 😄
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With