This module uses nyc to track code coverage, even across subprocess boundaries. It is enabled by default, and there's nothing extra you need to do to use it.
Nyc in turn uses istanbul to do the actual coverage code transformation and reporting.
To disable coverage, run your tests with the --no-coverage
argument.
To re-enable, add the --coverage
argument.
As of version 7, and by default starting in version 15, node-tap lets you easily enforce 100% coverage of all lines, branches, functions, and statements.
To do this, simply enable the check-coverage
flag, which is on by
default.
To not enforce maximum debuggability, code quality, and ease of
maintenance, you can disable it by specifying --no-check-coverage
on the
command line, or adding the config to your package.json like so:
{
"tap": {
"check-coverage": false
}
}
You can very easily take advantage of continuous test coverage reports by using Coveralls.
coveralls
in your project as a dev dependency by running npm
install coveralls --save-dev
COVERALLS_REPO_TOKEN
, and the value is the token you got from
Coveralls.tap
will
automatically generate coverage information and send it to the
appropriate place.There's no requirement that you use Coveralls! Any coverage service
that understands lcov
can be used as well.
For example, using CodeCov, you can do the following:
Add codecov
as a devDependency in your project with this command:
npm install codecov --save-dev
Add a test
script that generates coverage information, and a
posttest
that uploads it to codecov:
{
"scripts": {
"test": "tap",
"posttest": "tap --coverage-report=text-lcov | codecov --pipe"
}
}
Printing out a coverage report can be done along with tests, or after
any covered test run, using the --coverage-report=<type>
argument.
The most popular types are text
and html
, but any report style
supported by istanbul is available, including:
To specify a report format, you can use --coverage-report=<type>
.
The default type is text
, which produces a pretty text-only table on
the terminal. If you specify --coverage-report=html
, then tap will
attempt to launch a web browser to view the report after the test run.
You can prevent launching a browser by specifying the flag --no-browser
.
There are some situations where you may want to precisely specify which tests should provide coverage for which program files, or which tests perhaps should not be instrumented for code coverage at all.
In those cases, use a coverage map option.