nyc
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
@istanbuljs/load-nyc-config | 1.1.0 | 4.23 kB | ISC | prod | |
@istanbuljs/schema | 0.1.3 | 5.3 kB | MIT | prod | |
caching-transform | 4.0.0 | 4.17 kB | MIT | prod | |
convert-source-map | 1.9.0 | 3.91 kB | MIT | prod | |
decamelize | 1.2.0 | 1.65 kB | MIT | prod | |
find-cache-dir | 3.3.2 | 3.06 kB | MIT | prod | |
find-up | 4.1.0 | 3.66 kB | MIT | prod | |
foreground-child | 2.0.0 | 4.11 kB | ISC | prod | |
get-package-type | 0.1.0 | 2.54 kB | MIT | prod | |
glob | 7.2.3 | 15.08 kB | ISC | prod | |
istanbul-lib-coverage | 3.2.2 | 9.13 kB | BSD-3-Clause | prod | |
istanbul-lib-hook | 3.0.0 | 4.75 kB | BSD-3-Clause | prod | |
istanbul-lib-instrument | 4.0.3 | 14.39 kB | BSD-3-Clause | prod | 1 1 |
istanbul-lib-processinfo | 2.0.3 | 5.58 kB | ISC | prod | |
istanbul-lib-report | 3.0.1 | 10.3 kB | BSD-3-Clause | prod | |
istanbul-lib-source-maps | 4.0.1 | 8.68 kB | BSD-3-Clause | prod | |
istanbul-reports | 3.1.7 | 286.94 kB | BSD-3-Clause | prod | |
make-dir | 3.1.0 | 3.7 kB | MIT | prod | |
node-preload | 0.2.1 | 3.89 kB | MIT | prod | |
p-map | 3.0.0 | 3.26 kB | MIT | prod | |
process-on-spawn | 1.0.0 | 3.23 kB | MIT | prod | |
resolve-from | 5.0.0 | 2.28 kB | MIT | prod | |
rimraf | 3.0.2 | 6.33 kB | ISC | prod | |
signal-exit | 3.0.7 | 3.76 kB | ISC | prod | |
spawn-wrap | 2.0.0 | 11.06 kB | ISC | prod | |
test-exclude | 6.0.0 | 6.75 kB | ISC | prod | |
yargs | 15.4.1 | 54.97 kB | MIT | prod |
NYC, also known as Istanbul's state of the art command line interface, is a robust tool utilized for code coverage in JavaScript. It functions by instrumenting your JavaScript code with line counters, ascertaining the part of the code that has been executed (covered) when running tests. NYC supports applications that spawn subprocesses and provides source mapped coverage for Babel and TypeScript projects. With NYC, developers can conveniently track how much of their codebase is covered by tests, making it easier to identify areas that need further testing.
To use NYC, you will firstly need to install it as a dev dependency in your project. This can be done by running the command npm i -D nyc
or yarn add -D nyc
in your terminal, which will add NYC to the dev dependencies in your package.json file.
Upon installation, NYC should be used to wrap your test command in npm scripts. Here's an example of how you can use NYC with Mocha, a popular test runner:
{
"scripts": {
"test": "mocha",
"coverage": "nyc npm run test"
}
}
To generate a coverage report, you can simply run npm run coverage
. You can also use npx
instead of installing NYC as a dependency.
NYC also provides sophisticated configuration options which allow you to define your specific coverage settings. For instance, if you want to set a threshold for the minimum coverage, you can add the check-coverage
and statements
flags as such:
{
"all": true,
"check-coverage": true,
"statements": 80
}
This setup will fail the build if the statements coverage drops below 80%. For extensive guidance and tips on using and configuring NYC, please refer to the advanced docs in the project's repo.
The comprehensive documentation for NYC can be found primarily in the project's GitHub repository. This includes all the details you need to make effective use of NYC, from installation, usage, example code snippets, to sophisticated configuration options and troubleshooting tips. There are also numerous tutorials and advanced NYC documentation available on the Istanbul.js website. You'll find these resources invaluable in understanding how to generate, interpret, and improve your code coverage reports using NYC. Remember to also check the npx nyc --help
command for more detailed command-line instructions.