2

我正在尝试通过 Github 操作将 Angular (v11) 库的代码覆盖率发布到 Codecov.io

我已经设置了市场上的官方 Codecov github 操作

name: tests

on:
  pull_request:
    branches: [ master ]

jobs:
  build:
    # Machine environment:
    # We specify the Node.js version manually below, and use versioned Chrome from Puppeteer.
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - name: Use Node.js 14
        uses: actions/setup-node@v1
        with:
          node-version: 14
      - name: Install dependencies
        run: npm install
      - name: Build
        run: npm run build-lib
      - name: Test
        run: npm run test-lib-headless

      - name: Codecov
        uses: codecov/codecov-action@v1.1.1

package.json 中的任务

"test-lib-headless": "ng test ngx-scrollbar --watch=false --no-progress --browsers=ChromeHeadless --code-coverage",

业力.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: {
      jasmine: {
        // you can add configuration options for Jasmine here
        // the possible options are listed at https://jasmine.github.io/api/edge/Configuration.html
        // for example, you can disable the random execution with `random: false`
        // or set a specific seed with `seed: 4321`
      },
      clearContext: false // leave Jasmine Spec Runner output visible in browser
    },
    jasmineHtmlReporter: {
      suppressAll: true // removes the duplicated traces
    },
    coverageReporter: {
      dir: require('path').join(__dirname, './coverage'),
      subdir: '.',
      reporters: [
        { type: 'html' },
        { type: 'text-summary' }
      ]
    },
    reporters: ['progress', 'kjhtml'],
    port: 9876,
    colors: true,
    logLevel: config.LOG_INFO,
    autoWatch: true,
    browsers: ['Chrome'],
    customLaunchers: {
      ChromeHeadlessCI: {
        base: 'ChromeHeadless',
        flags: ['--no-sandbox']
      }
    },
    singleRun: false,
    restartOnFileChange: true,
    capabilities: {
      chromeOptions: {
        args: ["--headless"]
      },
      'browserName': 'chrome'
    },
  });
};

覆盖文件在coverage目录中创建

在此处输入图像描述

在 Github actions CI 中,它显示 codecov 没有找到文件!

在此处输入图像描述

为什么即使文件是在本地生成的,也找不到文件?Codecov 会寻找不同的报告扩展名吗?我怎样才能让它工作?

4

1 回答 1

4

这是因为 codecov 不支持默认生成的覆盖率报告。

简单的解决方案只是将lcov记者添加到您的配置中。

https://istanbul.js.org/docs/advanced/alternative-reporters/#lcovonly

coverageReporter: {
      dir: require('path').join(__dirname, './coverage/peach-tree'),
      subdir: '.',
      reporters: [
        { type: 'html' },
        { type: 'text-summary' },
        { type: 'lcovonly' },
      ]
    },

然后从 codecov 提供的 bash 脚本将毫无问题地上传您的报告。

于 2021-01-14T19:42:47.043 回答