{"id":19038,"library":"babel-plugin-coverage","title":"babel-plugin-coverage","description":"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.","status":"maintenance","version":"1.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/yyx990803/babel-plugin-coverage","tags":["javascript","babel","coverage","istanbul","tdd","test","unit"],"install":[{"cmd":"npm install babel-plugin-coverage","lang":"bash","label":"npm"},{"cmd":"yarn add babel-plugin-coverage","lang":"bash","label":"yarn"},{"cmd":"pnpm add babel-plugin-coverage","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency for Babel plugin API","package":"babel-core","optional":false}],"imports":[{"note":"This is a Babel plugin, not imported in user code. Configure in .babelrc under plugins.","wrong":"const coverage = require('babel-plugin-coverage')","symbol":"default","correct":"// No default import; use .babelrc config"},{"note":"In .babelrc, use the short name 'coverage'. The full name also works but is unnecessary.","wrong":"{\n  \"plugins\": [ [ \"babel-plugin-coverage\", {} ] ]\n}","symbol":"plugin","correct":"{\n  \"plugins\": [ \"coverage\" ]\n}"},{"note":"Options can include 'ignore' (glob pattern) or 'only' (glob pattern). Note: glob patterns should include trailing slash for directories.","wrong":"{\n  \"plugins\": [ [ \"babel-plugin-coverage\", { \"ignore\": \"test\" } ] ]\n}","symbol":"options","correct":"{\n  \"plugins\": [ [ \"coverage\", { \"ignore\": \"test/\" } ] ]\n}"}],"quickstart":{"code":"// .babelrc\n{\n  \"env\": {\n    \"test\": {\n      \"plugins\": [ \"coverage\" ]\n    }\n  }\n}\n\n// Install: npm install --save-dev babel-plugin-coverage\n// Then run tests with Karma + karma-coverage or mocha + nyc.","lang":"javascript","description":"Shows basic setup in .babelrc to enable coverage only during test environments."},"warnings":[{"fix":"Use @babel/plugin-istanbul for Babel 7+.","message":"babel-plugin-coverage only works with Babel 6.x. It is incompatible with Babel 7+.","severity":"breaking","affected_versions":"all"},{"fix":"In package.json, set \"nyc\": { \"include\": [ \"/\" ] } or equivalent.","message":"When using with NYC, you must configure NYC not to instrument your code via nyc.include.","severity":"gotcha","affected_versions":"all"},{"fix":"Use karma-coverage or nyc to generate HTML/lcov reports.","message":"This plugin does not generate any coverage report. It only instruments code. You still need a coverage reporter (karma-coverage, nyc).","severity":"gotcha","affected_versions":"all"},{"fix":"Consider migrating to @babel/plugin-istanbul for newer Babel versions and istanbul compatibility.","message":"The original babel-plugin-__coverage__ and this fork are effectively in maintenance mode. No new features or updates.","severity":"deprecated","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"npm install --save-dev babel-preset-env and add \"presets\": [\"env\"] to .babelrc","cause":"Missing or misconfigured babel-preset-env in .babelrc","error":"Couldn't find preset \"env\" relative to directory"},{"fix":"Use @babel/plugin-istanbul or downgrade to Babel 6.","cause":"Using a Babel 6 plugin with Babel 7+","error":"Error: Plugin/Preset files are not allowed to export objects, only functions."},{"fix":"Use Node.js >= 4.0 and <= 10.x (verify package.json engines if present).","cause":"Node.js version incompatible; the package may require older Node","error":"EBADENGINE: Unsupported engine for babel-plugin-coverage@1.0.0"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}