karma-rollup
raw JSON → 1.0.1 verified Mon Apr 27 auth: no javascript
Karma preprocessor that bundles ES2015 modules using Rollup for testing. Version 1.0.1 is the latest stable release (as of 2023+). Designed for use with Karma test runner, it integrates Rollup as a preprocessor to transpile and bundle ES module imports/exports into a single file per test file. Supports Rollup plugins (e.g., Bublé, Babel), custom preprocessors, watch mode with caching, and sourcemaps. Differentiators: lightweight compared to Webpack-based preprocessors, leverages Rollup's tree-shaking and fast bundling. Requires Rollup >=1.0.0 as a peer dependency.
Common errors
error Error: Cannot find module 'karma-rollup' ↓
cause karma-rollup is not installed or not listed in plugins.
fix
Run 'npm install karma-rollup --save-dev' and ensure plugins includes 'karma-*' or 'karma-rollup'.
error RollupError: You must supply output.name for IIFE format ↓
cause IIFE output format requires a name to avoid global scope collision.
fix
Add property 'output.name: 'MyProject'' to rollupPreprocessor.options.
error Error: No provider for "framework:jasmine"! (Resolving: framework:jasmine) ↓
cause Karma Jasmine framework not installed.
fix
Run 'npm install karma-jasmine --save-dev' and add 'jasmine' to frameworks array.
Warnings
gotcha 'input' property is handled automatically by karma-rollup; do not set it in rollupPreprocessor.options. ↓
fix Remove 'input' from options; the input file is determined by Karma's files and preprocessors.
gotcha Rollup 2.0+ changed the output format structure; older karma-rollup versions may not support Rollup >=2. Check peer dep: rollup >=1.0.0 (but may work with 2.x). ↓
fix Update karma-rollup or downgrade Rollup to >=1.0.0 <2.0.0; or test with Rollup 2.0 and adjust output config accordingly.
gotcha Using 'rollupPreprocessor' configuration, not 'rollup' – the key must be exactly 'rollupPreprocessor'. ↓
fix Set the config key as 'rollupPreprocessor' (not 'rollup') in karma.conf.js.
gotcha Missing 'name' in output for 'iife' format will cause Rollup error: 'You must supply output.name for IIFE format'. ↓
fix Add 'output.name: 'YourProject'' to rollupPreprocessor.options.
gotcha If not using default plugins array, ensure 'karma-rollup' is included in the plugins list (or 'karma-*'). ↓
fix Add 'karma-rollup' to config.plugins or use the wildcard pattern 'karma-*'.
Install
npm install karma-rollup yarn add karma-rollup pnpm add karma-rollup Imports
- rollupPreprocessor wrong
const rollupPreprocessor = require('karma-rollup')correct// Configure in karma.conf.js – no import needed - customPreprocessors wrong
const customPreprocessors = require('karma-rollup').customPreprocessorscorrect// Configure in karma.conf.js – no import needed - karma-rollup wrong
npm install karma-rollupcorrectnpm install karma-rollup --save-dev
Quickstart
// karma.conf.js
module.exports = function(config) {
config.set({
basePath: '',
frameworks: ['jasmine'],
files: [
'test/**/*.spec.js'
],
plugins: [
'karma-jasmine',
'karma-chrome-launcher',
'karma-rollup'
],
preprocessors: {
'test/**/*.spec.js': ['rollup']
},
rollupPreprocessor: {
options: {
plugins: [require('rollup-plugin-buble')()],
output: {
format: 'iife',
name: 'MyProject',
sourcemap: 'inline'
}
}
},
browsers: ['ChromeHeadless'],
reporters: ['progress'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
singleRun: false,
concurrency: Infinity
});
}