2017-08-02 45 views
0

我想在自己的過程中運行多個測試並以某種方式組合伊斯坦布爾報告。多個腳本(或組合覆蓋率報告)的單個istanbul命令

例如,兩種實現:

//sut1.js 
'use strict' 
module.exports = function() { 
    return 42 
} 

//sut2.js 
'use strict' 
module.exports = function() { 
    return '42' 
} 

和兩個測試:

//test1.js 
'use strict' 
const expect = require('chai').expect 
const sut1 = require('./sut1.js') 
expect(sut1()).to.equal(42) 
expect(sut1()).not.to.equal('42') 
console.log('looks good') 

和:

//test2.js 
'use strict' 
const expect = require('chai').expect 
const sut2 = require('./sut2.js') 

describe('our other function', function() { 
    it('should give you a string', function() { 
    expect(sut2()).to.equal('42') 
    }) 

    it('should not give a a number', function() { 
    expect(sut2()).not.to.equal(42) 
    }) 
}) 

我能得到一個覆蓋報告任何一個這樣的:

istanbul cover --print both test1.js 
istanbul cover --print both -- node_modules/mocha/bin/_mocha test2.js 

什麼是得到一個綜合覆蓋率報告最簡單的方法?有沒有一個班輪也可以輸出呢?使用摩卡或茉莉花,您可以傳入多個文件,但在這裏我想要實際運行不同的腳本。

回答

0

如果有人有興趣,答案是:

  • 不使用伊斯坦布爾;用紐約 - 這樣就可以通過可執行文件給它 ,而不是僅僅JavaScript文件
  • 把兩個測試在bash文件 在一起,然後運行以伊斯坦布爾

...

# test.sh 
node test1.js 
node_modules/mocha/bin/mocha test2.js 

再這樣下去

nyc ./test.sh 

,你會看到聯合測試輸出:

----------|----------|----------|----------|----------|----------------| 
File  | % Stmts | % Branch | % Funcs | % Lines |Uncovered Lines | 
----------|----------|----------|----------|----------|----------------| 
All files |  100 |  100 |  100 |  100 |    | 
sut1.js |  100 |  100 |  100 |  100 |    | 
sut2.js |  100 |  100 |  100 |  100 |    | 
test1.js |  100 |  100 |  100 |  100 |    | 
test2.js |  100 |  100 |  100 |  100 |    | 
----------|----------|----------|----------|----------|----------------| 

你也可以做它的package.json的腳本是這樣的:

"_test": "node test1.js && mocha test2.js", 
"test": "nyc npm run _test", 
相關問題