How much of your code runs during unit testing are an extremely valuable metric to track. Utilizing code karma-coverage babel-plugin-__coverage__ the plugin and plugin, we can get a accurate measure of how well we ' re covering the files that We are testing.
Install:
NPM i-d karam-coverage babel-plugin-__coverage__
Karma.config.js:
Const WEBPACKENV = {test:true}const Webpackconfig= require ('./webpack.config ')) (webpackenv)Process.env.BABEL_ENV = ' Test ' //So we load the correct Babel pluginsConst FILEGLOB = ' Src/js/**/*.test.js 'Module.exports=functionsetkarmaconfig (config) {config.set ({basepath:‘‘, Frameworks: [' Mocha ', ' Chai '], files: [Fileglob], preprocessors: {[Fileglob]: [' 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})}
. Bablerc
{ "presets": ["Es2015-webpack", "Stage-2"], "env": {"Test": { "Plugins": [ [/// exclude. Test &. Stub files ]} }
Package.json:
scripts: { "test": "Karma Start", "watch:test": "NPM test----auto-watch--no-single-run" , " Validate ":" Npm-run-all--parallel validate-webpack:* Lint test ",}
[Webpack 2] ADD Code Coverage to tests in a Webpack project