coverage
A command-line tool to collect and report code coverage of a JavaScript program
Last updated a year ago by shinnn .
ISC · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install coverage 
SYNC missed versions from official npm registry.

coverage

npm version Github Actions Build Status Build status CircleCI codecov

A command-line tool to collect and report code coverage of a JavaScript program

$ coverage test.js

✔ write a file
✔ create directories as needed
✔ validate arguments

3 of 3 passed.

----------|----------|----------|----------|----------|-------------------|
File      |  % Stmts | % Branch |  % Funcs |  % Lines | Uncovered Line #s |
----------|----------|----------|----------|----------|-------------------|
All files |    95.15 |    79.52 |      100 |    95.09 |                   |
 index.js |     90.6 |    75.38 |      100 |    90.52 |... 44,148,152,156 |
 lib.js   |      100 |    94.44 |      100 |      100 |               107 |
----------|----------|----------|----------|----------|-------------------|

This is an opinionated wrapper of c8, different in the following points:

Installation

Use npm.

npm install coverage

Once this package is installed to the project directory, users can execute coverage command inside npm scripts.

CLI

coverage [options] <file|command> [args]

An example of the HTML report

Execute the command, print code coverage to the stdout and write HTML reports under the ./coverage directory.

<file|command> can be either a JavaScript file path or a command. If a path is provided, the file is run with the node command.

$ coverage /path/to/entry-point.js # is the same as ↓
$ coverage node /path/to/entry-point.js

If the provided JavaScript path ends with .mjs,

Reporters

Users can override the default format of reports with --reporter option.

$ coverage example.js
------------|----------|----------|----------|----------|-------------------|
File        |  % Stmts | % Branch |  % Funcs |  % Lines | Uncovered Line #s |
------------|----------|----------|----------|----------|-------------------|
All files   |      100 |      100 |      100 |      100 |                   |
 example.js |      100 |      100 |      100 |      100 |                   |
------------|----------|----------|----------|----------|-------------------|

$ coverage --reporter=text-summary example.js

=============================== Coverage summary ===============================
Statements   : 100% ( 1/1 )
Branches     : 100% ( 1/1 )
Functions    : 100% ( 0/0 )
Lines        : 100% ( 1/1 )
================================================================================

$ coverage --reporter=none example.js # No reports

Codecov integration

When the execution exits with code 0 on a CI service or GitHub Actions, it automatically uploads the generated coverage to Codecov. Whether CODECOV_TOKEN environment variable is required or not varies between services.

$ coverage test.js

[... test results and coverage ...]

==> Travis CI detected.
==> Reading reports
    + /home/travis/build/shinnn/coverage/coverage/lcov.info bytes=1399
==> Gzipping contents
==> Uploading reports
    -> Uploading
    -> View reports at https://codecov.io/github/shinnn/coverage/commit/e4f5880b8ec5885e6a0b79030df5871e19d6de1d

c8 command-line options are supported. Run npx coverage --help to show the detailed reference for them.

coverage report

Output a report in the format specified in --reporter option.

This subcommand is only available after coverage has already been run.

License

ISC License © 2019 Shinnosuke Watanabe

Current Tags

  • 0.4.1                                ...           latest (a year ago)

22 Versions

  • 0.4.1                                ...           a year ago
  • 0.4.0                                ...           a year ago
  • 0.3.3                                ...           a year ago
  • 0.3.2                                ...           a year ago
  • 0.3.1                                ...           a year ago
  • 0.3.0                                ...           a year ago
  • 0.2.3                                ...           a year ago
  • 0.2.2                                ...           a year ago
  • 0.2.1                                ...           a year ago
  • 0.2.0                                ...           a year ago
  • 0.1.5                                ...           a year ago
  • 0.1.4                                ...           a year ago
  • 0.1.3                                ...           a year ago
  • 0.1.2                                ...           a year ago
  • 0.1.2-1                                ...           a year ago
  • 0.1.2-0                                ...           a year ago
  • 0.1.1                                ...           a year ago
  • 0.1.0                                ...           a year ago
  • 0.0.1-2                                ...           a year ago
  • 0.0.1-1                                ...           a year ago
  • 0.0.1-0                                ...           a year ago
  • 0.0.0                                ...           9 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 76
Last Day 0
Last Week 3
Last Month 109
Dependencies (7)
Dev Dependencies (5)
Dependents (1)

Copyright 2014 - 2017 © taobao.org |