GithubHelp home page GithubHelp logo

vscode-lcov's Introduction

VSCode LCOV

Renders Line and Branch coverage from lcov.info files interactively.

Live coverage info

Live info

Features

  • loosely coupled, just point it to a lcov.info file and you're in business!
  • can read multiple lcov.info files (e.g. one for the entire project, one for the last single test run)
  • generates a Coverage Report
  • supports watching certain files and executing a command (e.g. run test on file change)
  • supports JavaScript source maps

Coverage Report

  • Ctrl+T or Cmd+T then choose Show Coverage Report Coverage Report

Setting up

  • There is a complete simple example at https://github.com/alexandrudima/vscode-lcov/tree/master/examples/fizzbuzz
  • There are many tools that can generate lcov.info files
  • I have tested lcov.info files generated by istanbul e.g.istanbul cover --report lcovonly ./node_modules/mocha/bin/_mocha -- -R spec test.js
  • Configure the paths to your lcov.info files via the setting lcov.path. e.g:
"lcov.path": [
    "./.build/coverage/lcov.info",
    "./.build/coverage-single/lcov.info"
]
  • Live coverage via the setting lcov.watch. e.g. to execute a certain command any time a .js file is changed:
"lcov.watch": [{
    "pattern": "**/*.js",
    "command": "npm run test-coverage"
}]
  • Live coverage can be switched on via Ctrl+T or Cmd+T then choose Enable watchers
  • JavaScript sourcemaps via the setting lcov.sourceMaps.
"lcov.sourceMaps": true

Troubleshooting

  • View > Output and choose lcov.

Branch coverage: Configuration

"lcov.branchCoverage": "off" or "simple" (default) or "full"

Branch coverage: A single boolean expression

exports.example = function (a) {
	if (a) {
		console.log('1');
	}
}

The above source code contains a single branch block consisting of two branches.

Test Code if taken else taken "simple" "full"
//no calls image image
example(1) image image
example(0) image image
example(0), example(1) image image

Branch coverage: A binary boolean expression

exports.example = function (a, b) {
	if (a && b) {
		console.log('1');
	}
}

For the table columns:

  • IF = if taken
  • ELSE = else taken
  • A? = a evaluated
  • B? = b evaluated
Test Code IF ELSE A? B? "simple" "full"
//no calls image image
example(0,0) image image
example(0,1) image image
example(1,0) image image
example(1,1) image image
example(0,0), example(0,1) image image
example(0,0), example(1,0) image image
example(0,0), example(1,1) image image
example(0,1), example(1,0) image image
example(0,1), example(1,1) image image
example(1,0), example(1,1) image image
example(0,0), example(0,1), example(1,0) image image
example(0,0), example(0,1), example(1,1) image image
example(0,0), example(1,0), example(1,1) image image
example(0,1), example(1,0), example(1,1) image image

Branch coverage: A ternary boolean expression

exports.example = function (a, b, c) {
	if (a && b && c) {
		console.log('1');
	}
}

For the table columns:

  • IF = if taken
  • ELSE = else taken
  • A? = a evaluated
  • B? = b evaluated
  • C? = c evaluated
Test Code IF ELSE A? B? C? "full"
//no calls image
example(0,0,0) image
example(1,0,0) image
example(1,1,0) image
example(1,1,1) image

vscode-lcov's People

Contributors

alexdima avatar

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.