问题
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.
回答1:
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
"test": "./node_modules/istanbul/lib/cli.js cover ./node_modules/.bin/_mocha ./test/*.js -- --recursive -R spec -r should"
After running test, i am able to see results on
http://localhost:<PORT>/coverage
Hope this helps.
来源:https://stackoverflow.com/questions/23904568/istanbul-cover-report-is-wrong-for-test-with-mocha-using-mongoose