How much of your code runs during unit testing is an extremely valuable metric to track. Utilizing code the karma-coverage plugin and babel-plugin-__coverage__ plugin, we can get an 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 plugins
const fileGlob = 'src/js/**/*.test.js' module.exports = function setKarmaConfig(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": [
["__coverage__", {"ignore": "*.+(test|stub).*"}] // 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的更多相关文章

  1. Gumshoe - Microsoft Code Coverage Test Toolset

    Gumshoe - Microsoft Code Coverage Test Toolset 2014-07-17 What is Gumshoe? How to instrument a binar ...

  2. 10 Code Coverage Tools for C & C++

    Code coverage is a measure used in software testing that describes the degree to which the source co ...

  3. CI集成phpunit Error: No code coverage driver is available 的解决

    CI集成phpunit时,运行报No code coverage driver is available的错误,如下图: yanglingdeMacBook-Pro:tests yangling$ p ...

  4. iOS 9 学习系列: Xcode Code Coverage

    Code coverage 是一个计算你的单元測试覆盖率的工具. 高水平的覆盖给你的单元測试带来信心.也表明你的应用被彻底的測试过了. 你可能写了几千个单元測试,但假设覆盖率不高.那么你写的这套測试可 ...

  5. [Webpack] Detect Unused Code with Webpack and unused-files-webpack-plugin

    As you refactor and modify applications, it's difficult to manage and keep track of files as they be ...

  6. Code Coverage and Unit Test in SonarQube

    概念 https://blog.ndepend.com/guide-code-coverage-tools/ Code Coverage Results Import (C#, VB.NET) Uni ...

  7. 使用Visual Studio Code Coverage和nunit上传单元测试覆盖率和单元测试结果到SonarQube上

    SonarQube.Scanner.MSBuild.exe begin /k:"OMDCCQuotes" /d:sonar.host.url="http://myip:9 ...

  8. 测试工具 - IDEA - IDEA Code Coverage

    概述 使用 idea 自带的 code coverage 工具 背景 了解 白盒测试用例设计 和 测试覆盖率 之后, 大概就需要 实践 了 实践的话, 还是需要 工具 来检验效果 工具选取 选项 Ja ...

  9. [Jest] Track project code coverage with Jest

    Jest comes pre-packaged with the ability to track code coverage for the modules you're testing, but ...

随机推荐

  1. [codility]Prefix-set

    这题很简单,一开始用了set.但后来一想这样其实是n*logn的,而且没有利用所有的数都在0..N-1之间.那么可以直接用vector当hashset. // you can also use inc ...

  2. tbody添加垂直滚动条

    法一: 用2个table: <table width="300" border="0" cellpadding="0" cellspa ...

  3. MapReduce——计算温度最大值 (基于全新2.2.0API)

    MapReduce——计算温度最大值 (基于全新2.2.0API) deprecated: Job类的所有Constructors, 新的API用静态方法getInstance(conf)来去的Job ...

  4. apache开源项目--thrift

    Thrift 是一个软件框架(远程过程调用框架),用来进行可扩展且跨语言的服务的开发.它结合了功能强大的软件堆栈和代码生成引 擎,以构建在 C++, Java, Python, PHP, Ruby, ...

  5. 用css控制cellspacing、cellpadding

    用css控制cellspacing.cellpadding 发表于 2006 年 12 月 24 日 由 Silbo 在table中控制单元格之间的间距要用到cellspacing.cellpaddi ...

  6. Android 所有颜色代码

    colors.xml <?xml version="1.0" encoding="utf-8" ?> <resources> <c ...

  7. CORREL

    CORREL Show All Returns the correlation coefficient of the array1 and array2 cell ranges. Use the co ...

  8. HDU 1953

    #include<stdio.h> #include<math.h> long long int euler(long long int n) { long long int ...

  9. [King.yue]关于代码调试时的缓存问题的一个解决办法

    后台构造数据更改之后,页面数据一直不变,试过各种办法,清空浏览器缓存,停止端口重新运行,关掉程序重新打开,都不可以.最终全部重新生成之后,终于可以正常调试了. 另:调试ASP.NET网站程序的时候,为 ...

  10. 解决:javah 无法访问引用Android对象的问题

    无法访问android.view.View 是没有引入android.jar包 javah的参数中 有一个-bootclasspath参数 让他指向android.jar包 例如 javah -jni ...