使用
--code-coverage
运行 Angular 测试时遇到持续的“加载错误”。此错误仅在使用命令 ng test --no-watch --code-coverage
时发生;否则,在没有 ng test
的情况下运行 --code-coverage
效果很好。
Karma Configuration (karma.conf.js):
module.exports = function (config) {
config.set({
basePath: '',
frameworks: ['jasmine', '@angular-devkit/build-angular'],
plugins: [
require('karma-jasmine'),
require('karma-chrome-launcher'),
require('karma-jasmine-html-reporter'),
require('karma-coverage'),
require('@angular-devkit/build-angular/plugins/karma')
],
client: { clearContext: false },
coverageReporter: {
dir: require('path').join(__dirname, '../coverage/DATAGERRYApp'),
reporters: [{ type: 'html' }, { type: 'lcovonly' }, { type: 'text-summary' }],
fixWebpackSourcePaths: true
},
reporters: ['progress', 'kjhtml'],
port: 9876,
colors: true,
logLevel: config.LOG_DEBUG, // Enabled for detailed logging
autoWatch: true,
browsers: ['ChromeHeadless'],
singleRun: true,
restartOnFileChange: true
});
};
**使用的命令: **
ng test --no-watch --code-coverage
**错误输出: **
Error: Found 1 load error at Server.<anonymous> (/path/to/project/node_modules/karma/lib/server.js:243:26)
我尝试过的步骤:
我认为您的操作系统中未安装 google chrome。尝试安装 chrome 并运行命令。