GithubHelp home page GithubHelp logo

simonecorsi / lcov-total Goto Github PK

View Code? Open in Web Editor NEW
10.0 1.0 2.0 2.47 MB

⚙️ Parse LCOV output and return the average value, easily fail CI with a threshold

Home Page: https://www.npmjs.com/package/lcov-total

License: MIT License

JavaScript 97.65% Shell 2.35%
node lcov npm coverage test parser average tdd ci cli

lcov-total's Introduction

lcov-total

code style: prettier semantic-release npm (scoped) license

Table of contents

About

This module now uses ESM modules from v2.0.0, if you need to use CommonJS refer to v1.x.x

This simple package aim to parse lcov.info files and provide the total coverage Number without fancy formatting or anything else, either in stdout or programmatically.

Here's why:

  • You need to assest coverage in your CI and fail below certain threshold
  • you don't want to do unredable awk chains
  • every other options outputs fancy colored output which is tediuous to parse and error prone

Installation

You can install locally

npm install lcov-total

You can install globally

npm install -g lcov-total

Or use NPX

npx lcov-total

Usage

You can use lcov-total from command line providing lcov.info file location eg:

npx lcov-total lcov.info
# 100.00

If you pass the --gte=value flag you will get an exitCode 0 or 1 based on resulting coverage >= value expression, eg:

npx lcov-total lcov.info --gte=90
echo $?
# 0

Or programmatically

import lcovTotal from "lcov-total";
lcovTotal("/path/to/lcov.info"); // this throws if any error

Contributing

Project is pretty simple and straight forward for what is my needs, but if you have any idea you're welcome.

This projects uses commitlint with Angular configuration so be sure to use standard commit format or PR won't be accepted.

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'feat(scope): some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

Distributed under the MIT License. See LICENSE for more information.

Contact

Simone Corsi - @im_simonecorsi

Acknowledgements

lcov-total's People

Contributors

dependabot[bot] avatar github-actions[bot] avatar gohar94 avatar semantic-release-bot avatar simonecorsi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

lcov-total's Issues

Issue with --gte=100 returning exit code 1

Currently as per documentation:

If you pass the --gte=value flag you will get an exitCode 0 or 1 based on resulting coverage >= value expression

However the current code is > and not >=

process.exitCode = result > min ? 0 : 1;

Current issue: Passing --gte=100 will return 1 even if lcov-total returns 100%.

Should be:
process.exitCode = result >= min ? 0 : 1;

The automated release is failing 🚨

🚨 The automated release from the main branch failed. 🚨

I recommend you give this issue a high priority, so other packages depending on you could benefit from your bug fixes and new features.

You can find below the list of errors reported by semantic-release. Each one of them has to be resolved in order to automatically publish your package. I’m sure you can resolve this 💪.

Errors are usually caused by a misconfiguration or an authentication problem. With each error reported below you will find explanation and guidance to help you to resolve it.

Once all the errors are resolved, semantic-release will release your package the next time you push a commit to the main branch. You can also manually restart the failed CI job that runs semantic-release.

If you are not sure how to resolve this, here is some links that can help you:

If those don’t help, or if this issue is reporting something you think isn’t right, you can always ask the humans behind semantic-release.


No npm token specified.

An npm token must be created and set in the NPM_TOKEN environment variable on your CI environment.

Please make sure to create an npm token and to set it in the NPM_TOKEN environment variable on your CI environment. The token must allow to publish to the registry https://registry.npmjs.org/.


Good luck with your project ✨

Your semantic-release bot 📦🚀

Include option to force thresholds?

Hey Simone,

Thanks for this plugin.
I could see it useful for me in another project if it could not only read the coverage data (lcov-total lcov.info) but also allow to enforce it. Jest for example provide the thresholds rules like this:

{
  "jest": {
    "coverageThreshold": {
      "global": {
        "branches": 80,
        "functions": 80,
        "lines": 80,
        "statements": -10
      }
    }
  }
}

Since lcov-total can already read the data, it could be used in CI to fail/pass according to the thresholds set.

The automated release is failing 🚨

🚨 The automated release from the main branch failed. 🚨

I recommend you give this issue a high priority, so other packages depending on you could benefit from your bug fixes and new features.

You can find below the list of errors reported by semantic-release. Each one of them has to be resolved in order to automatically publish your package. I’m sure you can resolve this 💪.

Errors are usually caused by a misconfiguration or an authentication problem. With each error reported below you will find explanation and guidance to help you to resolve it.

Once all the errors are resolved, semantic-release will release your package the next time you push a commit to the main branch. You can also manually restart the failed CI job that runs semantic-release.

If you are not sure how to resolve this, here is some links that can help you:

If those don’t help, or if this issue is reporting something you think isn’t right, you can always ask the humans behind semantic-release.


No npm token specified.

An npm token must be created and set in the NPM_TOKEN environment variable on your CI environment.

Please make sure to create an npm token and to set it in the NPM_TOKEN environment variable on your CI environment. The token must allow to publish to the registry https://registry.npmjs.org/.


Good luck with your project ✨

Your semantic-release bot 📦🚀

Add flag for CLI comparison

Since CLI outputs only the raw number I wan't to add a way to make asserts to use into a CI, eg:

lcov-total --gte 90
# exit with 0 or 1

Different types of coverages

This is more of a question about the reasoning about the different types of coverages and total coverage.

In parser.js, line, function, and branch coverages are counted, but then only lines results are taken into account when counting the total coverage.

Why is branch and function coverage dropped? If only line coverage should be taken into account, why parse lines related to branch and function coverage in the parser? It's extra work that's dropped a few moments down the line.
Can the total() function return 3 numbers (lines, branch, function total coverages), instead of one?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.