# coverage

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

Latest version **0.4.1** (published 2019-06-12) · ISC license · 0 weekly downloads

## Install

```sh
npm install coverage
pnpm add coverage
yarn add coverage
bun add coverage
```

Provides the command `coverage`.

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.4.1 |
| Published | 2019-06-12 |
| First published | 2011-02-24 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 7 |
| Unpacked size | 12.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Shinnosuke Watanabe |
| Maintainers | shinnn |
| Keywords | code, coverage, quality, report, analysis, ecmascript, command, command-line, cli, travis-ci, github-actions, appveyor, circleci, codecov |

## Links

- npm: https://www.npmjs.com/package/coverage
- Repository: https://github.com/shinnn/coverage
- Homepage: https://github.com/shinnn/coverage#readme
- Issues: https://github.com/shinnn/coverage/issues
- npm.io page: https://npm.io/package/coverage

## Dependencies (7)

- [c8](https://npm.io/package/c8.md) ^5.0.1
- [slash](https://npm.io/package/slash.md) ^3.0.0
- [which](https://npm.io/package/which.md) ^1.3.1
- [test-exclude](https://npm.io/package/test-exclude.md) ^5.2.3
- [yargs-parser](https://npm.io/package/yargs-parser.md) ^13.1.1
- [foreground-child](https://npm.io/package/foreground-child.md) ^1.5.6
- [normalize-package-data](https://npm.io/package/normalize-package-data.md) ^2.5.0

## Alternatives

- [@salesforce/cli](https://npm.io/package/@salesforce/cli.md) — 389.7K weekly downloads
- [@mintlify/cli](https://npm.io/package/@mintlify/cli.md) — 208.9K weekly downloads
- [@grafana/e2e-selectors](https://npm.io/package/@grafana/e2e-selectors.md) — 128.7K weekly downloads
- [mintlify](https://npm.io/package/mintlify.md) — 112.0K weekly downloads
- [@intlayer/cli](https://npm.io/package/@intlayer/cli.md) — 22.8K weekly downloads

## Recent versions

- 0.4.1 (latest) — 2019-06-12
- 0.4.0 — 2019-06-07
- 0.3.3 — 2019-05-26
- 0.3.2 — 2019-05-26
- 0.3.1 — 2019-05-05
- 0.3.0 — 2019-04-30
- 0.2.3 — 2019-04-29
- 0.2.2 — 2019-04-29
- 0.2.1 — 2019-04-29
- 0.2.0 — 2019-04-27
- 0.1.5 — 2019-04-18
- 0.1.4 — 2019-04-17
- 0.1.3 — 2019-04-17
- 0.1.2 — 2019-04-17
- 0.1.2-1 — 2019-04-16
- … 7 more at https://npm.io/package/coverage/versions

## README

# coverage

[![npm version](https://img.shields.io/npm/v/coverage.svg)](https://www.npmjs.com/package/coverage)
[![Github Actions](https://action-badges.now.sh/shinnn/coverage)](https://wdp9fww0r9.execute-api.us-west-2.amazonaws.com/production/results/shinnn/coverage)
[![Build Status](https://travis-ci.com/shinnn/coverage.svg?branch=master)](https://travis-ci.com/shinnn/coverage)
[![Build status](https://ci.appveyor.com/api/projects/status/x5huttqwjqfpl05q/branch/master?svg=true)](https://ci.appveyor.com/project/ShinnosukeWatanabe/coverage/branch/master)
[![CircleCI](https://circleci.com/gh/shinnn/coverage/tree/master.svg?style=shield)](https://circleci.com/gh/shinnn/coverage/tree/master)
[![codecov](https://codecov.io/gh/shinnn/coverage/branch/master/graph/badge.svg)](https://codecov.io/gh/shinnn/coverage)

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

```console
$ 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](https://github.com/bcoe/c8), different in the following points:

* Runs both [`html` and `text` reporter](https://github.com/istanbuljs/nyc#running-reports) by default
* Automatically enables [ECMAScript module](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import) support for `.mjs` files
* The first argument can be a JavaScript file path instead of a command
* Built-in [Codecov](https://codecov.io) support

## Installation

[Use](https://docs.npmjs.com/cli/install) [npm](https://docs.npmjs.com/about-npm/).

```
npm install coverage
```

Once this package is installed to the project directory, users can execute `coverage` command inside [npm scripts](https://docs.npmjs.com/misc/scripts#description).

## CLI

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

<img alt="An example of the HTML report" src="screenshot.png" width="330px" align="right">

Execute the command, print code coverage to the stdout and write [HTML reports](https://istanbul.js.org/docs/advanced/alternative-reporters/#html) 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.

```console
$ 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`,

* [ECMAScript module mode](https://nodejs.org/api/esm.html) is automatically [enabled](https://nodejs.org/api/esm.html#esm_enabling).
* [`--es-module-specifier-resolution`](https://nodejs.org/api/esm.html#esm_customizing_esm_specifier_resolution_algorithm) is automatically set to `node`.

#### Reporters

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

```console
$ 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](https://github.com/features/actions), it automatically uploads the generated coverage to [Codecov](https://docs.codecov.io/docs). Whether `CODECOV_TOKEN` environment variable is required or not varies between [services](https://github.com/codecov/codecov-bash#ci-providers).

```console
$ 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](https://github.com/bcoe/c8/blob/v3.4.0/lib/parse-args.js#L13-L74) 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](./LICENSE) © 2019 Shinnosuke Watanabe

---
_Source: https://npm.io/package/coverage · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
