Istanbul cover report is wrong for test with mocha (using Mongoose)

孤街浪徒 提交于 2019-12-12 12:14:37

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!