[英]Angular karma code coverage report folder not generated
When I run ng test --code-coverage
, The coverage report is sometimes not generating, sometimes it is generating so I'm unable to verify the coverage statement after doing test suites.当我运行
ng test --code-coverage
时,覆盖率报告有时不会生成,有时会生成,所以我无法在完成测试套件后验证覆盖率声明。
My Karma configuration我的业力配置
// Karma configuration file, see link for more information
// https://karma-runner.github.io/1.0/config/configuration-file.html
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-istanbul-reporter'),
require('@angular-devkit/build-angular/plugins/karma')
],
client: {
clearContext: false // leave Jasmine Spec Runner output visible in browser
},
coverageIstanbulReporter: {
dir: require('path').join(__dirname, '../coverage'),
reports: ['html', 'lcovonly'],
fixWebpackSourcePaths: true
},
reporters: ['progress', 'kjhtml'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome'],
singleRun: false
});
};
In my case everything seemed correct, but no coverage files or messages were generated on the console.就我而言,一切似乎都正确,但控制台上没有生成覆盖文件或消息。
What solved the problem was editing angular.json, adding the following key:解决问题的是编辑angular.json,添加以下键:
projects.ClientApp.test.options.codeCoverage = true;
The reason, your code coverage is not generating is that, there are some broken unit tests which stops the generation of the code coverage folder.您的代码覆盖率未生成的原因是,有一些损坏的单元测试会停止生成代码覆盖率文件夹。 Even though, it is generates some times, but that also must be taking much time then usual.
虽然,它会产生一些时间,但这也必须比平常花费更多的时间。 Follow the below steps, in order to identify and fix the unit tests so that, code-coverage file will generate each time-
按照以下步骤,为了识别和修复单元测试,每次都会生成代码覆盖文件-
npm test
.npm test
。 Fix all the tests and it should generate the unit tests code coverage folder everytime.修复所有测试,它应该每次都生成单元测试代码覆盖率文件夹。
通过以下命令生成新的代码覆盖率文件夹
node --max_old_space_size=4096 ./node_modules/karma/bin/karma start ./test-config/karma.conf.js --coverage
Add the following config in your Karma.conf.js file在您的 Karma.conf.js 文件中添加以下配置
module.exports = function(config) {
config.set({
...
coverageReporter: {
dir: require('path').join(__dirname, 'dist/coverage/app-coverage'),
subdir: '.',
reporters: [
{ type: 'html' },
{ type: 'text-summary' },
{ type: 'cobertura' }
]
}
}
and then run:然后运行:
ng test --code-coverage=true
It will generate precise code coverage report, now go to the directory dist/coverage/app-coverage and open index.html file in browser.它将生成精确的代码覆盖率报告,现在 go 到目录dist/coverage/app-coverage并在浏览器中打开 index.html 文件。 It will provide code coverage for individual files and which code section is need to cover.
它将提供单个文件的代码覆盖率以及需要覆盖的代码部分。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.