cvr
v3.0.0
Published
code coverage tools
Downloads
20
Readme
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 contentstype
| String[ "lcov" | "cobertura" | "gocover" | "jacoco" ]
| the code coverage file typecallback
| Function | Callback argsError
,Array of Common Coverage Objects
getFileCoverage( coverageArray, filePath )
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
getLine( lineCoverage, line )
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
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 coveragesource
| 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 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
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 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
gitHub.getRepos( accessToken, callback )
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
gitHub.getOwnerRepos( accessToken, callback )
accessToken
| String | GitHub access tokencallback
| 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 tokenorg
| String | GitHub organization namecallback
| 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 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
gitHub.getOrgs( accessToken, callback )
accessToken
| String | GitHub access tokencallback
| Function, args err: Error | callback is invoked directly by the GitHub module
gitHub.getHookByUrl( accessToken, owner, repoName, hookUrl, callback )
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
gitHub.createHook( accessToken, owner, repoName, hookUrl, callback )
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
gitHub.deleteHook( accessToken, owner, repoName, hookUrl, callback )
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
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