Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I am getting 0 % coverage 0 SLOC in mocha code coverage using blanket

I am trying to get the code coverage in MOCHA JS test. I am using the blanket and the but I am getting 0 % coverage 0 SLOC why I am not understanding. my package.json is

{
  "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 is

exports.sanitize = function(word){


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

exports.testToString = function(){


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

and indexSpec.js which is under test folder is

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');
    });
} )
like image 394
user993158 Avatar asked Apr 24 '15 19:04

user993158


1 Answers

Paul is right. There is no point in using buggy library. Steps for making this code work with Istanbul:

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

  2. Generage coverage report: npm run coverage

Coverage report will be available in coverage/lcov-report/index.html

like image 76
user2811588 Avatar answered Oct 26 '22 00:10

user2811588