使用webpack4 + karma + mocha时,我要进行vue单元测试,覆盖率总为100%(0/0),但使用webpack3是正确的。
vue-loader @ 15
webpack @ 4
vue-loader @ 13
webpack @ 3
使用webpack4 + karma + mocha时,我要进行vue单元测试,覆盖率总为100%(0/0),但使用webpack3是正确的。
相同的业力配置:
module.exports = function(config) {
config.set({
basePath: '',
frameworks: ['mocha'],
files: ['./test/*.spec.js'],
exclude: [],
plugins: [
'karma-chrome-launcher',
'karma-mocha',
'karma-webpack',
'karma-coverage',
'karma-spec-reporter',
'karma-sourcemap-loader'
],
preprocessors: {
'./test/*.spec.js': ['webpack', 'sourcemap']
},
webpack: {
devtool: '#inline-source-map',
resolve: {
extensions: ['.js', '.vue', '.json'],
alias: {
vue: 'vue/dist/vue.min.js'
}
},
module: {
rules: [
{
test: /\.vue$/,
loader: 'vue-loader',
options: {
loaders: {
js: 'babel-loader'
},
postLoaders: {
js: 'istanbul-instrumenter-loader?esModules=true'
}
}
},
{
test: /\.js$/,
exclude: [/node_modules/],
loader: 'babel-loader',
query: {
compact: false,
presets: ['es2015']
}
},
{
test: /\.less$/,
use: [
{ loader: 'style-loader' },
{ loader: 'css-loader' },
{ loader: 'less-loader' },
{
loader: 'postcss-loader',
options: {
plugins: [require('autoprefixer')('last 200 versions')]
}
}
]
}
]
}
},
reporters: ['spec', 'coverage'],
port: 9877,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome'],
singleRun: false,
concurrency: Infinity,
coverageReporter: {
dir: './coverage',
reporters: [{ type: 'text-summary' }, { type: 'lcov', subdir: '.' }]
}
});
};