[英]I am getting 0 % coverage 0 SLOC in mocha code coverage using blanket
我想在MOCHA JS測試中獲得代碼覆蓋率。 我正在使用毯子而且我得到0%的覆蓋率0 SLOC為什么我不理解。 我的package.json是
{
"name": "basics",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "mocha && mocha test --require blanket --reporter html-cov > coverage.html"
},
"author": "",
"license": "MIT",
"devDependencies": {
"chai": "~2.2.0",
"mocha": "~2.2.4",
"blanket": "~1.1.6",
},
"config": {
"blanket": {
"pattern": ["index.js"],
"data-cover-never": "node_modules"
}
}
}
和index.js是
exports.sanitize = function(word){
return word.toLowerCase().replace(/-/g, ' ');
}
exports.testToString = function(){
return word.toLowerCase().replace(/-/g, ' ');
}
和indexSpec.js在測試文件夾下
var chai = require('chai');
var expect = require('chai').expect;
var word = require('../index.js');
describe ('sanitize', function(){
it('String matching ', function(){
var inputWord = 'hello WORLD';
var outputWord = word.sanitize(inputWord);
expect(outputWord).to.equal('hello world');
expect(outputWord).to.not.equal('HELLO WORLD');
expect(outputWord).to.be.a('string');
expect(outputWord).not.to.be.a('number');
});
it('Checke hyphen ', function(){
var inputWord = 'hello-WORLD';
var outputWord = word.sanitize(inputWord);
expect(outputWord).to.equal('hello world');
});
} )
保羅是對的。 使用buggy庫沒有意義。 使此代碼與伊斯坦布爾一起使用的步驟:
npm install -g istanbul
"scripts": {
"test": "mocha",
"coverage": "istanbul cover node_modules/mocha/bin/_mocha -- -R spec"
},
鍵入npm test
Generage覆蓋率報告: npm run coverage
覆蓋率報告將在coverage/lcov-report/index.html
從git repo獲得毯子。 我不知道他們的npm包有什么問題,但它也不適用於我。
從git repo獲取模塊工作正常。
在package.json
文件中進行以下更改
"devDependencies": {
"chai": "~2.2.0",
"mocha": "~2.2.4",
"blanket": "git://github.com/alex-seville/blanket.git"
},
我有這個問題,並在Neilskrijger推薦的根目錄中添加了blanket.js文件... https://github.com/alex-seville/blanket/issues/361 。 然后我將我的package.json中的毯子模式設置為'/ lib',這是我的源代碼的根,它工作正常。 正斜杠是必需的。 我的測試腳本是“mocha --require blanket -R html-cov --recursive> coverage.html”。
似乎我們很多人使用相同的教程並遇到了同樣的問題。
我已嘗試在此頁面上給出的所有提示(嘗試使用節點版本:node-v4.3.1和node-v5.7.0)+一些沒有任何運氣我最終得到另一個包伊斯坦布爾 ,我應該從一開始就做因為我通常使用統計數據作為使用哪個包的指示符(由更多用戶使用)。 首先嘗試使用這個包,它工作:-)我將它添加到package.json的腳本部分:
“coverage”:“。/ node_modules / .bin / lasbul cover ./node_modules/mocha/bin/_mocha - -R spec”
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.