mochawesome vs mocha-allure-reporter vs jest-allure
JavaScript Testing Frameworks and Reporting Tools Comparison
1 Year
mochawesomemocha-allure-reporterjest-allureSimilar Packages:
What's JavaScript Testing Frameworks and Reporting Tools?

These packages are designed to enhance the testing experience in JavaScript applications, particularly in Node.js environments. They provide various functionalities for running tests, generating reports, and integrating with CI/CD pipelines. The main goal of these tools is to improve the visibility and maintainability of test results, making it easier for developers to understand the outcomes of their tests and the overall health of their codebase. Each package has its unique features and reporting capabilities, catering to different testing needs and preferences.

Package Weekly Downloads Trend
Github Stars Ranking
Stat Detail
Package
Downloads
Stars
Size
Issues
Publish
License
mochawesome1,330,5121,06935.7 kB81-MIT
mocha-allure-reporter21,9574526.1 kB0-Apache-2.0
jest-allure17,70311522.8 kB35-MIT
Feature Comparison: mochawesome vs mocha-allure-reporter vs jest-allure

Integration

  • mochawesome:

    mochawesome is designed specifically for Mocha, providing a standalone reporting solution that generates HTML and JSON reports. It can be easily integrated into any Mocha test suite without altering the test logic.

  • mocha-allure-reporter:

    mocha-allure-reporter works with Mocha, providing a straightforward way to generate Allure reports. It requires minimal setup and can be easily included in existing Mocha test suites, making it a convenient choice for Mocha users.

  • jest-allure:

    jest-allure integrates directly with Jest, allowing you to leverage Jest's powerful testing capabilities while enhancing your reports with Allure's rich features. This integration ensures that you can easily generate Allure reports without additional configuration steps.

Report Format

  • mochawesome:

    mochawesome generates visually appealing HTML reports that are easy to read and navigate. The reports include detailed information about each test, including duration, status, and error messages, making it user-friendly for developers.

  • mocha-allure-reporter:

    mocha-allure-reporter also generates Allure reports, offering similar benefits in terms of structure and detail. It allows for the inclusion of additional information like screenshots and logs, enhancing the context of test failures.

  • jest-allure:

    jest-allure produces Allure reports, which are known for their structured and detailed presentation of test results. These reports include features like test history, attachments, and a clear overview of passed and failed tests, making it easy to analyze results.

Customization

  • mochawesome:

    mochawesome offers customization options for report generation, including the ability to specify report file names, output directories, and even the inclusion of custom CSS for styling the reports.

  • mocha-allure-reporter:

    mocha-allure-reporter provides options for customizing the report output, such as adding metadata and custom attributes to tests, which can be useful for tracking specific test scenarios or environments.

  • jest-allure:

    jest-allure allows for some customization in report generation, including the ability to add custom steps and attachments to your tests. This flexibility can help tailor reports to meet specific project needs.

Ease of Use

  • mochawesome:

    mochawesome is user-friendly and provides a simple command-line interface for generating reports. Its HTML output is easy to navigate, making it a great choice for teams that prioritize usability.

  • mocha-allure-reporter:

    mocha-allure-reporter is straightforward to implement within existing Mocha test suites. It requires minimal configuration, making it accessible for teams looking to enhance their reporting without significant changes to their testing setup.

  • jest-allure:

    jest-allure is designed to be easy to set up and use, especially for those already familiar with Jest. Its integration with Jest's existing features means that developers can quickly start generating reports with minimal overhead.

Community and Support

  • mochawesome:

    mochawesome has a dedicated user base and active community, offering support and updates. Its popularity ensures that developers can find tutorials, documentation, and community-driven enhancements.

  • mocha-allure-reporter:

    mocha-allure-reporter is supported by the Mocha community, which is well-established and provides a wealth of resources for troubleshooting and best practices.

  • jest-allure:

    jest-allure benefits from the strong community support surrounding Jest, which is one of the most popular testing frameworks in the JavaScript ecosystem. This ensures that users can find help and resources easily.

How to Choose: mochawesome vs mocha-allure-reporter vs jest-allure
  • mochawesome:

    Opt for mochawesome if you want a visually appealing and detailed HTML report for your Mocha tests. Mochawesome provides a rich user interface for viewing test results and is particularly useful for teams that value aesthetics and usability in their reporting.

  • mocha-allure-reporter:

    Select mocha-allure-reporter if you are using Mocha as your testing framework and require detailed reporting capabilities. This package is ideal for teams already invested in Mocha's ecosystem and looking for comprehensive test reports that can be easily integrated into CI/CD workflows.

  • jest-allure:

    Choose jest-allure if you are using Jest as your testing framework and need a seamless integration for generating Allure reports. Jest is known for its speed and ease of use, making it a great choice for projects that prioritize developer experience and rapid feedback.

README for mochawesome

mochawesome

npm Node.js CI Gitter

Mochawesome is a custom reporter for use with the Javascript testing framework, mocha. It runs on Node.js (>=10) and works in conjunction with mochawesome-report-generator to generate a standalone HTML/CSS report to help visualize your test runs.

Features

Mochawesome Report
  • Simple, clean, and modern design
  • Beautiful charts (via ChartJS)
  • Support for test and suite nesting
  • Displays before and after hooks
  • Review test code inline
  • Stack trace for failed tests
  • Support for adding context information to tests
  • Filters to display only the tests you want
  • Responsive and mobile-friendly
  • Offline viewing
  • Supports parallel mode

Usage

  1. Add Mochawesome to your project:

npm install --save-dev mochawesome

  1. Tell mocha to use the Mochawesome reporter:

mocha testfile.js --reporter mochawesome

  1. If using mocha programatically:
var mocha = new Mocha({
  reporter: 'mochawesome',
});

Parallel Mode

Since mocha@8 test files can be run in parallel using the --parallel flag. In order for mochawesome to work properly it needs to be registered as a hook.

mocha tests --reporter mochawesome --require mochawesome/register

Output

Mochawesome generates the following inside your project directory:

mochawesome-report/
├── assets
│   ├── app.css
│   ├── app.js
│   ├── MaterialIcons-Regular.woff
│   ├── MaterialIcons-Regular.woff2
│   ├── roboto-light-webfont.woff
│   ├── roboto-light-webfont.woff2
│   ├── roboto-medium-webfont.woff
│   ├── roboto-medium-webfont.woff2
│   ├── roboto-regular-webfont.woff
│   └── roboto-regular-webfont.woff2
├── mochawesome.html
└── mochawesome.json

The two main files to be aware of are:

mochawesome.html - The rendered report file

mochawesome.json - The raw json output used to render the report

Options

Options can be passed to the reporter in two ways.

Environment variables

The reporter will try to read environment variables that begin with MOCHAWESOME_.

$ export MOCHAWESOME_REPORTFILENAME=customReportFilename

Note that environment variables must be in uppercase.

Mocha reporter-options

You can pass comma-separated options to the reporter via mocha's --reporter-options flag. Options passed this way will take precedence over environment variables.

$ mocha test.js --reporter mochawesome --reporter-options reportDir=customReportDir,reportFilename=customReportFilename

Alternately, reporter-options can be passed in programatically:

var mocha = new Mocha({
  reporter: 'mochawesome',
  reporterOptions: {
    reportFilename: 'customReportFilename',
    quiet: true,
  },
});

Available Options

The options below are specific to the reporter. For a list of all available options see mochawesome-report-generator options.

| Option Name | Type | Default | Description | | :---------------- | :------ | :---------- | :-------------------------------------------------------------------------------------------------------------------------------- | | quiet | boolean | false | Silence console messages | | reportFilename | string | mochawesome | Filename of saved report (html and json)
See notes for available token replacements. | | html | boolean | true | Save the HTML output for the test run | | json | boolean | true | Save the JSON output for the test run | | consoleReporter | string | spec | Name of mocha reporter to use for console output, or none to disable console report output entirely |

reportFilename replacement tokens

Using the following tokens it is possible to dynamically alter the filename of the generated report.

  • [name] will be replaced with the spec filename when possible.
  • [status] will be replaced with the status (pass/fail) of the test run.
  • [datetime] will be replaced with a timestamp. The format can be - specified using the timestamp option.

For example, given the spec cypress/integration/sample.spec.js and the following config:

{
  reporter: "mochawesome",
  reporterOptions: {
    reportFilename: "[status]_[datetime]-[name]-report",
    timestamp: "longDate"
  }
}

The resulting report file will be named pass_February_23_2022-sample-report.html

Note: The [name] replacement only occurs when mocha is running one spec file per process and outputting a separate report for each spec. The most common use-case is with Cypress.

Adding Test Context

Mochawesome ships with an addContext helper method that can be used to associate additional information with a test. This information will then be displayed inside the report.

Please note: arrow functions will not work with addContext. See the example.

addContext(testObj, context)

| param | type | description | | :------ | :------------- | :---------------------------------- | | testObj | object | The test object | | context | string|object | The context to be added to the test |

Context as a string

Simple strings will be displayed as is. If you pass a URL, the reporter will attempt to turn it into a link. If the URL links to an image or video, it will be shown inline.

Context as an object

Context passed as an object must adhere to the following shape:

{
  title: 'some title'; // must be a string
  value: {
  } // can be anything
}

Example

Be sure to use ES5 functions and not ES6 arrow functions when using addContext to ensure this references the test object.

const addContext = require('mochawesome/addContext');

describe('test suite', function () {
  it('should add context', function () {
    // context can be a simple string
    addContext(this, 'simple string');

    // context can be a url and the report will create a link
    addContext(this, 'http://www.url.com/pathname');

    // context can be an image url and the report will show it inline
    addContext(this, 'http://www.url.com/screenshot-maybe.jpg');

    // context can be an object with title and value properties
    addContext(this, {
      title: 'expected output',
      value: {
        a: 1,
        b: '2',
        c: 'd',
      },
    });
  });
});

It is also possible to use addContext from within a beforeEach or afterEach test hook.

describe('test suite', () => {
  beforeEach(function () {
    addContext(this, 'some context');
  });

  afterEach(function () {
    addContext(this, {
      title: 'afterEach context',
      value: { a: 1 },
    });
  });

  it('should display with beforeEach and afterEach context', () => {
    // assert something
  });
});

Typescript

This project does not maintain its own type definitions, however they are available on npm from DefinitelyTyped.

$ npm install --save-dev @types/mochawesome

Related

mochawesome-report-generator

License

mochawesome is MIT licensed.