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

cvr

v3.0.0

Published

code coverage tools

Downloads

20

Readme

CVR

line cvr

The badge above is generated in part by this repo!

Tools for working with code coverage reports.

CVR has support for processing coverage in Cobertura, LCOV, Jacoco, and Go Cover. Coverage is translated first to a standard JavaScript format and then can be queried for coverage metrics including line, function, and branch coverage. There are also a set of tools for interacting with the GitHub API that make it easier to get files matching coverage reports.

Installation

CVR is a node module and does not have browser support.

npm install cvr

Basic Use

var cvr = require( "cvr" );
cvr.getCoverage( coverageFileContents, coverageFileFormat, function ( err, cov )
{
    var linePercent = cvr.getLineCoveragePercent( cov );
} );

For more complicated examples, taking a look at /test/test.js is recommended.

Common Coverage Object

Parsers are used for each coverage format to convert the diverse formats into a common format that is used internally for processing. This is the Common Coverage Object and documented on lcov-parse and reproduced below.

{
  "title": "Test #1",
  "file": "anim-base/anim-base-coverage.js",
  "functions": {
    "hit": 23,
    "found": 29,
    "details": [ {
      "name": "(anonymous 1)",
      "line": 7,
      "hit": 6
    } ]
  },
  "lines": {
    "found": 181,
    "hit": 143,
    "details": [ {
      "line": 7,
      "hit": 6
    } ]
  },
  "branches": {
    "found": 123,
    "hit": 456,
    "details": [ {
      "line": 7,
      "hit": 6
    } ]
  }
}

Methods

getCoverage( content, type, callback )

  • content | String | the code coverage file contents
  • type | String [ "lcov" | "cobertura" | "gocover" | "jacoco" ] | the code coverage file type
  • callback | Function | Callback args Error, Array of Common Coverage Objects

getFileCoverage( coverageArray, filePath )

  • coverageArray | Array of Common Coverage Objects | array of file coverage
  • filePath | String | the file to find in coverageArray
  • returns | Common Coverage Object | the first matching file found, or undefined

getLine( lineCoverage, line )

  • lineCoverage | Line Coverage from Common Coverage Object | array of file coverage
  • line | Number | the line number to find
  • returns | Object { active: true | false, hit: true | false | null }
  • active whether a line was covered
  • hit whether it was hit where and hit=null when active=false

getLineCoveragePercent( coverageArray )

  • coverageArray | Array of Common Coverage Objects | array of file coverage
  • returns | Number | percent of lines that have coverage

linesCovered( coverage )

  • coverage | Common Coverage Objects | file coverage
  • returns | Array of Line Coverage | only the hit lines from the file

linesMissing( coverage )

  • coverage | Common Coverage Objects | file coverage
  • returns | Array of Line Coverage | only the non-hit lines from the file

getFileType( filePath )

  • filePath | String | the file name or path
  • returns | String | a file type based on filePath extension
  • "bash" | "css" | "go" | "javascript" | "less" | "markdown" | "python" | "sql" | "clike" (default for non-matched)

renderCoverage( coverage, source )

  • coverage | Common Coverage Object | the file coverage
  • source | String | the file contents
  • returns | String | HTML output wraps covered lines in <span>s to indicate whether the line was hit or not.

formatCoverage( coverage, source, filePath, callback )

Returns a complete template with code coloring and syntax highlighting, as compared to renderCoverage which just returns an HTML snippet.

  • coverage | Common Coverage Object | the file coverage
  • source | String | the file contents
  • filePath | String | the file path
  • callback | Function, args err: Error, String: html | html is created based on the source/templates/basic.html file

sortCoverage( coverageArray )

  • coverageArray | Array of Common Coverage Objects | array of file coverage

GitHub Methods

gitHub.getFile( accessToken, owner, repoName, commitHash, filePath, callback )

  • accessToken | String | GitHub access token
  • owner | String | GitHub file owner
  • repoName | String | GitHub repo name
  • commitHash | String | GitHub commit hash (sha)
  • filePath | String | GitHub file path (this must match the path on GitHub, not the local file path)
  • callback | Function, args err: Error, String: contents | contents is the file contents

gitHub.getRepos( accessToken, callback )

This is a convenience method that collects repos from the user's org and own repos

  • accessToken | String | GitHub access token
  • callback | Function, args err: Error, Array: repos | repos is a list of all the repos, the order is not guaranteed to be consistent

gitHub.getOwnerRepos( accessToken, callback )

  • accessToken | String | GitHub access token
  • callback | Function, args err: Error, Array: repos | repos is a list of all the owner's repos

gitHub.getOrgRepos( accessToken, org, callback )

  • accessToken | String | GitHub access token
  • org | String | GitHub organization name
  • callback | Function, args err: Error, Array: repos | repos is a list of all the org's repos

gitHub.createStatus( accessToken, message, callback )

  • accessToken | String | GitHub access token
  • message follows http://mikedeboer.github.io/node-github/#statuses.prototype.create and is passed along directly.
  • callback | Function, args err: Error | callback is invoked directly by the GitHub module

gitHub.getOrgs( accessToken, callback )

  • accessToken | String | GitHub access token
  • callback | Function, args err: Error | callback is invoked directly by the GitHub module

gitHub.getHookByUrl( accessToken, owner, repoName, hookUrl, callback )

  • accessToken | String | GitHub access token
  • owner | String | GitHub hook owner
  • repoName | String | GitHub repo name
  • hookUrl | String | URL of hook
  • callback | Function, args err: Error | callback is invoked directly by the GitHub module

gitHub.createHook( accessToken, owner, repoName, hookUrl, callback )

  • accessToken | String | GitHub access token
  • owner | String | GitHub hook owner
  • repoName | String | GitHub repo name
  • hookUrl | String | URL of hook
  • callback | Function, args err: Error | callback is invoked directly by the GitHub module

gitHub.deleteHook( accessToken, owner, repoName, hookUrl, callback )

  • accessToken | String | GitHub access token
  • owner | String | GitHub hook owner
  • repoName | String | GitHub repo name
  • hookUrl | String | URL of hook
  • callback | Function, args err: Error | callback is invoked directly by the GitHub module

Tests

npm test

Or to run with coverage statistics npm run testcover

Contributing

A JSCS file is included. Please check any changes against the code standards defined in that file. All changes should have tests.

License

MIT