我使用毛毯在摩卡代码覆盖范围内获得0%覆盖0 SLOC

我正在尝试在MOCHA JStesting中获得代码覆盖率。 我正在使用毯子,但我得到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, ' '); } 

和正在testing文件夹中的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'); }); } ) 

保罗是对的。 使用越野车库没有意义。 使这个代码与伊斯坦布尔合作的步骤:

  1. 在全球安装伊斯坦布尔npm install -g istanbul
  2. 在package.json中更改脚本部分
  "scripts": { "test": "mocha", "coverage": "istanbul cover node_modules/mocha/bin/_mocha -- -R spec" }, 
  1. inputnpm test

  2. 生成报告报告: npm run coverage

覆盖率报告将在coverage/lcov-report/index.html

从git回购获得毯子。 我不知道他们的npm软件包有什么问题,但是它也不适用于我。

从git仓库获取模块工作正常。

package.json文件中进行以下更改

 "devDependencies": { "chai": "~2.2.0", "mocha": "~2.2.4", "blanket": "git://github.com/alex-seville/blanket.git" }, 

我有这个问题,并在Neilskrijgerbuild议在我的根目录中添加一个blanket.js文件… https://github.com/alex-seville/blanket/issues/361 。 然后我在我的package.json中设置我的毯子模式到“/ lib”,这是我的源代码的根,它的工作。 正斜杠是必需的。 我的testing脚本是“mocha –require blanket -R html-cov –recursive> coverage.html”。

看来我们很多人都使用了相同的教程,并遇到了同样的问题。

我已经尝试了在这个页面上给出的所有提示(试用节点版本:node-v4.3.1和node-v5.7.0)+几个没有任何运气我结束了另一个包伊斯坦布尔 ,我应该从一开始因为我通常使用统计信息作为使用哪个包的指示器(它被更多的用户使用)。 首先尝试这个包,它的工作原理:-)我把这个添加到package.json的脚本部分:

“coverage”:“./node_modules/.bin/istanbul cover ./node_modules/mocha/bin/_mocha -R spec”