[Webpack 2] Ensure all source files is included in Test coverages reports with Webpack

Source: Internet
Author: User

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

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.