javascript - I am getting 0 % coverage 0 SLOC in mocha code coverage using blanket -
i trying code coverage in mocha js test. using blanket , getting 0 % coverage 0 sloc why not understanding. 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 under 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'); }); } )
paul right. there no point in using buggy library. steps making code work istanbul:
- install istanbul globally
npm install -g istanbul - change script section in package.json
"scripts": { "test": "mocha", "coverage": "istanbul cover node_modules/mocha/bin/_mocha -- -r spec" }, run test typing
npm testgenerage coverage report:
npm run coverage
coverage report available in coverage/lcov-report/index.html
Comments
Post a Comment