At the end of the day, all you need to do is place the bin nyc in front of the existing test scripts in your package.json:
{
"scripts": {
"test": "nyc ava --timeout=3000"
}
}
that's it! this will instrument the code that your tests execute, and any subprocesses that it spawns.
By default nyc uses Istanbul's text
reporter. Various other reporters are
available. You can view the full list on the Using Alternative Reporters page.
If you'd like to specify alternate reporter, or would like to run
multiple reporters, simply use the --reporter
flag.
for instance, suppose you would like to output the default text report, along with an HTML coverage report.
{
"scripts": {
"test": "nyc --reporter=html --reporter=text ava"
}
}
This will output the text
report to the terminal, as well as outputting the
detailed html
report to ./coverage/index.html
.
coveralls.io is a great tool for adding coverage reporting to your continuous-integration flow. Here's how to get Istanbul integrated with coveralls and travis-ci.org:
npm install coveralls --save-dev
{
"script": {
"test": "nyc --reporter=html --reporter=text ava",
"coverage": "nyc report --reporter=text-lcov | coveralls"
}
}
For private repos, add the environment variable COVERALLS_REPO_TOKEN
to Travis.
add the following to your .travis.yml
:
after_success: npm run coverage
AVA has a TypeScript recipe that should get you started. Feel free to contribute to their docs or make a PR here if you have more details to share! :smile:
nyc and Istanbul provide many advanced configuration options a good place to start learning more is the istanbuljs/nyc README.
Adding coverage to your AVA tests could not be easier
Now, simply place the command nyc in front of your existing test command, for example:
{
"scripts": {
"test": "nyc ava"
}
}