cvr

3.0.0 • Public • Published

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 )

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

Readme

Keywords

none

Package Sidebar

Install

npm i cvr

Weekly Downloads

0

Version

3.0.0

License

MIT

Unpacked Size

104 kB

Total Files

20

Last publish

Collaborators

  • jrit
  • vokal