Heads Up! You're viewing the docs for v0.10, an old version of Karma. v6.4 is the newest.

Migration from v0.8

The good thing is that you don't have to migrate everything at once. You can keep the global Karma and update project by project.

Note:

If you are getting "npm ERR! peerinvalid Peer" error. Try removing old version of Karma first.

Let's get started...

First upgrade your local or global install of Karma via the command line using NPM.

# upgrade local install...
cd <path-to-your-project>
npm install karma

# or upgrade global install...
sudo npm install -g karma

Plugins #

All the frameworks, reporters, preprocessors and browser launchers are now separate plugins. Here is a list of all of them including related plugins. So install all the plugins you need:

npm install karma-<plugin name> --save-dev

Frameworks #

  • jasmine (karma-jasmine ships with Karma)
  • mocha karma-mocha
  • qunit karma-qunit

Preprocessors #

  • coffee (karma-coffee-preprocessor ships with Karma)
  • html2js (karma-ng-html2js-preprocessor ships with Karma)
  • coverage karma-coverage
  • live karma-live-preprocessor

Reporters #

  • dots (included, no plugin)
  • progress (included, no plugin)
  • growl karma-growl-reporter
  • junit karma-junit-reporter
  • teamcity karma-teamcity-reporter

Launchers #

  • Chrome (karma-chrome-launcher ships with Karma)
  • Chrome Canary (karma-chrome-launcher ships with Karma)
  • PhantomJS (karma-phantomjs-launcher ships with Karma)
  • Firefox karma-firefox-launcher
  • Safari karma-safari-launcher
  • IE karma-ie-launcher
  • Opera karma-opera-launcher

New config syntax #

The configuration file is now a regular Node module, that exports a single function. This function will get called with a config object:

module.exports = function(config) {
  config.set({
    basePath: '.',
    files: [
      // ...
    ]
  })
};

Also, remove all the constants like JASMINE, JASMINE_ADAPTER, MOCHA, MOCHA_ADAPTER, QUNIT, QUNIT_ADAPTER, REQUIRE, REQUIRE_ADAPTER, ANGULAR_SCENARIO, ANGULAR_SCENARIO_ADAPTER from files and use frameworks config instead:

// before
files = [
  JASMINE,
  JASMINE_ADAPTER,
  '*.js'
];

// change to
module.exports = function(config) {
  config.set({
    frameworks: ['jasmine'],
    files: ['*.js']
  });
};

That should be it ;-) If you have any problem, ask on mailing list.

You can also check out migrating AngularJS.