无法加载记者“coverage-istanbul”
Posted
技术标签:
【中文标题】无法加载记者“coverage-istanbul”【英文标题】:Can not load reporter "coverage-istanbul" 【发布时间】:2020-02-29 16:25:16 【问题描述】:我正在尝试使用 https://webpack.js.org/loaders/istanbul-instrumenter-loader/ 运行代码覆盖率
这里是 karma.conf.js
var testWebpackCfg = require('../webpack/webpack.config.test.js');
module.exports = function(config)
config.set(
basePath: '../../',
frameworks: ['jasmine'],
plugins: [ 'karma-webpack', 'karma-jasmine-jquery', 'karma-jasmine', 'karma-chrome-launcher','karma-firefox-launcher', 'karma-coverage','karma-spec-reporter', 'karma-jasmine-html-reporter'],
preprocessors:
'client/test/index.js': ['webpack']
,
reporters: [ 'spec', 'coverage-istanbul'],
coverageIstanbulReporter:
reports: [ 'text-summary' ],
dir: './coverage',
fixWebpackSourcePaths: true
,
files: [
'client/test/index.js'
],
webpack: testWebpackCfg,
// web server port
port: 9876,
runnerPort: 9100,
urlRoot: '/',
// level of logging
// possible values: LOG_DISABLE || LOG_ERROR || LOG_WARN || LOG_INFO || LOG_DEBUG
logLevel: config.LOG_INFO,
// enable / disable watching file and executing tests whenever any file changes
autoWatch: false,
browsers: ['Chrome'],
singleRun: true
);
;
Webpack 配置
test: /\.js$/i,
exclude: [
paths.appNodeModules
],
use: [
loader: require.resolve('babel-loader'),
options:
presets: ['@babel/preset-env']
,
loader: require.resolve('istanbul-instrumenter-loader'),
options:
esModules: true
]
在运行 Karma 时,我看到了这个错误 ',它没有注册! 也许你错过了一些插件?'
【问题讨论】:
【参考方案1】:Nishant 给出了基本答案,但我发现当我没有明确指定业力配置文件时,我也收到了这条消息,根据这个答案:
cant get junit running with Karma
【讨论】:
【参考方案2】:通过在 karma 配置插件中添加 karma-coverage-istanbul-reporter 解决了该错误。
npm i karma-coverage-istanbul-reporter --save-dev
karma.conf.js
...
plugins: ['karma-coverage-istanbul-reporter']
...
【讨论】:
以上是关于无法加载记者“coverage-istanbul”的主要内容,如果未能解决你的问题,请参考以下文章