Search code examples
reportcode-coveragegulp

How to make a Gulp Code Coverage Badge?


A lot of projects in GitHub use the Badges to communicate the total Code coverage of the tests. How can we achieve that using Gulp tests?

For instance, the Badge for overall coverage of a system displays:

enter image description here


Solution

  • After going around on GitHub, I found the solution for Badges:

    http://shields.io/

    I was able to create an npm module that takes the Cobertura report and outputs the overall percentage of the coverage and generate the badge with 3 colors, based on the thresholds.

    https://www.npmjs.org/package/istanbul-cobertura-badger

    I'm adding this here because I ended up working on my own solution...

    var coberturaBadger = require('istanbul-cobertura-badger');
    
    var coberturaFile = "build/tests/cobertura-coverage.xml";
    var destinationPath = path.join(process.env.PWD, "build/tests");
    
    coverageBadger(coberturaFile, destinationPath, function() {
      console.log("Badge created at " + destinationPath + "/cobertura.svg");
    });