esnext-coverage

Modular coverage tools for the modern web.
Installation
npm install --save-dev esnext-coverage
Usage with test frameworks
See esnext-coverage-examples repository for more details.
Require esnext-coverage when running Tape:
tape -r esnext-coverage test/*.js
Require esnext-coverage when running Mocha:
mocha -r esnext-coverage test/*.js
Replace babel-register with esnext-coverage in the list of Jasmine helpers:
"helpers": [
"../node_modules/esnext-coverage/lib/esnext-coverage.js"
]
Options
The esnext-coverage configuration is an object that extends Babel API options with two additional properties:
reporters
A reporter signature is an object containing formatter
(String
or Function
, defaults to JSON.stringify
), console
(Boolean
, defaults to false
) and outFile
(String
, optional) properties.
When formatter
is a String
, esnext-coverage will attempt to require(`esnext-coverage-format-${formatter}`)
similar to Babel requiring plugins.
reporters: [
{formatter: 'text', console: true},
{formatter: 'html', outFile: 'reports/coverage/coverage.html'},
{formatter: myFormatter, outFile: 'reports/coverage/coverage.my'}
]
If reporters are not specified, a default reporter is used with 'json'
as formatter and 'reports/coverage/coverage.json'
file as output:
reporters: [
{formatter: 'json', outFile: 'reports/coverage/coverage.json'}
]
thresholds
Both global
and local
properties are optional. No threshold is enforced by default.
thresholds: {
global: {
statement: 100,
branch: 100,
function: 100,
line: 100
},
local: {
statement: 100,
branch: 100,
function: 100,
line: 100
}
}
Configuration
Add an "esnext-coverage": {...options}
entry in your package.json
file or create either .esnextcoverage.js
or .esnextcoveragerc
file in the root of your project.
package.json
{
"name": "my project",
"version": "1.2.3",
"esnext-coverage": {
"only": "test/*.js",
"reporters": [
{"formatter": "text", "console": true}
]
}
}
.esnextcoverage.js
module.exports = {
only: 'test/*.js',
reporters: [
{formatter: 'text', console: true}
]
};
.esnextcoveragerc
{
"only": "test/*.js",
"reporters": [
{"formatter": "text", "console": true}
]
}
CLI usage
Usage: esnext-coverage [options] [command]
Commands:
instrument [options] [file] instruments code
collect [options] [file] collects coverage data
format [options] [file] formats coverage data
Options:
-h, --help output usage information
-V, --version output the version number
Reads code from stdin or from a file, instruments it, and writes the instrumented code to stdout or to a file.
Reads code from stdin or from a file, collects coverage data, and writes the result to stdout or to a file.
Transforms coverage data to the specified format.
Prior art
esnext-coverage has been inspired by Adana.
License
MIT License