Code Monkey home page Code Monkey logo

diff-test-coverage's Introduction

diff-test-coverage

A Node.js commandline tool which filters test coverage based on a (source control) diff.

NPM versionDependency Status

Supported coverage report formats:

  • lcov
  • cobertura
  • clover
  • jacoco
  • golang-cover

Supported source control systems:

  • Git
  • Mercurial
  • Anything else that produces unified diffs.

Installation

  1. Install Node.js with NPM
  2. npm i -g @connectis/diff-test-coverage

Example output

Screenshot

Usage and options

Execute diff-test-coverage to see the documentation.

Usage:
1. Execute your tests to generate your test coverage reports.
2. Figure out what Git or Mercurial command to use to generate your diff (see Examples below).
3. Execute: <diff command> | diff-test-coverage -c <coverage report glob> -t <coverage report type> --

Options:
  --help                   Show help  [boolean]
  --version                Show version number  [boolean]
  -c, --coverage           Glob pattern(s) that specify which coverage report files to use.  [array] [required]
  -t, --type               The type of coverage report. When provided multiple times the types will be mapped to the matching coverage glob patterns.  [array] [required] [choices: "lcov", "cobertura", "clover", "jacoco", "golang-cover"]
  -l, --line-coverage      Required line coverage percentage on the diff. The application will exit with -1 if this is not reached.  [number] [default: 80]
  -b, --branch-coverage    Required branch coverage percentage on the diff. The application will exit with -1 if this is not reached.  [number] [default: 80]
  -f, --function-coverage  Required function coverage percentage on the diff. The application will exit with -1 if this is not reached.  [number] [default: 80]
  --diff-base-dir          The base directory for resolving relative paths in the diff. Uses current working directory by default.  [string] [default: `process.cwd()`]
  --diff-filter            Glob pattern(s) that specify which files from the diff should be included.  [array]
  --log-base-dir           The base directory for resolving relative paths in the console logger. Uses current working directory by default.  [string] [default: `process.cwd()`]
  --log-template           The information which should be logged to the console.  [array] [choices: "diff-files", "coverage-files-line", "coverage-files-complete", "totals-line", "totals-complete", "errors"] [default: ["coverage-files-complete","totals-complete","errors"]]
  --color                  Whether colors should be used in the log. Default: autodetect by 'chalk'.  [boolean]

Examples:
  git diff master...MY-BRANCH | diff-test-coverage -c **/coverage.xml -t cobertura --                                                                     Runs 'diff-test-coverage' with a git diff and Cobertura coverage reports.
  hg export -r "branch(.) and not merge()" | diff-test-coverage -c **/target/site/jacoco/jacoco.xml -t jacoco --                                          Runs 'diff-test-coverage' with a mercurial diff and Jacoco coverage reports.
  <diff command> | diff-test-coverage --log-template diff-files coverage-files-line totals-line errors <other args> --                                    Runs 'diff-test-coverage' with custom logging.
  <diff command> | diff-test-coverage --diff-filter *.java *.kt --log-template diff-files coverage-files-complete totals-complete errors <other args> --  Runs 'diff-test-coverage' with the diff filtered on Java and Kotlin files.
  <diff command> | diff-test-coverage --no-color <other args> --                                                                                          Runs 'diff-test-coverage' without color in the log.
  git diff master...MY-BRANCH                                                                                                                             Creates a diff of the Git branch 'MY-BRANCH' which originated from the master branch.
  hg export -r "branch(.) and not merge()"                                                                                                                Creates a diff of the current Mercurial branch, excluding any merge commits.
  hg export -r "branch(MY-BRANCH) and not merge()"                                                                                                        Creates a diff of the Mercurial branch MY-BRANCH, excluding any merge commits.

diff-test-coverage's People

Contributors

andreroggeri avatar marklagendijk avatar

Stargazers

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

Watchers

 avatar  avatar  avatar

diff-test-coverage's Issues

Multiple dependencies contain `minimist` vulnerability

The following packages are using a version of minimist that contains a vulnerability:
cobertura-parse
golang-cover-parse
jacoco-parse
These packages aren't maintained anymore so I'm not sure how to proceed. If there's anything I can do to help let me know.

Can't get it to work with lcov?

I am running this command:

$ git diff develop...feature/optimistic-ui | diff-test-coverage -c coverage/clover.xml -t lcov

I'm getting the following error:

Not enough non-option arguments: got 0, need at least 1

Any ideas?

An unexpected error occured: Error: Failed to parse string

Trying to get it to work with lcov and jest tests. Here's my command and result:

git diff develop...feature/update-mentions | diff-test-coverage -c coverage/clover.xml -t lcov --
An unexpected error occurred: Error: Failed to parse string
    at maybeWrapAsError (/Users/karl/.nvm/versions/node/v10.16.3/lib/node_modules/@connectis/diff-test-coverage/node_modules/bluebird/js/release/util.js:61:12)
    at /Users/karl/.nvm/versions/node/v10.16.3/lib/node_modules/@connectis/diff-test-coverage/node_modules/bluebird/js/release/nodeback.js:38:50
    at walkFile (/Users/karl/.nvm/versions/node/v10.16.3/lib/node_modules/@connectis/diff-test-coverage/node_modules/lcov-parse/lib/index.js:108:9)
    at /Users/karl/.nvm/versions/node/v10.16.3/lib/node_modules/@connectis/diff-test-coverage/node_modules/lcov-parse/lib/index.js:118:13
    at FSReqWrap.readFileAfterClose [as oncomplete] (internal/fs/read_file_context.js:53:3)

template `coverage-lines-line` does not work

Using template coverage-lines-line causes the following error.
All other templates are working for me.

git diff origin/master...HEAD | diff-test-coverage -c coverage/lcov.info -t lcov --log-template coverage-lines-line --
An unexpected error occurred: TypeError: Cannot read property 'toString' of undefined
    at _.find.detail (/Users/home/.nvm/versions/node/v10.18.1/lib/node_modules/@connectis/diff-test-coverage/lib/console-reporter.js:126:73)
    at baseFindIndex (/Users/home/.nvm/versions/node/v10.18.1/lib/node_modules/@connectis/diff-test-coverage/node_modules/lodash/lodash.js:802:11)
    at findIndex (/Users/home/.nvm/versions/node/v10.18.1/lib/node_modules/@connectis/diff-test-coverage/node_modules/lodash/lodash.js:7258:14)
    at Function.find (/Users/home/.nvm/versions/node/v10.18.1/lib/node_modules/@connectis/diff-test-coverage/node_modules/lodash/lodash.js:5059:21)
    at isLineCovered (/Users/home/.nvm/versions/node/v10.18.1/lib/node_modules/@connectis/diff-test-coverage/lib/console-reporter.js:126:29)
    at displayLineCoverageLine (/Users/home/.nvm/versions/node/v10.18.1/lib/node_modules/@connectis/diff-test-coverage/lib/console-reporter.js:95:23)
    at Object.displayLineCoverageLine (/Users/home/.nvm/versions/node/v10.18.1/lib/node_modules/@connectis/diff-test-coverage/lib/console-reporter.js:62:29)
    at _.forEach (lodash.templateSources[0]:18:10)
    at /Users/home/.nvm/versions/node/v10.18.1/lib/node_modules/@connectis/diff-test-coverage/node_modules/lodash/lodash.js:4905:15
    at baseForOwn (/Users/home/.nvm/versions/node/v10.18.1/lib/node_modules/@connectis/diff-test-coverage/node_modules/lodash/lodash.js:2990:24)
    at /Users/home/.nvm/versions/node/v10.18.1/lib/node_modules/@connectis/diff-test-coverage/node_modules/lodash/lodash.js:4874:18
    at Function.forEach (/Users/home/.nvm/versions/node/v10.18.1/lib/node_modules/@connectis/diff-test-coverage/node_modules/lodash/lodash.js:9342:14)
    at _.forEach (lodash.templateSources[0]:16:4)
    at /Users/home/.nvm/versions/node/v10.18.1/lib/node_modules/@connectis/diff-test-coverage/node_modules/lodash/lodash.js:4905:15
    at baseForOwn (/Users/home/.nvm/versions/node/v10.18.1/lib/node_modules/@connectis/diff-test-coverage/node_modules/lodash/lodash.js:2990:24)
    at /Users/home/.nvm/versions/node/v10.18.1/lib/node_modules/@connectis/diff-test-coverage/node_modules/lodash/lodash.js:4874:18

const lineCoverage = _.find(coverageDetails, detail => detail.line.toString() === lineNumber.toString());

When I log out the value of coverageDetails, I get a string from the my git diff:
import { lstatSync, readdirSync, readFileSync } from "fs";.

The issue seems to be that this line is passing a previousLineNumber arg

const message = displayLineCoverageLine(lineNumber, previousLineNumber, line, linesCoverageDetails);

However, displayLineCoverageLine is not expecting that arg.
function displayLineCoverageLine(lineNumber, line, linesCoverageDetails) {

Windows compatibility

This error is ocurring while parsing a cobertura.xml file.

I'm using the following command to get the coverage diff:

git diff develop...HEAD | diff-test-coverage -c coverage/cobertura-coverage.xml -t cobertura --

lcov file doesn't work, I get the "No coverage information found for any of the new lines in the diff." message.

git diff develop...HEAD | diff-test-coverage -c coverage/lcov.info -t lcov --

Is there anything wrong with my setup ?

PS: I already tried to increase the node max memory, but still the same error

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.