Karma Cucumber Reporter

1.0.4 · maintenance · verified Tue Apr 21

karma-cucumber-reporter is a specialized Karma plugin designed to transform test results from the Karma test runner into the Cucumber JSON format. This output is primarily intended for consumption by external tools like `cucumber-reporting` to generate comprehensive BDD-style reports. The current stable version is 1.0.4, suggesting a mature and stable state rather than active, rapid development. Its key differentiator lies in its strict requirement for a specific test structure: top-level `describe('PREFIX FEATURE', ...)` and nested `describe('SCENARIO NAME', ...)` blocks, which allows it to accurately map Karma's test outcomes to Cucumber features and scenarios. It integrates seamlessly into Karma's configuration, writing the resulting JSON to a specified file or standard output.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to install and configure `karma-cucumber-reporter` in `karma.conf.js`. It includes an example test file structured with the required `PREFIX FEATURE` and `SCENARIO` `describe` blocks, showing how to produce a `cucumber-report.json` output file compatible with Cucumber reporting tools.

npm install -D karma karma-jasmine karma-chrome-launcher karma-cucumber-reporter

// karma.conf.js
module.exports = function(config) {
  config.set({
    frameworks: ['jasmine'],
    files: [
      'test/**/*.spec.js'
    ],
    reporters: ['progress', 'cucumber'],
    plugins: [
      'karma-jasmine',
      'karma-chrome-launcher',
      require('karma-cucumber-reporter')
    ],
    browsers: ['ChromeHeadless'],
    singleRun: true,
    autoWatch: false,
    cucumberReporter: {
      out: './cucumber-report.json', // Output file for the Cucumber JSON report
      prefix: 'FeaturePrefix'       // Prefix to identify features for reporting
    }
  });
};

// test/example.spec.js
describe('FeaturePrefix MyApplication Feature', function () {
  describe('Scenario: As a user, I can log in successfully', function () {
    it('Given I am on the login page', function () {
      expect(true).toBe(true); // Placeholder for actual test logic
    });

    it('When I enter valid credentials', function () {
      expect('username').toEqual('username');
      expect('password').toEqual('password');
    });

    it('Then I should be redirected to the dashboard', function () {
      expect(1 + 1).toBe(2);
    });
  });

  describe('Scenario: As an admin, I can manage users', function () {
    it('Given I am logged in as an admin', function () {
      expect(true).toBe(true);
    });
    it('When I navigate to the user management section', function () {
      expect(true).toBe(true);
    });
    it('Then I should see a list of users', function () {
      expect(false).not.toBe(true);
    });
  });
});

view raw JSON →