teamcity - "ng test"无法同时进行覆盖率报告和 TeamCity 报告

标签 teamcity karma-jasmine angular-cli istanbul karma-coverage

我正在尝试在 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 报告标志,则覆盖文件夹根本不存在。

附加信息:
  • Angular-CLI 版本 1.0.0-rc.4(问题首次发现使用 1.0.0-rc.1)
  • Karma 版本 1.4.1
  • 节点版本 6.9.4
  • Windows 7 企业版

  • 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/

    相关文章:

    Angular:构建应用程序后,我们如何知道它是哪个环境

    node.js - 文件替换不适用于 e2e 测试

    git - TeamCity 无法从 VCS 加载build设置,忽略新设置

    angular - 如何在订阅 Angular7 单元测试用例中对代码进行单元测试

    nunit - TeamCity NUnit 运行程序因 x86 - x64 - MSIL 差异而失败

    async-await - karma-typescript:使用 Async 关键字导入 JS 文件

    javascript - 使用 Jasmine : how to remove or modify spyOn 进行 Angular 单元测试

    angular - 安装特定版本的 ng cli

    windows - 通过 TeamCity 执行时 dos2unix 格式转换错误

    msbuild - 如何对team city编译的源代码进行混淆