karma-rollup-preprocessor

raw JSON →
7.0.8 verified Mon Apr 27 auth: no javascript maintenance

Karma preprocessor to bundle ES modules using Rollup. Current stable version 7.0.8 (last released 2021). Release cadence is sporadic with long gaps between major versions. Key differentiators: integrates Rollup into Karma test pipeline, supports all Rollup options, allows multiple configured preprocessors for different transpilation setups. Requires Rollup >=1.0.0 as peer dependency.

error Error: Invalid configuration: preprocessors.rollup expected a string or an array of strings.
cause Preprocessor name used incorrectly (e.g., 'rollupPreprocessor' instead of 'rollup').
fix
In preprocessors config, use 'rollup' as the preprocessor name, not 'rollupPreprocessor'.
error TypeError: Cannot read property 'plugins' of undefined
cause rollupPreprocessor object is missing or not correctly placed in Karma config.
fix
Ensure rollupPreprocessor is defined inside config.set({...}) as a top-level key.
error Error: ENOENT: no such file or directory, open '...'
cause Input file not found because Rollup is trying to resolve a missing module.
fix
Install missing npm packages and configure resolve plugins (e.g., @rollup/plugin-node-resolve).
deprecated rollup-plugin-buble and rollup-plugin-babel are no longer maintained; use @rollup/plugin-buble and @rollup/plugin-babel instead.
fix Replace require('rollup-plugin-buble') with require('@rollup/plugin-buble') and update configuration accordingly.
gotcha Karma's file watcher must be disabled for files processed by rollupPreprocessor (watched: false).
fix Set `watched: false` in the files array for patterns handled by rollup preprocessor.
gotcha The Rollup input option is handled automatically; setting it manually can cause issues.
fix Do not specify `input` in rollupPreprocessor options; the preprocessor sets it to each test file.
gotcha Source map file paths may be incorrect on Windows when using absolute paths.
fix Use relative paths or update to version 7.0.8 which includes a fix.
npm install karma-rollup-preprocessor
yarn add karma-rollup-preprocessor
pnpm add karma-rollup-preprocessor

Basic Karma configuration with rollupPreprocessor for bundling test files.

// karma.conf.js
module.exports = function(config) {
  config.set({
    files: [
      { pattern: 'test/**/*.spec.js', watched: false }
    ],
    preprocessors: {
      'test/**/*.spec.js': ['rollup']
    },
    rollupPreprocessor: {
      plugins: [
        require('rollup-plugin-commonjs')(),
        require('rollup-plugin-node-resolve')()
      ],
      output: {
        format: 'iife',
        name: 'MyTest',
        sourcemap: 'inline'
      }
    }
  });
};