2012-01-11 36 views
3

我正在努力讓Expresso設置和一些測試運行。我跟着一個tutorial on node tuts,並有4個測試運行,並通過。現在我試圖在運行測試時看到代碼覆蓋率輸出,如docs顯示。但是,我有點失落。如何使用expresso顯示代碼覆蓋率輸出?

我超基本學習示例測試是在一個文件夾中稱爲test.js名爲test:

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:

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 

    100% 4 tests 

同樣的,如果我有一個運行expresso-c標誌或各種其他選項,我得到相同的輸出。我想要獲得文檔中顯示的代碼覆蓋率輸出。我也運行命令$ node-jscoverage lib lib-cov,而lib-cov文件夾現在有東西..

我在想什麼?

+0

難道不是隻如果你的測試失敗不同的輸出? – fent 2012-01-11 21:05:13

+0

雅,但不管測試通過,應該有額外的代碼覆蓋輸出。圖片示例:http://dl.dropbox.com/u/6396913/cov.png – hookedonwinter 2012-01-11 21:07:20

回答

0

最好成績,我發現到目前爲止是在試運行編輯路徑:

這是run_tests.sh

#! /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