[Webpack 2] Ensure all source files are included in test coverage reports with Webpack

If you’re only instrumenting the files in your project that are under test then your code coverage report will be misleading and it will be difficult for you to track or enforce improvements to application coverage over time. In this lesson we’ll learn how to ensure all source files are included in coverage reports and how to enforce a specific threshold so you can work toward improving application code coverage.

Install:

npm i -D istanbul

Include all the src code not only test code:

const webpackEnv = {test: true}
const webpackConfig = require(‘./webpack.config‘)(webpackEnv)
process.env.BABEL_ENV = ‘test‘ // so we load the correct babel plugins
const testGlob = ‘src/js/**/*.test.js‘
const srcGlob = ‘src/js/**/*!(test|stub).js‘

module.exports = function setKarmaConfig(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 23 --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

时间: 2024-10-19 11:18:40

[Webpack 2] Ensure all source files are included in test coverage reports with Webpack的相关文章

Generate Ctags Files for C/C++ Source Files and All of Their Included Header Files

原文地址:http://www.topbug.net/blog/2012/03/17/generate-ctags-files-for-c-slash-c-plus-plus-source-files-and-all-of-their-included-header-files/ This post is for those people who use Exuberant Ctags. If you are using other versions of ctags, this post ma

vue项目优化之按需加载组件-使用webpack require.ensure

vue项目优化之按需加载组件-使用webpack require.ensure 使用 vue-cli构建的项目,在 默认情况下 ,执行 npm run build  会将所有的js代码打包为一个整体, 打包位置是 dist/static/js/app.[contenthash].js 类似下面的路由代码 router/index.js  路由相关信息,该路由文件引入了多个 .vue组件 import Hello from '@/components/Hello' import Province

[转] Webpack的devtool和source maps

source maps Webpack打包生成的.map后缀文件,使得我们的开发调试更加方便,它能帮助我们链接到断点对应的源代码的位置进行调试(//# souceURL),而devtool就是用来指定source-maps的配置方式的.以下是官方文档的说明: source maps 开发工具(Devtool) 此选项控制是否生成,以及如何生成 Source Map.以下是官方文档的配置选项: devtool配置选项 其中一些值适用于开发环境(从表格中各种方式的构建速度来看,可以看出eval方式可

vue按需加载组件-webpack require.ensure

使用 vue-cli构建的项目,在 默认情况下 ,执行 npm run build 会将所有的js代码打包为一个整体, 打包位置是 dist/static/js/app.[contenthash].js 类似下面的路由代码 router/index.js 路由相关信息,该路由文件引入了多个 .vue组件 import Hello from '@/components/Hello'import Province from '@/components/Province'import Segment

解决:Elipse配置Jython Interpreters时报错Error: Python stdlib source files not found

今天学习lynnLi的博客monkeyrunner之eclipse中运行monkeyrunner脚本之环境搭建(四)时,遇到了一个问题,即: lynnLi给出的解决办法是:将Python下的Lib拷贝到sdk中jython-standalone-2.5.3.jar所在目录tools\lib,再次New一个Jython,添加jython-standalone-2.5.3.jar路径即可 但是这样尝试,又报错了: 后来借鉴了这篇文章的做法,成功配置Jython Interpreters: 将\sdk

webpack require.ensure 按需加载

使用 vue-cli构建的项目,在 默认情况下 ,会将所有的js代码打包为一个整体比如index.js.当使用存在多个路由代码的时候,index.js可能会超大,影响加载速度. 这个每个路由页面除了index.js 还会有一个当前路由页面的js这样拆分了index.js的体积.

Plugin/Preset files are not allowed to export objects,webpack报错/babel报错的解决方法

1.为什么会报错 ? 这里抱着错误是因为 babel 的版本冲突. 多是因为你的 babel 依赖包不兼容. 可以查看你的 package.json 的依赖列表 即有 babel 7.0 版本的( @babel/core , @babel/preset-react ) 也可命令查看 bebel-cli 的版本 ( babel -V ) 也有 babel 6.0 版本的 ( [email protected] , [email protected] , [email protected] ) 如果

CSS文件修改后,编辑器提醒Generated source files should not be edited. The changes will be lost when sources are regenerated

我在谷歌调试器中修改了CSS样式查看是有效果的,于是找到目录下的CSS文件将相关的样式修改过来,但是刷新之后页面没有任何变化,这个问题困挠了我好久,但是我看见了这样一条警告: 后来我尝试着清除了浏览器的缓存 终于解决了这个问题! 原文地址:https://www.cnblogs.com/xlzfdddd/p/10466763.html

how to use Eclipse for kernel development

http://wiki.eclipse.org/HowTo_use_the_CDT_to_navigate_Linux_kernel_source Here are some steps that I've found to get the CDT to work well with the Linux kernel source. If you exclude some of these steps, it may still work to a large degree, but some