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.
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.
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.
specDone and suiteDone after tests complete.// 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.
test, pass, fail, and hook in real-time.// 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) => { ... })
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.
allure.step calls inside your it blocks.// 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 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;
});
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.
allure.addAttachment within your spec or a custom reporter extension.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.
// 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');
}
});
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.
it block.// 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.
describe and it structure.// Mocha: Adding severity label
it('should validate critical path', function() {
allure.addLabel('severity', 'critical');
allure.addLabel('feature', 'authentication');
// Test logic...
});
You maintain a large AngularJS codebase using Jasmine for unit and E2E tests.
jasmine-allure-reporter// Confirmed setup for Angular/Jasmine
jasmine.getEnv().addReporter(new AllureReporter({ resultsDir: 'results' }));
You are building a REST API tested with Mocha, Chai, and SuperTest.
mocha-allure-reporter// Confirmed setup for Node/Mocha
// Run with: mocha --reporter mocha-allure-reporter
Your team is migrating from Jasmine to Mocha incrementally.
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
| Feature | jasmine-allure-reporter | mocha-allure-reporter |
|---|---|---|
| Target Runner | Jasmine | Mocha |
| Integration Type | Reporter Interface (specDone) | Event Emitter (runner.on) |
| Step Definition | Manual allure.step wrappers | Manual allure.step wrappers |
| Attachment API | allure.addAttachment | allure.addAttachment |
| Labeling | allure.addLabel inside it | allure.addLabel inside it |
| Real-time Logging | Limited (mostly post-test) | High (event-driven) |
| Configuration | jasmine.conf.js | CLI flag or .mocharc.js |
The decision is straightforward: match the reporter to your test runner.
jasmine-allure-reporter is your only path. It provides solid reporting but may require more manual instrumentation for deep step tracking.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.
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.
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.
A plugin to generate an Allure report out of Jasmine tests.
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'
}));
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'
}));
}
}
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.
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!
allure-js-commons.See the system tests to quickly check how the reporter works in real life:
node_modules/protractor/bin/protractor ./test/system/conf.js