The badge above is generated in part by this repo!
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.
CVR is a node module and does not have browser support.
npm install cvr
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.
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
} ]
}
}
content
| String | the code coverage file contentstype
| String[ "lcov" | "cobertura" | "gocover" | "jacoco" ]
| the code coverage file typecallback
| Function | Callback argsError
,Array of Common Coverage Objects
coverageArray
| Array of Common Coverage Objects | array of file coveragefilePath
| String | the file to find incoverageArray
- returns | Common Coverage Object | the first matching file found, or
undefined
lineCoverage
| Line Coverage from Common Coverage Object | array of file coverageline
| Number | the line number to find- returns | Object { active: true | false, hit: true | false | null }
active
whether a line was coveredhit
whether it was hit where andhit=null
whenactive=false
coverageArray
| Array of Common Coverage Objects | array of file coverage- returns | Number | percent of lines that have coverage
coverage
| Common Coverage Objects | file coverage- returns | Array of Line Coverage | only the hit lines from the file
coverage
| Common Coverage Objects | file coverage- returns | Array of Line Coverage | only the non-hit lines from the file
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)
coverage
| Common Coverage Object | the file coveragesource
| String | the file contents- returns | String | HTML output wraps covered lines in
<span>
s to indicate whether the line was hit or not.
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 coveragesource
| String | the file contentsfilePath
| String | the file pathcallback
| Function, args err: Error, String: html |html
is created based on thesource/templates/basic.html
file
coverageArray
| Array of Common Coverage Objects | array of file coverage
accessToken
| String | GitHub access tokenowner
| String | GitHub file ownerrepoName
| String | GitHub repo namecommitHash
| 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
This is a convenience method that collects repos from the user's org and own repos
accessToken
| String | GitHub access tokencallback
| Function, args err: Error, Array: repos |repos
is a list of all the repos, the order is not guaranteed to be consistent
accessToken
| String | GitHub access tokencallback
| Function, args err: Error, Array: repos |repos
is a list of all the owner's repos
accessToken
| String | GitHub access tokenorg
| String | GitHub organization namecallback
| Function, args err: Error, Array: repos |repos
is a list of all the org's repos
accessToken
| String | GitHub access tokenmessage
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
accessToken
| String | GitHub access tokencallback
| Function, args err: Error | callback is invoked directly by the GitHub module
accessToken
| String | GitHub access tokenowner
| String | GitHub hook ownerrepoName
| String | GitHub repo namehookUrl
| String | URL of hookcallback
| Function, args err: Error | callback is invoked directly by the GitHub module
accessToken
| String | GitHub access tokenowner
| String | GitHub hook ownerrepoName
| String | GitHub repo namehookUrl
| String | URL of hookcallback
| Function, args err: Error | callback is invoked directly by the GitHub module
accessToken
| String | GitHub access tokenowner
| String | GitHub hook ownerrepoName
| String | GitHub repo namehookUrl
| String | URL of hookcallback
| Function, args err: Error | callback is invoked directly by the GitHub module
npm test
Or to run with coverage statistics npm run testcover
A JSCS file is included. Please check any changes against the code standards defined in that file. All changes should have tests.
MIT