jasmine-allure-reporter vs mocha-allure-reporter
Integrating Allure Reporting with Jasmine and Mocha Test Frameworks
jasmine-allure-reportermocha-allure-reporterSimilar Packages:

Integrating Allure Reporting with Jasmine and Mocha Test Frameworks

jasmine-allure-reporter and mocha-allure-reporter are specialized adapters that bridge popular JavaScript testing frameworks (Jasmine and Mocha) with the Allure Report platform. While both aim to generate rich, interactive HTML reports featuring test history, trends, and detailed step logs, they differ fundamentally in their integration mechanics due to the architectural differences between Jasmine and Mocha. jasmine-allure-reporter typically relies on Jasmine's custom reporter interface to capture spec results, whereas mocha-allure-reporter leverages Mocha's robust event-driven runner to hook into test lifecycle events. Choosing the correct package is strictly dictated by your underlying test runner; they are not interchangeable.

Npm Package Weekly Downloads Trend

3 Years

Github Stars Ranking

Stat Detail

Package
Downloads
Stars
Size
Issues
Publish
License
jasmine-allure-reporter034-239 years agoISC
mocha-allure-reporter04526.1 kB0-Apache-2.0

Jasmine vs Mocha Allure Reporters: Architecture and Integration

Generating high-quality test reports is critical for maintaining confidence in large-scale applications. jasmine-allure-reporter and mocha-allure-reporter serve the same ultimate goal—producing rich Allure dashboards—but they operate in distinct ecosystems. The choice isn't about feature parity; it's about compatibility with your test runner's internal architecture. Let's dive into how they handle integration, step tracking, and attachments.

🔌 Integration Mechanics: Reporter Interface vs Event Emitters

The core difference lies in how each package listens to test execution. Jasmine and Mocha expose different APIs for reporting, and the respective Allure packages must adapt to these specific contracts.

jasmine-allure-reporter implements Jasmine's Reporter interface.

  • It receives callbacks like specDone and suiteDone after tests complete.
  • This "post-execution" model means it captures results mostly after the fact, which can limit real-time step granularity unless explicitly coded inside specs.
// jasmine.conf.js configuration
const AllureReporter = require('jasmine-allure-reporter').AllureReporter;

jasmine.getEnv().addReporter(new AllureReporter({
  resultsDir: 'allure-results'
}));

// The reporter listens to Jasmine's internal events
// No manual event wiring needed in test files

mocha-allure-reporter hooks into Mocha's Runner event emitter.

  • It subscribes to events like test, pass, fail, and hook in real-time.
  • This allows for more dynamic interaction, such as logging steps precisely when they happen during test execution.
// mocha.opts or .mocharc.js configuration
module.exports = {
  reporter: 'mocha-allure-reporter',
  reporterOptions: {
    resultsDir: 'allure-results'
  }
};

// Mocha emits events that the reporter catches instantly
// runner.on('test', (test) => { ... })

🪜 Step Tracking: Implicit vs Explicit Logging

Allure's most powerful feature is the ability to break tests down into granular steps. How you define these steps depends heavily on which reporter you use.

jasmine-allure-reporter often requires manual step decoration within the spec.

  • Since Jasmine's reporter interface is less intrusive, you typically wrap actions in allure.step calls inside your it blocks.
  • Without explicit wrapping, the report may only show the top-level test name.
// Jasmine spec file
const allure = require('jasmine-allure-reporter').allure;

it('should log in successfully', () => {
  allure.step('Enter username', () => {
    page.setUsername('user123');
  });
  
  allure.step('Enter password', () => {
    page.setPassword('secret');
  });
  
  page.login();
  expect(page.isLoggedIn).toBe(true);
});

mocha-allure-reporter provides a more fluid API for steps, often integrated via a global allure object or plugin.

  • Mocha's event-driven nature allows the reporter to sometimes infer steps better, but explicit logging is still recommended for clarity.
  • The API feels more native to Mocha's chainable style.
// Mocha spec file
const allure = require('mocha-allure-reporter');

it('should log in successfully', function() {
  allure.step('Enter username', () => {
    page.setUsername('user123');
  });
  
  allure.step('Enter password', () => {
    page.setPassword('secret');
  });
  
  page.login();
  expect(page.isLoggedIn).to.be.true;
});

📎 Handling Attachments: Screenshots and Logs

Adding screenshots or logs to failed tests is a standard requirement for debugging. Both packages support this, but the implementation details vary slightly based on framework conventions.

jasmine-allure-reporter attaches files using the reporter instance or global helper.

  • You typically call allure.addAttachment within your spec or a custom reporter extension.
  • Timing is crucial; attachments must be added before the specDone event fires.
// Jasmine: Adding a screenshot on failure
const allure = require('jasmine-allure-reporter').allure;

afterEach(function() {
  if (this.currentSpec.failedExpectations.length > 0) {
    const screenshot = browser.takeScreenshot();
    allure.addAttachment('Failure Screenshot', screenshot, 'image/png');
  }
});

mocha-allure-reporter uses a similar pattern but leverages Mocha's afterEach hook context.

  • The attachment API is consistent, but the lifecycle hook ensures the test state is readily available.
  • Mocha's error handling makes it easier to trigger attachments automatically on failure.
// Mocha: Adding a screenshot on failure
const allure = require('mocha-allure-reporter');

afterEach(function() {
  if (this.currentTest.state === 'failed') {
    const screenshot = browser.takeScreenshot();
    allure.addAttachment('Failure Screenshot', screenshot, 'image/png');
  }
});

🏷️ Metadata and Labeling

Categorizing tests by severity, feature, or story is essential for meaningful reports. Both packages allow adding labels, but the syntax aligns with their respective framework styles.

jasmine-allure-reporter uses function calls to tag specs.

  • Labels are often added at the beginning of an it block.
  • This keeps metadata close to the test logic but can clutter the spec body.
// Jasmine: Adding severity label
it('should validate critical path', () => {
  allure.addLabel('severity', 'critical');
  allure.addLabel('feature', 'authentication');
  
  // Test logic...
});

mocha-allure-reporter offers a chainable or function-based approach.

  • Some versions allow decorating the test function directly or using setup hooks.
  • This flexibility fits well with Mocha's descriptive describe and it structure.
// Mocha: Adding severity label
it('should validate critical path', function() {
  allure.addLabel('severity', 'critical');
  allure.addLabel('feature', 'authentication');
  
  // Test logic...
});

🌐 Real-World Scenarios

Scenario 1: Legacy Angular Application

You maintain a large AngularJS codebase using Jasmine for unit and E2E tests.

  • Best choice: jasmine-allure-reporter
  • Why? It integrates directly with Jasmine's existing configuration without requiring a framework migration. It respects Angular's digest cycles and Jasmine's async handling.
// Confirmed setup for Angular/Jasmine
jasmine.getEnv().addReporter(new AllureReporter({ resultsDir: 'results' }));

Scenario 2: Modern Node.js API Testing

You are building a REST API tested with Mocha, Chai, and SuperTest.

  • Best choice: mocha-allure-reporter
  • Why? Mocha's flexibility with async/await and its rich event system pairs perfectly with the Allure reporter for detailed API request/response logging.
// Confirmed setup for Node/Mocha
// Run with: mocha --reporter mocha-allure-reporter

Scenario 3: Mixed Framework Migration

Your team is migrating from Jasmine to Mocha incrementally.

  • ⚠️ Challenge: You cannot use a single reporter for both.
  • Strategy: Configure parallel pipelines. Run Jasmine tests with jasmine-allure-reporter and Mocha tests with mocha-allure-reporter, pointing both to the same allure-results directory. Allure CLI will merge them into one report.
# Run Jasmine tests
jasmine --reporter=jasmine-allure-reporter

# Run Mocha tests
mocha --reporter=mocha-allure-reporter

# Generate combined report
allure generate allure-results --clean

📌 Summary Table

Featurejasmine-allure-reportermocha-allure-reporter
Target RunnerJasmineMocha
Integration TypeReporter Interface (specDone)Event Emitter (runner.on)
Step DefinitionManual allure.step wrappersManual allure.step wrappers
Attachment APIallure.addAttachmentallure.addAttachment
Labelingallure.addLabel inside itallure.addLabel inside it
Real-time LoggingLimited (mostly post-test)High (event-driven)
Configurationjasmine.conf.jsCLI flag or .mocharc.js

💡 Final Recommendation

The decision is straightforward: match the reporter to your test runner.

  • If you are entrenched in the Jasmine ecosystem (common in Angular), jasmine-allure-reporter is your only path. It provides solid reporting but may require more manual instrumentation for deep step tracking.
  • If you prefer Mocha (common in Node.js, Vue, and React backends), mocha-allure-reporter offers a slightly more fluid experience due to Mocha's event-driven architecture.

Crucial Note: Do not attempt to swap these packages. A Mocha reporter will silently fail or crash when run against Jasmine, and vice versa, because they listen for completely different internal events. If you need to unify reporting across a mixed codebase, configure both reporters to output to the same results directory and let the Allure CLI merge the data.

How to Choose: jasmine-allure-reporter vs mocha-allure-reporter

  • jasmine-allure-reporter:

    Choose jasmine-allure-reporter if your project relies on Jasmine as the primary test runner, which is common in legacy Angular applications or projects preferring Jasmine's built-in assertion syntax. This package is designed to hook into Jasmine's specific reporter lifecycle, translating spec descriptions and expectation failures into Allure's XML format. It is the only viable option for Jasmine users who need detailed step annotations and attachment support without switching testing frameworks. Avoid this package if you are using Mocha, as it lacks the necessary hooks to capture Mocha's test events.

  • mocha-allure-reporter:

    Choose mocha-allure-reporter if your testing stack is built on Mocha, often paired with Chai or Sinon in Node.js and modern frontend environments. This package takes advantage of Mocha's flexible event emitter system to track test suites, hooks (before/after), and individual test cases with high precision. It supports advanced Allure features like dynamic step logging and severity labeling directly within Mocha's it blocks. Do not use this package with Jasmine, as it expects Mocha-specific runner events that Jasmine does not emit.

README for jasmine-allure-reporter

Jasmine Allure Plugin

A plugin to generate an Allure report out of Jasmine tests.

Using Allure Reporter in Jasmine2

Add the lib into package.json and then configure the plugin:

// conf.js
var AllureReporter = require('jasmine-allure-reporter');
jasmine.getEnv().addReporter(new AllureReporter({
  resultsDir: 'allure-results'
}));

Using Allure Reporter in Protractor

Put the above code into the onPrepare inside of your conf.js:

// conf.js
exports.config = {
  framework: 'jasmine2',
  onPrepare: function() {
    var AllureReporter = require('jasmine-allure-reporter');
    jasmine.getEnv().addReporter(new AllureReporter({
      resultsDir: 'allure-results'
    }));
  }
}

Generate HTML report from Allure results

The Reporter will generate xml files inside of a resultsDir, then we need to generate HTML out of them. You can use Maven for that. Copy ready-to-use pom.xml from node_modules/jasmine-allure-reporter and run:

mvn site -Dallure.results_pattern=allure-results

It will put HTMLs into target/site/allure-maven-plugin folder. To serve them via localhost:1324 use:

mvn jetty:run -Djetty.port=1234

Otherwise choose one of other ways to generate HTML.

Adding Screenshot in the end of each test

  onPrepare: function () {
    var AllureReporter = require('jasmine-allure-reporter');
    jasmine.getEnv().addReporter(new AllureReporter());
    jasmine.getEnv().afterEach(function(done){
      browser.takeScreenshot().then(function (png) {
        allure.createAttachment('Screenshot', function () {
          return new Buffer(png, 'base64')
        }, 'image/png')();
        done();
      })
    });
  }

Note done callback!

TBD

  • Currently attachments are added to the test case instead of the current step. This needs to be fixed in allure-js-commons.
  • Add support for Features.
  • Add support to Jasmine1. Right now only Jasmine2 is available (do we really need this?).
  • Add ability to use reflection for decoration method of page objects so that we don't need to write Allure-related boilerplate tying ourselves to one specific reporter.

For Developers

See the system tests to quickly check how the reporter works in real life: node_modules/protractor/bin/protractor ./test/system/conf.js