首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用expresso显示代码覆盖率输出?

如何使用expresso显示代码覆盖率输出?
EN

Stack Overflow用户
提问于 2012-01-12 03:48:10
回答 1查看 660关注 0票数 3

我正在设置Expresso并运行一些测试。我使用了一个tutorial on node tuts,运行了4个测试,并且通过了测试。现在,我正在尝试在运行测试时显示代码覆盖率输出,就像docs显示的那样。然而,我有点迷失了。

我的超级基本学习示例测试位于名为test.js的文件夹中的文件中:

代码语言:javascript
复制
var Account = require('../lib/account');

require('should');

module.exports = {
    "initial balance should be 0" : function(){
        var account = Account.create();
        account.should.have.property('balance');
        account.balance.should.be.eql(0);
    },

    "crediting account should increase the balance" : function(){
        var account = Account.create();
        account.credit(10);
        account.balance.should.be.eql(10);
    },

    "debiting account should decrease the balance" : function(){
        var account = Account.create();
        account.debit(5);
        account.balance.should.be.eql(-5);
    },

    "transferring from account a to b b should decrease from a and increase b": function(){
        var accountA = Account.create();
        var accountB = Account.create();
        accountA.credit(100);
        accountA.transfer(accountB, 25);
        accountA.balance.should.be.eql(75);
        accountB.balance.should.be.eql(25);
    }
}

代码本身在lib/account.js中:

代码语言:javascript
复制
var Account = function(){
    this.balance = 0;
}

module.exports.create = function(){
    return new Account();
}

Account.prototype.credit = function(amt){
    this.balance += amt;
}

Account.prototype.debit = function(amt){
    this.balance -= amt;
}

Account.prototype.transfer = function(acct, amt){
    this.debit(amt);
    acct.credit(amt);
}

Account.prototype.empty = function(acct){
    this.debit(this.balance);
}

当我从命令行运行expresso时,我得到:

代码语言:javascript
复制
$ expresso

    100% 4 tests

同样,如果我使用-c标志或各种其他选项运行expresso,也会得到相同的输出。我想获得文档中显示的代码覆盖率输出。我还运行了命令$ node-jscoverage lib lib-cov,现在lib-cov文件夹中包含了一些内容。

我遗漏了什么?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-01-17 05:54:36

到目前为止,我发现的最好的结果是在测试运行时编辑路径:

这是run_tests.sh

代码语言:javascript
复制
#! /bin/bash

rm -Rf ./app-cov
node_modules/expresso/deps/jscoverage/node-jscoverage app/ app-cov
NODE_PATH=$NODE_PATH:/usr/local/lib/node:/usr/local/lib/node_modules:./mmf_node_modules:./app-cov node_modules/expresso/bin/expresso -c
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8825675

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档