Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Readme Reshuffle #1093

Merged
merged 12 commits into from May 3, 2019
52 changes: 23 additions & 29 deletions README.md
Expand Up @@ -78,15 +78,15 @@ This table is a quick TLDR for the rest of this readme and there are more advanc

| Option name | Description | Type | Default |
| ----------- | ----------- | ---- | ------- |
| `all` | whether or not to instrument all files (not just the ones touched by your test suite) | `Boolean` | `false` |
| `check-coverage` | check whether coverage is within thresholds, fail if not | `Boolean` | `false` |
| `extension` | a list of extensions that nyc should attempt to handle in addition to `.js` | `Array<String>` | `['.js']` |
| `include` | [globs of files to be included from instrumentation](#selecting-files-for-coverage) | `Array<String>` | `['**']`|
| `exclude` | See [selecting files for coverage for more info](#selecting-files-for-coverage) | `Array<String>` | [list](https://github.com/istanbuljs/istanbuljs/blob/master/packages/test-exclude/index.js#L176-L184) |
| `reporter` | [coverage reporters to use](https://istanbul.js.org/docs/advanced/alternative-reporters/) | `Array<String>` | `['text']` |
| `report-dir` | where to put the coverage report files | `String` | `./coverage` |
| `skip-full` | don't show files with 100% statement, branch, and function coverage | `Boolean` | `false` |
| `temp-dir` | directory to output raw coverage information to | `String` | `./.nyc_output` |
| `all` | Whether or not to instrument all files (not just the ones touched by your test suite) | `Boolean` | `false` |
| `check-coverage` | Check whether coverage is within thresholds, fail if not | `Boolean` | `false` |
| `extension` | List of extensions that nyc should attempt to handle in addition to `.js` | `Array<String>` | `['.js']` |
| `include` | See [selecting files for coverage] for more info | `Array<String>` | `['**']`|
| `exclude` | See [selecting files for coverage] for more info | `Array<String>` | [list](https://github.com/istanbuljs/istanbuljs/blob/master/packages/test-exclude/index.js#L176-L184) |
| `reporter` | [Coverage reporters to use](https://istanbul.js.org/docs/advanced/alternative-reporters/) | `Array<String>` | `['text']` |
| `report-dir` | Where to put the coverage report files | `String` | `./coverage` |
| `skip-full` | Don't show files with 100% statement, branch, and function coverage | `Boolean` | `false` |
| `temp-dir` | Directory to output raw coverage information to | `String` | `./.nyc_output` |

Configuration can also be provided by `nyc.config.js` if programmed logic is required:
```js
Expand Down Expand Up @@ -117,7 +117,7 @@ As an example, an alternative way to configure nyc for `babel-plugin-istanbul` w
}
```

To publish and reuse your own `nyc` configuration, simply create an npm module that exports an `index.json` with your `nyc` config.
To publish and reuse your own `nyc` configuration, simply create an npm module that exports your JSON config (via [`index.json`](https://github.com/istanbuljs/istanbuljs/blob/master/packages/nyc-config-typescript/) or a CJS [`index.js`](https://github.com/istanbuljs/istanbuljs/blob/master/packages/nyc-config-hook-run-in-this-context/)).

## Selecting files for coverage

Expand Down Expand Up @@ -235,14 +235,17 @@ nyc may create artefact directories within the project root, such as:

## Require additional modules

The `--require` flag can be provided to `nyc` to indicate that additional
modules should be required in the subprocess collecting coverage:
The `--require` flag can be provided to `nyc` to indicate that additional modules should be required in the subprocess collecting coverage:
JaKXz marked this conversation as resolved.
Show resolved Hide resolved

`nyc --require @babel/register --require @babel/polyfill mocha`
```
nyc --require @babel/register --require @babel/polyfill mocha
```

## Caching

`nyc`'s default behavior is to cache instrumented files to disk to prevent instrumenting source files multiple times, and speed `nyc` execution times. You can disable this behavior by running `nyc` with the `--cache false` flag. You can also change the default cache directory from `./node_modules/.cache/nyc` by setting the `--cache-dir` flag.
`nyc`'s default behavior is to cache instrumented files to disk to prevent instrumenting source files multiple times, and speed `nyc` execution times.
You can disable this behavior by running `nyc` with the `--cache false` flag.
You can also change the default cache directory from `./node_modules/.cache/nyc` by setting the `--cache-dir` flag.

## Coverage thresholds

Expand All @@ -264,13 +267,10 @@ To do this check on a per-file basis (as opposed to in aggregate), set the `per-

### High and low watermarks

Several of the coverage reporters supported by nyc display special information
for high and low watermarks:
Several of the coverage reporters supported by nyc display special information for high and low watermarks:

* high-watermarks represent healthy test coverage (in many reports
this is represented with green highlighting).
* low-watermarks represent sub-optimal coverage levels (in many reports
this is represented with red highlighting).
* high-watermarks represent healthy test coverage (in many reports this is represented with green highlighting).
* low-watermarks represent sub-optimal coverage levels (in many reports this is represented with red highlighting).

You can specify custom high and low watermarks in nyc's configuration:

Expand Down Expand Up @@ -313,14 +313,7 @@ rather than having to ignore every instance of that method:
}
```

## Accurate stack traces using source-maps

When `produce-source-map` is set to true, then the instrumented source files will
include inline source maps for the instrumenter transform. When combined with
[source-map-support](https://github.com/evanw/node-source-map-support),
stack traces for instrumented code will reflect their original lines.

### Support for custom require hooks (babel, typescript, etc.)
## Support for custom require hooks (babel, typescript, etc.)

nyc supports custom require hooks like [`@babel/register`]. nyc can load
the hooks for you, [using the `--require` flag](#require-additional-modules).
Expand All @@ -330,7 +323,7 @@ of the pre-transpiled code. You'll have to configure your custom require hook
to inline the source-map in the transpiled code. For Babel that means setting
the `sourceMaps` option to `inline`.

### Source-Map support for pre-instrumented codebases
## Source-Map support for pre-instrumented codebases

If you opt to pre-instrument your source-code (rather than using a just-in-time
transpiler like [`@babel/register`]) nyc supports both inline source-maps and
Expand Down Expand Up @@ -361,3 +354,4 @@ Take a look at http://istanbul.js.org/docs/advanced/ and please feel free to [co

[`@babel/register`]: https://www.npmjs.com/package/@babel/register
[`babel-plugin-istanbul`]: https://github.com/istanbuljs/babel-plugin-istanbul
[selecting files for coverage]: #selecting-files-for-coverage