Registry / testing / babel-plugin-coverage

babel-plugin-coverage

JSON →
library1.0.0jsnpmunverified

A Babel 6.x plugin that instruments JavaScript code with Istanbul-compatible `__coverage__` variables for test coverage collection. v1.0.0 is the latest stable release. This fork of babel-plugin-__coverage__ adds istanbul-style ignore hints and alters statement counting for conditionals. It works with Karma and mocha/nyc without additional tooling. No ongoing development; exists as a legacy solution for projects stuck on Babel 6.

npm install babel-plugin-coverage
INSTALL
IMPORT
SIG · BABEL-PLUGIN-COVER
B
babel-plugin-coverage
testingjavascriptv1.0.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
// No default import; use .babelrc config
const coverage = require('babel-plugin-coverage')
This is a Babel plugin, not imported in user code. Configure in .babelrc under plugins.
plugin
{ "plugins": [ "coverage" ] }
{ "plugins": [ [ "babel-plugin-coverage", {} ] ] }
In .babelrc, use the short name 'coverage'. The full name also works but is unnecessary.
options
{ "plugins": [ [ "coverage", { "ignore": "test/" } ] ] }
{ "plugins": [ [ "babel-plugin-coverage", { "ignore": "test" } ] ] }
Options can include 'ignore' (glob pattern) or 'only' (glob pattern). Note: glob patterns should include trailing slash for directories.

Shows basic setup in .babelrc to enable coverage only during test environments.

// .babelrc { "env": { "test": { "plugins": [ "coverage" ] } } } // Install: npm install --save-dev babel-plugin-coverage // Then run tests with Karma + karma-coverage or mocha + nyc.
Debug
Known issues
breakingbabel-plugin-coverage only works with Babel 6.x. It is incompatible with Babel 7+.
fix
Use @babel/plugin-istanbul for Babel 7+.
affects: all
gotchaWhen using with NYC, you must configure NYC not to instrument your code via nyc.include.
fix
In package.json, set "nyc": { "include": [ "/" ] } or equivalent.
affects: all
gotchaThis plugin does not generate any coverage report. It only instruments code. You still need a coverage reporter (karma-coverage, nyc).
fix
Use karma-coverage or nyc to generate HTML/lcov reports.
affects: all
deprecatedThe original babel-plugin-__coverage__ and this fork are effectively in maintenance mode. No new features or updates.
fix
Consider migrating to @babel/plugin-istanbul for newer Babel versions and istanbul compatibility.
affects: all
Errors
Common errors & fixes
Couldn't find preset "env" relative to directory
Missing or misconfigured babel-preset-env in .babelrc
fix
npm install --save-dev babel-preset-env and add "presets": ["env"] to .babelrc
Error: Plugin/Preset files are not allowed to export objects, only functions.
Using a Babel 6 plugin with Babel 7+
fix
Use @babel/plugin-istanbul or downgrade to Babel 6.
EBADENGINE: Unsupported engine for babel-plugin-coverage@1.0.0
Node.js version incompatible; the package may require older Node
fix
Use Node.js >= 4.0 and <= 10.x (verify package.json engines if present).
Upgrade
Version history
1.0.0latest on npm
Audit
Dependencies
babel-corerequiredPeer dependency for Babel plugin API
Agent activity
17 hits · last 30 days
node
16
OpenAI (training)
1
Resources
babel-plugin-coverage — npm install babel-plugin-coverage · libregistry