karma-rollup-plugin
raw JSON → 0.2.4 verified Mon Apr 27 auth: no javascript maintenance
A Karma preprocessor plugin that integrates Rollup for on-the-fly bundling and ES2015+ transpilation in test environments. Current version is 0.2.4 (stable, but rarely updated). It supports Rollup plugins, source maps (inline), and multiple ES versions via Babel or Buble. Compared to alternatives like karma-rollup-preprocessor, this plugin is simpler, more actively maintained at the time, and more aligned with the Rollup ecosystem. However, it lacks modern Rollup features and may not work with Rollup >=1.0.
Common errors
error Error: Cannot find module 'rollup' ↓
cause Rollo is not installed or is a missing peer dependency.
fix
Run: npm install rollup --save-dev
error TypeError: rollup.rollup is not a function ↓
cause Incompatible Rollup version >=1.0 where API changed.
fix
Install Rollup 0.x: npm install rollup@0.68.2 --save-dev
error WARN: 'umd' format requires a module name. Use the 'moduleName' option. ↓
cause Using 'umd' format without 'moduleName' in rollupPreprocessor.
fix
Add moduleName to rollupPreprocessor or switch to 'iife'.
Warnings
breaking No support for Rollup >=1.0 due to API changes. ↓
fix Upgrade to a maintained fork or use karma-rollup-preprocessor with Rollup compatibility.
deprecated Package is no longer actively maintained; last release was years ago. ↓
fix Consider using @open-wc/karma-esm or karma-rollup-preprocessor.
gotcha Using 'umd' format without a module name throws a warning and may produce unexpected results. ↓
fix Always specify a module name when using 'umd', or use 'iife' for tests.
gotcha Source maps must be 'inline' because Karma expects them inlined for proper debugging. ↓
fix Set sourceMap: 'inline' in rollupPreprocessor config.
Install
npm install karma-rollup-plugin yarn add karma-rollup-plugin pnpm add karma-rollup-plugin Imports
- rollupPreprocessor (Karma config key) wrong
rollupPreprocessor: require('karma-rollup-plugin')correct// In karma.conf.js rollupPreprocessor: { /* options */ } - Plugin as a module (programmatic use) wrong
import karmaRollup from 'karma-rollup-plugin';correctconst karmaRollup = require('karma-rollup-plugin'); - Preprocessor in preprocessors wrong
preprocessors: { 'test/**/*.js': ['karma-rollup-plugin'] }correctpreprocessors: { 'test/**/*.js': ['rollup'] }
Quickstart
// karma.conf.js
module.exports = function (config) {
config.set({
basePath: '',
frameworks: ['jasmine'],
files: [
'test/**/*.spec.js'
],
preprocessors: {
'test/**/*.spec.js': ['rollup']
},
rollupPreprocessor: {
plugins: [ require('rollup-plugin-buble')() ],
format: 'iife',
sourceMap: 'inline'
},
reporters: ['progress'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['ChromeHeadless'],
singleRun: false
});
};