[Webpack 2] Add Code Coverage to tests in a Webpack project
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__
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的更多相关文章
- Gumshoe - Microsoft Code Coverage Test Toolset
Gumshoe - Microsoft Code Coverage Test Toolset 2014-07-17 What is Gumshoe? How to instrument a binar ...
- 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 ...
- CI集成phpunit Error: No code coverage driver is available 的解决
CI集成phpunit时,运行报No code coverage driver is available的错误,如下图: yanglingdeMacBook-Pro:tests yangling$ p ...
- iOS 9 学习系列: Xcode Code Coverage
Code coverage 是一个计算你的单元測试覆盖率的工具. 高水平的覆盖给你的单元測试带来信心.也表明你的应用被彻底的測试过了. 你可能写了几千个单元測试,但假设覆盖率不高.那么你写的这套測试可 ...
- [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 ...
- Code Coverage and Unit Test in SonarQube
概念 https://blog.ndepend.com/guide-code-coverage-tools/ Code Coverage Results Import (C#, VB.NET) Uni ...
- 使用Visual Studio Code Coverage和nunit上传单元测试覆盖率和单元测试结果到SonarQube上
SonarQube.Scanner.MSBuild.exe begin /k:"OMDCCQuotes" /d:sonar.host.url="http://myip:9 ...
- 测试工具 - IDEA - IDEA Code Coverage
概述 使用 idea 自带的 code coverage 工具 背景 了解 白盒测试用例设计 和 测试覆盖率 之后, 大概就需要 实践 了 实践的话, 还是需要 工具 来检验效果 工具选取 选项 Ja ...
- [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 ...
随机推荐
- Foundation和UIKit框架图
学习Foundation和UIKit的时候比较容易忽视的一个问题: 对于一个新的类,知道它的用法和属性方法,但往往忽视了它的继承关系, 了解类的继承关系能帮助加深对其理解. 另外在官方文档中每一个类的 ...
- Java Vector 类
Vector类实现了一个动态数组.和ArrayList和相似,但是两者是不同的: Vector是同步访问的. Vector包含了许多传统的方法,这些方法不属于集合框架. Vector主要用在事先不知道 ...
- 学习kernel编程的建议
我把我学习kernel编程的过程介绍给大家,希望大家有个参考. 学习kernel编程需要阅读大量的kernel方面的书籍,在此我列举一下我读过的kernel书籍(按时间先后顺序),并给一些建议. 1. ...
- Win32下 Qt与Lua交互使用(二):在Lua脚本中使用Qt类
话接上篇.成功配置好Qt+Lua+toLua后,我们可以实现在Lua脚本中使用各个Qt的类.直接看代码吧. #include "include/lua.hpp" #include ...
- 让ASP.NET MVC页面返回不同类型的内容
在ASP.NET MVC的controller中大部分方法返回的都是ActionResult,更确切的是ViewResult.它返回了一个View,一般情况下是一个HTML页面.但是在某些情况下我们可 ...
- 函数的重载与 泛型(generic)有什么不同?
函数重载指 重载函数,形参(类型)不同,实现的功能一样. 泛型算法指2个方面:这些算法可作用于各种不同的容器类型,而这些容器类型又可以容纳多种不同类型的元素.
- GML、SVG、VML的比较
转自:http://www.cnblogs.com/3echo/archive/2009/02/19/1394399.html GML.SVG和VML都是基于XML的可用来描述矢量图形的标记语言,都是 ...
- android中如何实现离线缓存
离线缓存就是在网络畅通的情况下将从服务器收到的数据保存到本地,当网络断开之后直接读取本地文件中的数据. 将网络数据保存到本地: 你可以自己写一个保存数据成本地文件的方法,保存在android系统的任意 ...
- WPF学习小记
WPF通用控制事件 Click:当控件被单击时发生.某些情况下,当用户按下Enter键时也会发生这样的事件. Drop:当拖曳操作完成时发生,也就是说,当用户将某个对象拖曳dao该控件上,然后松开鼠标 ...
- 录制屏幕(gif)便于在博客中嵌入软件licecap