Giter VIP home page Giter VIP logo

cvr's Introduction

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

cvr's People

Contributors

cmdadabo avatar foresmac avatar jrit avatar scottferg avatar tathanen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cvr's Issues

Jacoco (Android) Coverage

I wanted to open a ticket to support jacoco coverage with vokal/jacoco-parse

There are a few issues with Android source structure that might be a problem with finding the appropriate files for linking.

For example:

An android application with a Mock and Live "Flavor" will have the source structured like so:

... //Root project files
app/
    src/
        mock/java/
        main/java/
        live/java/

Additionally we will mostly likely need to specify the root folder for the project as the source is located in any arbitrary subfolder of the main project. In the example above that folder is app

Add github hooks

It would be nice if this would post the results of a coverage check to github showing the percentage of code covered and a link to view details. And, do we want a configurable threshold for successful build, or standardize on 95%?

The benefit here is that a code reviewer can know how much code is covered at a glance while a project dev can always click over to view details if something is off.

Simplify reporting

Currently reporting is via a fairly ugly curl command which could be considerably cleaner. Ignoring the implementation details, which make sense in my head but I haven't put together yet, this is what I would propose:

Reduce:
curl --data "token=$CVR_TOKEN&commit=$GITHASH&coverage=$COVERAGE&coveragetype=cobertura" https://cvr.vokal.io/coverage

Down to:

curl -sSL https://cvr.vokal.io/coverage/$$cvrToken | sh

I'll tackle implementing this. Like I said I have thoughts. So ignoring the question of how I infer all of the additional data, any concerns over this approach?

Python files marked as "clike"

I presume this is use for syntax highlighting? Probably pretty safe to just assume any file that ends in .py is a Python file.

Can't parse go coverage reports?

Not sure, this uploaded to cvr but it's not listing. Maybe I need the prepend path?

mode: count
vip/handler.go:44.31,47.2 2 0
vip/handler.go:49.71,54.16 4 7
vip/handler.go:59.2,61.34 2 7
vip/handler.go:73.2,74.23 2 7
vip/handler.go:78.2,78.21 1 7
vip/handler.go:83.2,83.35 1 6
vip/handler.go:87.2,87.9 1 5
vip/handler.go:54.16,57.3 2 0
vip/handler.go:61.34,63.12 2 10
vip/handler.go:63.12,69.9 5 3
vip/handler.go:74.23,76.3 1 3
vip/handler.go:78.21,81.3 2 1
vip/handler.go:83.35,85.3 1 1
vip/handler.go:90.59,97.2 5 6
vip/handler.go:99.58,101.12 2 1
vip/handler.go:106.2,106.75 1 1
vip/handler.go:101.12,103.3 1 0
vip/handler.go:103.3,105.3 1 1
vip/handler.go:109.59,112.45 2 0
vip/handler.go:116.2,116.30 1 0
vip/handler.go:112.45,115.3 2 0
vip/handler.go:119.65,120.23 1 0
vip/handler.go:124.2,128.45 2 0
vip/handler.go:133.2,137.16 4 0
vip/handler.go:141.2,142.119 2 0
vip/handler.go:120.23,122.3 1 0
vip/handler.go:128.45,131.3 2 0
vip/handler.go:137.16,139.3 1 0
vip/handler.go:145.59,146.24 1 5
vip/handler.go:151.2,151.33 1 5
vip/handler.go:167.2,172.16 5 4
vip/handler.go:176.2,180.16 3 4
vip/handler.go:185.2,187.22 2 4
vip/handler.go:196.2,205.45 5 4
vip/handler.go:146.24,149.3 2 0
vip/handler.go:151.33,158.3 4 0
vip/handler.go:158.3,158.33 1 5
vip/handler.go:158.33,165.3 4 1
vip/handler.go:172.16,174.3 1 0
vip/handler.go:180.16,183.3 2 0
vip/handler.go:187.22,189.13 2 0
vip/handler.go:189.13,191.4 1 0
vip/handler.go:191.4,193.4 1 0
vip/handler.go:205.45,208.3 2 1
vip/handler.go:211.57,214.2 2 0
vip/handler.go:216.82,217.49 1 6
vip/handler.go:217.49,219.17 2 5
vip/handler.go:222.3,222.23 1 5
vip/handler.go:226.3,232.17 6 5
vip/handler.go:235.3,237.45 2 5
vip/handler.go:219.17,221.4 1 0
vip/handler.go:222.23,224.4 1 0
vip/handler.go:232.17,234.4 1 0
vip/handler.go:239.3,241.17 2 1
vip/handler.go:245.3,248.17 4 1
vip/handler.go:252.3,258.45 5 1
vip/handler.go:241.17,243.4 1 0
vip/handler.go:248.17,250.4 1 0
vip/main.go:44.19,49.12 3 0
vip/main.go:49.12,53.39 3 0
vip/main.go:57.3,57.77 1 0
vip/main.go:53.39,55.4 1 0
vip/main.go:57.77,59.4 1 0
vip/main.go:60.3,61.56 1 0
vip/main.go:61.56,63.4 1 0
vip/main.go:67.29,70.8 3 2
vip/main.go:70.8,72.3 1 1
vip/main.go:72.3,77.3 2 1
vip/main.go:80.13,86.16 6 1
vip/main.go:91.2,92.16 2 1
vip/main.go:97.2,101.21 4 1
vip/main.go:105.2,106.25 2 1
vip/main.go:113.2,114.24 2 1
vip/main.go:122.2,132.21 9 1
vip/main.go:86.16,89.3 2 1
vip/main.go:92.16,95.3 2 1
vip/main.go:101.21,103.3 1 1
vip/main.go:106.25,108.3 1 1
vip/main.go:108.3,111.3 2 0
vip/main.go:114.24,116.3 1 1
vip/main.go:116.3,118.17 2 0
vip/main.go:118.17,120.4 1 0
vip/main.go:135.13,139.16 3 0
vip/main.go:143.2,148.60 4 0
vip/main.go:152.2,153.70 1 0
vip/main.go:164.2,164.15 1 0
vip/main.go:174.2,182.20 6 0
vip/main.go:139.16,141.3 1 0
vip/main.go:148.60,150.3 1 0
vip/main.go:153.70,157.18 3 0
vip/main.go:161.4,161.27 1 0
vip/main.go:157.18,159.5 1 0
vip/main.go:164.15,166.17 2 0
vip/main.go:166.17,169.4 2 0
vip/main.go:169.4,171.4 1 0

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.