伊斯坦布尔封面报告在摩卡咖啡中测试不正确(使用猫鼬) [英] Istanbul cover report is wrong for test with mocha (using Mongoose)

查看:116
本文介绍了伊斯坦布尔封面报告在摩卡咖啡中测试不正确(使用猫鼬)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经尝试过伊斯坦布尔为我的应用程序进行掩护测试.一切似乎都可以正常工作,但是某些方法被标记为未覆盖,并且我确信(由于日志的缘故)那些功能已被覆盖. 这是我要测试的代码(使用Mongoose):

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);

和我的测试班:

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

任何线索将不胜感激.

JM.

推荐答案

我遇到了类似的问题,并且设法使用 按照他们页面上的说明,伊斯坦布尔中间件.

I had similar issue, and I have managed to make it work using Istanbul middleware, by following instructions on their page.

在脚本部分的package.json中,我已添加

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

希望这会有所帮助.

这篇关于伊斯坦布尔封面报告在摩卡咖啡中测试不正确(使用猫鼬)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆