【发布时间】:2017-11-11 17:50:38
【问题描述】:
在this guide 之后,我已将 istanbul-instrumenter 添加到我的测试配置中,以获取显示其余文件的“未捆绑”覆盖率报告。但是,捆绑的测试文件仍然显示在build/:
----------------------------|----------|----------|----------|----------|----------------|
File | % Stmts | % Branch | % Funcs | % Lines |Uncovered Lines |
----------------------------|----------|----------|----------|----------|----------------|
All files | 70.78 | 36.36 | 69.23 | 60.95 | |
build | 67.39 | 31.03 | 66.67 | 53.93 | |
tests.js | 67.39 | 31.03 | 66.67 | 53.93 |... 208,209,211 |
src/routes/Home | 100 | 75 | 100 | 100 | |
index.js | 100 | 75 | 100 | 100 | 11 |
src/routes/Home/components | 100 | 75 | 100 | 100 | |
HomeView.js | 100 | 75 | 100 | 100 | 18 |
----------------------------|----------|----------|----------|----------|----------------|
✨ Done in 14.19s.
到目前为止,这是我的测试配置。我认为在 istanbul-instrumenter-loader 子句中排除 build 会做到这一点,但它似乎没有:
var nodeExternals = require('webpack-node-externals');
var path = require('path');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
var project = require('../project.config');
const inProject = path.resolve.bind(path, project.basePath);
const inProjectSrc = (file) => inProject(project.srcDir, file);
const __DEV__ = project.env === 'development';
const extractStyles = new ExtractTextPlugin({
filename: 'styles/[name].[contenthash].css',
allChunks: true,
disable: __DEV__
});
module.exports = {
entry: {
main: ['./tests/test-bundler.js']
},
target: 'node',
output: {
path: path.resolve('./build', project.basePath),
filename: 'build/tests.js'
},
externals: [nodeExternals()],
module: {
rules: [
{
test: /\.js?$/,
use: [
{
loader: 'babel-loader',
options: {
cacheDirectory: true,
plugins: [
'babel-plugin-transform-class-properties',
'babel-plugin-syntax-dynamic-import',
[
'babel-plugin-transform-runtime',
{
helpers: true,
polyfill: false, // we polyfill needed features in src/normalize.js
regenerator: true
},
],
[
'babel-plugin-transform-object-rest-spread',
{
useBuiltIns: true // we polyfill Object.assign in src/normalize.js
},
],
],
presets: [
'babel-preset-react',
['babel-preset-env', {
targets: {
ie9: true,
uglify: true,
modules: false
}
}],
]
}
}
],
exclude: /node_modules/
},
{
test: /\.(sass|scss)$/,
use: [
'css-loader?modules&importLoaders=1&localIdentName=[name]__[local]__[hash:base64:5]',
'sass-loader',
]
},
{
test: /\.(gif|png|jpe?g|svg)$/i,
loaders: [
'file-loader',
{
loader: 'image-webpack-loader',
query: {
progressive: true,
optipng: {
optimizationLevel: 7
},
gifsicle: {
interlaced: false
},
pngquant: {
quality: '65-90',
speed: 4
}
}
}
]
},
{
// delays coverage til after tests are run, fixing transpiled source
// coverage error
enforce: 'post',
test: /\.js$/,
exclude: /(tests|node_modules|bower_components|build)\//,
loader: 'istanbul-instrumenter-loader'
}
]
},
resolve: {
extensions: ['.js', '.jsx']
}
};
如何确保入口点build/tests.js不用于覆盖率计算?
【问题讨论】:
标签: webpack code-coverage webpack-2 istanbul