Modular coverage tools for the modern web.
npm install --save-dev esnext-coverage
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"
]
The esnext-coverage configuration is an object that extends Babel API options with two additional properties:
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: [
// Format using esnext-coverage-format-text,
// and write the formatted output to stdout:
{formatter: 'text', console: true},
// Format using esnext-coverage-format-html,
// and write the formatted output to a file:
{formatter: 'html', outFile: 'reports/coverage/coverage.html'},
// Format using a custom formatter function,
// and write the formatted output to a file:
{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'}
]
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
}
}
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.
{
"name": "my project",
"version": "1.2.3",
"esnext-coverage": {
"only": "test/*.js",
"reporters": [
{"formatter": "text", "console": true}
]
}
}
module.exports = {
only: 'test/*.js',
reporters: [
{formatter: 'text', console: true}
]
};
{
"only": "test/*.js",
"reporters": [
{"formatter": "text", "console": true}
]
}
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.
esnext-coverage has been inspired by Adana.