If you ' re only instrumenting the files in your project that is under test then your code coverage report would be Misleadi Ng and it'll be difficult-for-you-to-track or enforce improvements-application coverage over time. In this lesson we'll learn how to ensure all source files is included in coverages reports and how to enforce a specific t Hreshold so can work toward improving application code coverage.
Install:
NPM i-d Istanbul
Include all the SRC code does not have only test code:
Const WEBPACKENV = {test:true}const Webpackconfig= require ('./webpack.config ')) (webpackenv) Process.env.BABEL_ENV= ' Test '//So we load the correct Babel pluginsConst TESTGLOB = ' src/js/**/*.test.js ' const SRCGLOB = ' src/js/**/*! (test|stub). js 'Module.exports=functionsetkarmaconfig (config) {config.set ({basepath:‘‘, Frameworks: [' Mocha ', ' Chai '], files: [Testglob, Srcglob], preprocessors: {[Testglob]: [' Webpack '], [Srcglob]: [' Webpack '],}, Webpack:webpackconfig, Webpackmiddleware: {noinfo:true}, reporters: [' Progress ', ' coverage '], Coveragereporter: {reporters: [{type:' Lcov ', dir: ' coverage/', SubDir: '. '}, {type:' JSON ', dir: ' coverage/', SubDir: '. '}, {type:' Text-summary '},],}, Port:9876, colors:true, Loglevel:config. Log_info, Autowatch:false, browsers: [' Chrome '], Singlerun:true, concurrency:infinity})}
Use Istanbul CLI to check code coverage not below Cetain number:
"Check-coverage": "Istanbul check-coverage--statements--branches 5--functions 9--lines 24",
Add to Validator:
"Validate": "Npm-run-all--parallel validate-webpack:* Lint test--serial check-coverage",
Because It checkout coverage should run after test, so add '--serial ' flag
[Webpack 2] Ensure all source files is included in Test coverages reports with Webpack