npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

sf-plugin-check-coverage

v1.0.0

Published

sf/sfdx plugin to check the code coverage of a test run and per file

Downloads

25

Readme

sf-plugin-check-coverage

sf/sfdx plugin to check the code coverage of a test run and per file

Actions Status

This plugin uses the coverage information from sf apex run test and sf apex get test stored in a directory to enforce the Apex class and trigger coverage to be above a given threshold (in percent). If the code coverage is below the threshold, the command fails.

Installation

sf plugins install sf-plugin-check-coverage

Prerequisites

This plugin makes use of the files in the coverage directory.

Example content of the coverage directory:

$ tree coverage
coverage
├── test-result-7075t00001mmTZw-codecoverage.json
├── test-result-7075t00001mmTZw-junit.xml
├── test-result-7075t00001mmTZw.json
├── test-result-codecoverage.json
├── test-result.txt
└── test-run-id.txt

1 directory, 6 files

You can retrieve the code coverage from the target org to a directory (here: coverage)

  • when running tests

    sf apex run test --code-coverage --output-dir coverage --wait 60
  • or from a completed test run

    sf apex get test --code-coverage --output-dir coverage --test-run-id 7070300002Y0bgjAAB

The relevant flags are --code-coverage --output-dir coverage (short: -c -d coverage).

Usage

We'll assume you've stored the code coverage in the coverage directory.

By default only the test run coverage is enforced (default: 75%):

sf coverage check --coverage-dir coverage

Enforce higher test run coverage:

sf coverage check --coverage-dir coverage --test-run-coverage 80

Enforce per-file coverage:

sf coverage check --coverage-dir coverage --per-file-coverage 75

Advanced Usage

Ignoring coverage of certain files

Sometimes specific classes cannot be covered with tests.

Create a .sfcoverageignore with the following content:

force-app/main/default/classes/CommunityController.cls

and add the --ignore-file flag:

sf coverage check -d coverage --ignore-file .sfcoverageignore

If you don't want to maintain such a file, you can alternatively use the following trick using a line comment in the files you want to ignore:

In force-app/main/default/classes/CommunityController.cls, add the line comment // SKIP_COVERAGE_CHECK somewhere.

Generate the ignore file on the fly listing all files containing this line comment:

sf coverage check -d coverage --ignore-file <(grep -l -r "// SKIP_COVERAGE_CHECK" force-app)

Note: Bash Process Substitution does not work on Windows with Git Bash in Node.js.