babel-plugin-coverage

raw JSON →
1.0.0 verified Sat Apr 25 auth: no javascript maintenance

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.

error Couldn't find preset "env" relative to directory
cause Missing or misconfigured babel-preset-env in .babelrc
fix
npm install --save-dev babel-preset-env and add "presets": ["env"] to .babelrc
error Error: Plugin/Preset files are not allowed to export objects, only functions.
cause Using a Babel 6 plugin with Babel 7+
fix
Use @babel/plugin-istanbul or downgrade to Babel 6.
error EBADENGINE: Unsupported engine for babel-plugin-coverage@1.0.0
cause 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).
breaking babel-plugin-coverage only works with Babel 6.x. It is incompatible with Babel 7+.
fix Use @babel/plugin-istanbul for Babel 7+.
gotcha When using with NYC, you must configure NYC not to instrument your code via nyc.include.
fix In package.json, set "nyc": { "include": [ "/" ] } or equivalent.
gotcha This 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.
deprecated The 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.
npm install babel-plugin-coverage
yarn add babel-plugin-coverage
pnpm add babel-plugin-coverage

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.