Karma Test Runner

6.4.4 · deprecated · verified Sun Apr 19

Karma, currently at stable version 6.4.4, is a long-standing JavaScript test runner specifically designed to execute tests directly within real browser environments. Its core utility lies in facilitating test-driven development by providing quick feedback cycles, enabling testing across diverse browsers (desktop, mobile, tablets) and integration with continuous integration servers. It supports running tests on file saves and offers features like coverage reporting via Istanbul. However, the project has been officially deprecated. The web testing ecosystem has evolved significantly since Karma's inception over ten years ago, leading to the emergence of more performant and modern alternatives. While critical security issues will continue to be addressed until 12 months after Angular CLI's Web Test Runner support stabilizes, no new features or general bug fixes are being accepted. Users are strongly encouraged to migrate to modern alternatives such as Web Test Runner, `jasmine-browser-runner`, Jest, or Vitest.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart sets up a basic `karma.conf.js` using Jasmine and ChromeHeadless. To run, first install `karma`, `karma-jasmine`, `jasmine-core`, and `karma-chrome-launcher` (`npm install -D karma karma-jasmine jasmine-core karma-chrome-launcher`), then execute `npx karma start`.

// karma.conf.js
module.exports = function(config) {
  config.set({
    frameworks: ['jasmine'],
    files: [
      'src/**/*.js',
      'test/**/*.js'
    ],
    exclude: [],
    preprocessors: {},
    reporters: ['progress'],
    port: 9876,
    colors: true,
    logLevel: config.LOG_INFO,
    autoWatch: true,
    browsers: ['ChromeHeadless'], // Ensure karma-chrome-launcher is installed
    singleRun: false,
    concurrency: Infinity
  });
};

// test/example.test.js
describe('A simple test', function() {
  it('should pass', function() {
    expect(true).toBe(true);
  });
});

view raw JSON →