[Webpack 2] ADD Code Coverage to tests in a Webpack project

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.