我正在尝试在 TeamCity 构建服务器上为 Angular CLI 项目运行单元测试。
如果我使用命令:
ng test --single-run --code-coverage
然后,正如预期的那样,我得到了一份测试覆盖率报告,但单个测试结果没有显示在 TeamCity 中。
如果我打开 TeamCity 报告:
ng test --single-run --code-coverage --reporters teamcity
然后测试通过,TeamCity 报告完美运行,但它默默地无法生成代码覆盖率报告。此行为可在我的本地计算机上重现,因此与构建服务器的配置方式无关。
这两个选项应该相互排斥有什么理由吗?
注意 - 这与 Configuring code coverage report for Karma on TeamCity 不是同一个问题.如果报告存在,则 TeamCity 会正确显示,但如果我打开 TeamCity 报告标志,则覆盖文件夹根本不存在。
附加信息:
karma 配置:
// Karma configuration file, see link for more information
// https://karma-runner.github.io/0.13/config/configuration-file.html
module.exports = function (config) {
config.set({
basePath: '',
frameworks: ['jasmine', '@angular/cli'],
plugins: [
require('karma-jasmine'),
require('karma-chrome-launcher'),
require('karma-jasmine-html-reporter'),
require('karma-coverage-istanbul-reporter'),
require('@angular/cli/plugins/karma'),
require('karma-teamcity-reporter')
],
client:{
clearContext: false // leave Jasmine Spec Runner output visible in browser
},
files: [
{ pattern: './src/test.ts', watched: false }
],
preprocessors: {
'./src/test.ts': ['@angular/cli']
},
mime: {
'text/x-typescript': ['ts','tsx']
},
coverageIstanbulReporter: {
reports: [ 'html', 'lcovonly' ],
fixWebpackSourcePaths: true
},
angularCli: {
environment: 'dev'
},
reporters: config.angularCli && config.angularCli.codeCoverage
? ['progress', 'coverage-istanbul']
: ['progress', 'kjhtml'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome'],
singleRun: false
});
};
最佳答案
我将此作为 issue on GitHub 提出Angular-CLI 团队指出了解决方案:
ng test --single-run --code-coverage --reporters=teamcity,coverage-istanbul
--code-coverage
选项仅在记者列表包含报道工具时才有效。如果没有报道记者在场,它会默默地失败。 --reporters
开关替换默认的记者列表,所以 coverage-istanbul
必须明确重新添加。 coverage-istanbul
报告者不自行生成报告; --code-coverage
切换还是需要的。 关于teamcity - "ng test"无法同时进行覆盖率报告和 TeamCity 报告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42958455/