karma-systemjs

raw JSON →
0.16.0 verified Fri May 01 auth: no javascript maintenance

A Karma plugin adapter for loading test files via SystemJS module loader instead of script tags. Current version 0.16.0 disables SystemJS bundles by default; set useBundles: true to enable. Supports transpilers like Babel and TypeScript. Key differentiator: integrates SystemJS module loading into Karma test runner for testing ES modules with transpilation. Requires manual configuration of SystemJS config file and serving of dependencies. Note: The project appears to be in maintenance mode with limited recent activity.

error TypeError: 'undefined' is not a function (evaluating 'Function.prototype.bind')
cause PhantomJS v1.x does not support Function.prototype.bind, required by transpilers.
fix
Add 'phantomjs-polyfill' to your SystemJS config: System.config({ map: { 'phantomjs-polyfill': 'node_modules/phantomjs-polyfill/bind-polyfill.js' } });
error Error: Mismatched anonymous define() module: function (...) { ... }
cause Files loaded via System.import() that contain AMD define() blocks may conflict with SystemJS's own AMD detection.
fix
Ensure all modules are properly defined as ES modules or System.register; avoid anonymous AMD define() calls.
breaking In v0.16.0, SystemJS bundles are no longer automatically loaded. You must set useBundles: true in the systemjs config to enable bundle loading.
fix Set systemjs.useBundles: true in your Karma config if you rely on SystemJS bundles.
breaking In v0.9.0, arrays in SystemJS config file are overwritten by arrays in karma config, rather than merged.
fix Ensure that the karma config arrays either contain all needed values or use a different approach to avoid data loss.
gotcha The transpiler (e.g., plugin-babel, traceur) must be served as served:true, included:false in Karma file patterns since v0.13.0.
fix In your SystemJS config, specify the transpiler path under paths or map; karma-systemjs will handle serving automatically.
gotcha PhantomJS v1.x lacks Function.prototype.bind, causing transpiler errors: 'TypeError: undefined is not a function'
fix Install phantomjs-polyfill and include it in your SystemJS config.
deprecated es6-module-loader is deprecated in favor of systemjs itself; modern SystemJS versions may not need it.
fix Consider using SystemJS 0.21+ which includes its own polyfill; remove es6-module-loader dependency if not needed.
npm install karma-systemjs
yarn add karma-systemjs
pnpm add karma-systemjs

Configures Karma to use SystemJS for loading test files via System.import(), with a separate system config file and additional serve files.

// karma.conf.js
module.exports = function(config) {
  config.set({
    frameworks: ['systemjs', 'jasmine'],
    files: [
      'test/**/*.spec.js'
    ],
    plugins: ['karma-systemjs', 'karma-jasmine', 'karma-chrome-launcher'],
    systemjs: {
      configFile: 'system.conf.js',
      serveFiles: [
        'lib/**/*.js'
      ],
      config: {
        paths: {
          'angular-mocks': 'node_modules/angular-mocks/angular-mocks.js'
        }
      },
      useBundles: false
    },
    browsers: ['Chrome']
  });
};