I get 0% coverage 0 SLOC in mocha code coverage using a blanket

I am trying to get code coverage in the MOCHA JS test. I use a blanket, but I get 0% coverage 0 SLOC, why I do not understand. my 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" } } } 

and index.js

 exports.sanitize = function(word){ return word.toLowerCase().replace(/-/g, ' '); } exports.testToString = function(){ return word.toLowerCase().replace(/-/g, ' '); } 

and indexSpec.js located in the test folder,

 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'); }); } ) 
+7
javascript mocha chai
source share
4 answers

Paul is right. It makes no sense to use the buggy library. Steps to create this code in Istanbul:

  • Install Istanbul Worldwide npm install -g istanbul
  • Change script section in package.json
  "scripts": { "test": "mocha", "coverage": "istanbul cover node_modules/mocha/bin/_mocha -- -R spec" }, 
  1. Run the test by typing npm test

  2. Generation npm run coverage Report: npm run coverage

A coverage report will be available at coverage/lcov-report/index.html

+1
source share

Get coverage from the git repository. I don't know what happened to their npm package, but that didn't work for me either.

Getting the module from the git repository works fine.

Make the following changes to the package.json file

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

I had this problem and I added the blanket.js file to my root directory as recommended by Neilskrijger here ... https://github.com/alex-seville/blanket/issues/361 . Then I installed my blanket template in my package.json package in '/ lib', which was the root of my source code, and it worked. Slash required. My test script was "mocha --require blanket -R html-cov --recursive> coverage.html".

0
source share

It seems that many of us used the same tutorial and faced the same problem.

I tried all the hints given on this page (tried with node versions: node -v4.3.1 and node -v5.7.0) + some more with no luck I ended up with another Istanbul package, which I had to do from the very beginning, since I usually use statistics as an indicator of which package to use (many more users use it). First try with this package and it worked :-) I added this to the script section of package.json:

"cover": "./ node_modules / .bin / istanbul cover./node_modules/mocha/bin/_mocha - -R spec"

0
source share

All Articles