I've tried Istanbul to get a cover test for my application. All seems to work fine, but some methods are marked as not covered and I'm sure (beacause of logs) that those functions are covered. Here is the code I want to test (using Mongoose) :
var mongoose = require('mongoose'),
Schema = mongoose.Schema;
function BaseSchema(objectName, schema) {
// !!! Marke as not covered
log.trace('BaseSchema CTOR : objectName=%s schema=%s', objectName, schema);
Schema.apply(this, [schema]);
...
this.statics.removeAll = function (cb) {
// !!! marked as not covered
log.debug('Calling %s.removeAll', this._objectName);
this.remove({}, cb);
};
...
util.inherits(BaseSchema, Schema);
and my test class :
describe('Advanced CRUD Account :', function () {
it('Should remove all', function (done) {
account = new Account({
email: 'testu@test.com',
pseudo: 'Testu'
});
Account.removeAll(function () {
done();
});
});
I see the logs so i'm sure the method is well called.
I run the cover test with this command :
istanbul cover node_modules/mocha/bin/_mocha -- -r server.js -R spec test/mocha/**/*.js packages/**/mocha/**/*.js
Any clues will be greatly appreciated.
JM.
I had similar issue, and I have managed to make it work using Istanbul middleware, by following instructions on their page.
In my package.json in scripts section i have added
After running test, i am able to see results on
Hope this helps.