Unit Test Coverage.

testing:coverage

Calculate test coverage based on test results and report the coverage badge.

# Applicable Events

所有事件

# Overall Coverage

coverage coverage coverage coverage

The coverage is parsed from the local coverage report file. The following report formats are currently supported:

  • json (recommended)
  • json-summary
  • lcov (recommended)
  • jacoco
  • golang

# Incremental Coverage

coverage-pr coverage-pr coverage-pr coverage-pr

The test coverage for changed lines is only supported for pull_request and pull_request.target events.

# Parameters

# pattern

  • type: String
  • required: false

Specify the location of the coverage report file using the glob format, relative to the current working directory. When not specified, it will attempt to find the following files in the current directory (including subdirectories): coverage.json, jacoco*.xml, lcov.info, *.lcov.

# lines

  • type: Number
  • required: false

Specify the threshold for full coverage and check if the overall coverage percentage is below that value to block the workflow and exit the pipeline.

# diffLines

  • type: Number
  • required: false

Specify the threshold for incremental coverage, check if the overall coverage percentage is below that value, and halt the workflow to exit the pipeline. The pull_request and pull_request.target events support calculating incremental coverage results, while other events only calculate overall coverage.

# allowExts

  • type: String
  • required: false

The whitelist of code file types involved in coverage calculation should be comma-separated, for example: .json,.ts,.js. By default, all files included in the report will be considered for coverage calculation if no whitelist of code file types is specified.

# lang

  • type: String
  • required: false

When the coverage result report target format is set to golang, please specify the parameter as go to avoid calculation errors. For other cases, you can ignore this parameter.

# breakIfNoCoverage

  • type: Boolean
  • required: false

Should an error be thrown and the process terminated when the coverage report file is not found?

# Output Results

{
    // Code line coverage, e.g., 100. If calculation fails, the value is NA.
    lines,
    // Incremental code line coverage, e.g., 100. If calculation fails, the value is NA.
    diff_pct,
}

# Configuration Example

#.cnb.yml
main:
  push:
    - stages:
        - name: Coverage
          type: testing:coverage
          options:
            breakIfNoCoverage: false
          exports:
            lines: LINES
        - name: Result
          script: echo $LINES