rollup-plugin-coverage
raw JSON → 0.1.4 verified Mon Apr 27 auth: no javascript deprecated
Rollup plugin for Istanbul unit test coverage. Version 0.1.4 provides integration with Istanbul instrumenter for code coverage reporting in Rollup and Karma. It offers options for include/exclude patterns, coverage options, and sourcemap support. The plugin is no longer actively maintained; users are advised to migrate to @rollup/plugin-istanbul or official Rollup coverage plugins.
Common errors
error Error: Cannot find module 'rollup-plugin-coverage' ↓
cause Package not installed or missing from node_modules.
fix
Run npm install rollup-plugin-coverage --save-dev
error TypeError: coverage is not a function ↓
cause Using named import instead of default import.
fix
Change import { coverage } to import coverage
Warnings
deprecated Package has not been updated since 2018 and is effectively deprecated. Use @rollup/plugin-istanbul instead. ↓
fix Replace with @rollup/plugin-istanbul: npm install @rollup/plugin-istanbul and update import.
gotcha Plugin must be placed before other plugins (like babel) to avoid instrumentation issues. ↓
fix Place coverage plugin first in the plugins array.
gotcha Coverage variable is not automatically captured in browser testing; requires manual extraction. ↓
fix Use Karma with karma-coverage for automatic browser coverage collection.
gotcha Sourcemap support requires setting sourceMapWithCode: true in coverageOptions. ↓
fix Add coverageOptions: { sourceMapWithCode: true }.
Install
npm install rollup-plugin-coverage yarn add rollup-plugin-coverage pnpm add rollup-plugin-coverage Imports
- default wrong
const coverage = require('rollup-plugin-coverage')correctimport coverage from 'rollup-plugin-coverage' - coverage wrong
import { coverage } from 'rollup-plugin-coverage'correctimport coverage from 'rollup-plugin-coverage' - coverage wrong
const coverage = require('rollup-plugin-coverage')correctconst coverage = require('rollup-plugin-coverage').default
Quickstart
import { rollup } from 'rollup';
import coverage from 'rollup-plugin-coverage';
rollup({
input: 'src/main.js',
plugins: [
coverage({
exclude: ['test/**/*.js', 'node_modules/**'],
coverageOptions: {
esModules: true
}
})
]
}).then(bundle => bundle.write({ file: 'dist/bundle.js', format: 'es' }));