Karma QUnit Adapter

4.2.1 · active · verified Sun Apr 19

karma-qunit is a plugin for the Karma test runner that provides an adapter for integrating QUnit, a popular JavaScript unit testing framework. This package allows developers to run their QUnit tests within the Karma environment, facilitating automated testing across various browsers and environments. The current stable version is 4.2.1. Releases appear to be driven by bug fixes and compatibility updates with new Karma or QUnit versions, rather than a fixed cadence, often with several minor releases and occasional major updates. Key differentiators include its tight integration with Karma's robust browser launching and reporting capabilities, offering a more flexible and powerful testing setup compared to running QUnit tests directly in a browser without a test runner. It handles the setup and teardown required for QUnit tests within Karma's lifecycle. While many modern projects lean towards frameworks like Jest or Vitest, karma-qunit remains relevant for projects using QUnit, particularly those with existing Karma test setups or legacy codebases.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates a basic Karma configuration (`karma.conf.js`) for running QUnit tests, including how to enable the `karma-qunit` plugin, specify test files, and pass custom QUnit configuration options via the `client` property. It also includes the crucial `clearContext: false` for proper UI display.

const path = require('path');

module.exports = function (config) {
  config.set({
    basePath: '',
    frameworks: ['qunit'],
    plugins: ['karma-qunit'],
    files: [
      // Your QUnit test files
      'test/**/*.js',
      // Optional: QUnit library itself if not globally available, though karma-qunit often handles it
      // path.resolve(__dirname, 'node_modules/qunit/qunit/qunit.js')
    ],
    exclude: [],
    preprocessors: {},
    reporters: ['progress'],
    port: 9876,
    colors: true,
    logLevel: config.LOG_INFO,
    autoWatch: true,
    browsers: ['Chrome'],
    singleRun: false,
    concurrency: Infinity,
    client: {
      clearContext: false, // Recommended for showUI: true
      qunit: {
        showUI: true,
        testTimeout: 5000, // Example QUnit config option
        filter: 'my-module:*' // Another example
      }
    }
  })
}

view raw JSON →