我使用毯子在mocha代码覆盖范围内获得0%覆盖0 SLOC

use*_*158 7 javascript mocha.js node.js chai blanket.js

我想在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"
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

和index.js是

exports.sanitize = function(word){


    return word.toLowerCase().replace(/-/g, ' ');
}

exports.testToString = function(){


    return word.toLowerCase().replace(/-/g, ' ');
}
Run Code Online (Sandbox Code Playgroud)

和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');
    });
} )
Run Code Online (Sandbox Code Playgroud)

Jay*_*nki 0

从 git 仓库获取毯子。我不知道他们的 npm 包有什么问题,但它对我来说也不起作用。

从 git repo 获取模块工作正常。

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

"devDependencies": {
    "chai": "~2.2.0",
    "mocha": "~2.2.4",
    "blanket": "git://github.com/alex-seville/blanket.git"
},
Run Code Online (Sandbox Code Playgroud)