0.2.2 • Published 1 year ago

@appbot.co/uncover v0.2.2

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

@appbot.co/uncover

Maintainability Test Coverage

npm version npm downloads node-current (scoped)

Several code quality tools can only handle line coverage, but that doesn't help when your production code is failing with missed branches, or uncovered methods.

This tool allow you to take your valid LCOV files, with the useful branch and function coverage, and modify the line coverage to reflect those misses.

Usage

Install

npm i @appbot.co/uncover
# or
yarn add @appbot.co/uncover

Run

For a single coverage file

uncover coverage/lcov.info > coverage/lcov.uncovered.info
# For your coverage provider, you may then need to rename it back to find it
mv coverage/lcov.uncovered.info coverage/lcov.info
# send to your coverage provider. eg.
# ./cc-test-reporter after-build -t lcov -p "./"

If your coverage is produced from multiple test runs

# store each runs coverage with unique ids
UUID=$(cat /proc/sys/kernel/random/uuid)
mv lcov.info lcov.$UUID.info

# once all the runs are complete, merge and uncover
uncover coverage/lcov.*.info > coverage/lcov.info
# you can now send to your coverage provider as though it was a single run. eg.
# ./cc-test-reporter after-build -t lcov -p "./"

📔 Notes

For Ruby: You will need to use the umbrellio fork with the method coverage branch to get method coverage until PR#987 is merged. For Javascript: c8 dose not currently produce correct branch and function coverage. Stick with nyc for now.

Uncovering

// javascript
if (something) {
  newThing = new Thing();
}
# ruby
newThing = Thing.new if something

Testing each of these with something set will show positive line coverage, and checking coverage locally would likely show the missing (branch) coverage from where it was non-truthy, but your online tool may not show that. For a PR with anything substantial going on, it's easy to miss a non-present test covering non-present code. Well, you won't any more. In fact, you may be triggered to look even harder, because now some code that seems obviously covered, will show no coverage at all.

# javascript
const meth = () => 'call me'
# ruby 3.1
def meth = 'call me'

These too would show positive line coverage, even when the method was never called. These are rectified by clearing the coverage for the line on which they were defined.

Here are before and after shots showing the coverage in the gutter on VSCode. Branch coverage can be seen in the before shot, but this will show as fully covered in some tools, as the method coverage is here.

before after

As an example of the lies that line coverage provides. When we enabled this tool at Appbot our coverage on Code Climate dropped by about 4%. Now excuse me while I go squash some potential bugs 🐛.

Merging

If you pass in multiple lcov files uncover will merge them ... properly. All the coverage elements get summed before uncover does its real work.

example:

uncover lcov.run1.info lcov.run2.info > lcov.info

0.2.2

1 year ago

0.2.1

1 year ago

0.2.0

1 year ago

0.1.0

1 year ago