2017-08-02 3 views
0

独自のプロセスでいくつかのテストを実行し、何とかistanbulレポートを結合したいと考えています。例えば複数のスクリプト(または組み合わせたカバレッジレポート)の単一のistanbulコマンド

、2つの実装:

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

複合カバレッジレポートを取得する最も簡単な方法は何ですか?それを出力するライナーは1つありますか?

モカまたはジャスミンを使用すると、複数のファイルを渡すことができますが、ここでは実際には別のスクリプトを実行します。

答えて

0

誰もが興味を持っている場合は、その答えは次のとおりです。

  • は、イスタンブールを使用しないでください。 NYCを使用する - あなたはそれ の代わり
  • が一緒にbashのファイル に2つのテストを置くだけのJavaScriptファイルに実行ファイルを渡し、イスタンブール

とそれを実行できるように...

# 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", 
関連する問題