我使用 Karma 运行测试,使用 webpack 打包文件,使用 babel 进行 es6 -> es5 转换。我已经运行了测试并生成了代码覆盖率,但是代码覆盖率数字是用于编译后的源文件。反正有没有获得原始源文件的代码覆盖率?
我尝试使用sourcemap
预处理器,但它似乎没有做任何事情。我需要将它添加到 webpack 配置中的某个地方吗?
业力.conf.js
config.set({
browsers: ['Chrome'], //run in Chrome
files: [
'src/**/*-test.js'
],
frameworks: ['mocha'], //use the mocha test framework
plugins: [
'karma-chrome-launcher',
'karma-mocha',
'karma-sourcemap-loader',
'karma-webpack',
'karma-coverage',
],
preprocessors: {
'src/**/*-test.js': ['webpack']
},
reporters: ['dots', 'coverage'], //report results in this format
coverageReporter: {
reporters: [{
type: 'text-summary',
}, {
type: 'html',
dir: 'build/reports/coverage'
}]
},
singleRun: true, //just run once by default
webpack: {
node: {
fs: 'empty'
},
// Instrument code that isn't test or vendor code.
module: {
loaders: [{
test: /\.js?$/,
include: path.join(__dirname, 'src/js'),
loader: 'babel?stage=0'
}],
postLoaders: [{
test: /\.js$/,
exclude: /(test|node_modules)\//,
loader: 'istanbul-instrumenter'
}]
}
},
webpackMiddleware: {
noInfo: true //please don't spam the console when running in karma!
}
});