Skip to content

GitHub action for creating markdown coverage report from Istanbul text report

License

Notifications You must be signed in to change notification settings

fingerprintjs/action-coverage-report-md

Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

Repository files navigation

typescript-action status

Jest coverage report in Markdown

This action uses a text coverage report from Jest and generates a Markdown report based on it in the format shown below. The table shows the status of each file. Each file and uncovered line is properly linked to it's examined version on GitHub.

St File % Stmts % Branch % Funcs % Lines Uncovered Line #s
🟡 All files 70.58 72.22 83.33 71.42
🟡  src 63.23 64.28 80 64.17
🔴   main.ts 0 0 0 0 1-37
🟢   report.ts 95.55 100 88.88 95.55 14-15
🟢  src/utils 100 100 100 100
🟢   getReportParts.ts 100 100 100 100
🟢   status.ts 100 100 100 100

Note This package isn’t part of our core product. It’s kindly shared “as-is” without any guaranteed level of support from Fingerprint. We warmly welcome community contributions.

Usage

The action returns a markdownReport output that you can use in other actions. The example below shows how to use the report in a pull request comment.

steps:
  - name: Prepare coverage report in markdown
    uses: fingerprintjs/action-coverage-report-md@v2
    id: coverage
  - name: Add coverage comment to the PR
    uses: marocchino/sticky-pull-request-comment@v2
    with:
      message: ${{ steps.coverage.outputs.markdownReport }}

Extended usage

steps:
  - name: Prepare coverage report in markdown
    uses: fingerprintjs/action-coverage-report-md@v2
    id: coverage
    with:
      textReportPath: './coverage/text-report.txt'
      srcBasePath: './utils'
  - name: Add coverage comment to the PR
    uses: marocchino/sticky-pull-request-comment@v2
    with:
      message: ${{ steps.coverage.outputs.markdownReport }}

Add coverage report to the job summary

You can add a code coverage report to the job summary. For more information, see Adding a job summary in the GitHub Actions documentation.

Job summary example

steps:
  - name: Prepare coverage report in markdown
    uses: fingerprintjs/action-coverage-report-md@v2
    id: coverage
    with:
      textReportPath: './coverage/text-report.txt'
      srcBasePath: './utils'
  - name: Add coverage report to the job summary
    run: |
      echo "## Code Coverage" >> $GITHUB_STEP_SUMMARY
      echo "${{ steps.coverage.outputs.markdownReport }}" >> $GITHUB_STEP_SUMMARY

API

Inputs

Name Type Default Value Description
textReportPath string './coverage/coverage.txt' Path to the coverage report in the Istanbul text format.
srcBasePath string './src' Base path for the source folder.

Outputs

Name Type Description
markdownReport string Coverage report in Markdown format.

How to get a text coverage report

Jest

  • Using a CLI:
npx jest --coverage --coverageReporters="text" > coverage.txt
  • Using a Configuration file:
module.exports = {
  // ... other settings
  coverageReporters: [['text', { file: 'coverage.txt', path: './' }]],
};

nyc (Istanbul)

  • Using a CLI:
npx nyc report --reporter=text > ./coverage/coverage.txt
  • Using a Configuration file:
module.exports = {
  // ... other settings
  "reporter": ["text"],
  "report-dir": "./coverage"  // will generate a file ./coverage/text.txt
}

Karma

module.exports = function(config) {
  config.set({
    // ... other settings
    reporters: ['coverage'],
    coverageReporter: {
        type : 'text',
        dir: './coverage',
        file: 'coverage.txt'
    }
  });
};