项目作者: shinnn

项目描述 :
Collect and report code coverage of a JavaScript program
高级语言: JavaScript
项目地址: git://github.com/shinnn/coverage.git
创建时间: 2019-04-07T00:04:20Z
项目社区:https://github.com/shinnn/coverage

开源协议:ISC License

下载


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

  1. $ coverage test.js
  2. write a file
  3. create directories as needed
  4. validate arguments
  5. 3 of 3 passed.
  6. ----------|----------|----------|----------|----------|-------------------|
  7. File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
  8. ----------|----------|----------|----------|----------|-------------------|
  9. All files | 95.15 | 79.52 | 100 | 95.09 | |
  10. index.js | 90.6 | 75.38 | 100 | 90.52 |... 44,148,152,156 |
  11. lib.js | 100 | 94.44 | 100 | 100 | 107 |
  12. ----------|----------|----------|----------|----------|-------------------|

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

Installation

Use npm.

  1. 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.

  1. $ coverage /path/to/entry-point.js # is the same as ↓
  2. $ 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.

  1. $ coverage example.js
  2. ------------|----------|----------|----------|----------|-------------------|
  3. File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
  4. ------------|----------|----------|----------|----------|-------------------|
  5. All files | 100 | 100 | 100 | 100 | |
  6. example.js | 100 | 100 | 100 | 100 | |
  7. ------------|----------|----------|----------|----------|-------------------|
  8. $ coverage --reporter=text-summary example.js
  9. =============================== Coverage summary ===============================
  10. Statements : 100% ( 1/1 )
  11. Branches : 100% ( 1/1 )
  12. Functions : 100% ( 0/0 )
  13. Lines : 100% ( 1/1 )
  14. ================================================================================
  15. $ 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.

  1. $ coverage test.js
  2. [... test results and coverage ...]
  3. ==> Travis CI detected.
  4. ==> Reading reports
  5. + /home/travis/build/shinnn/coverage/coverage/lcov.info bytes=1399
  6. ==> Gzipping contents
  7. ==> Uploading reports
  8. -> Uploading
  9. -> 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