mochawesome vs cucumber-html-reporter vs jest-html-reporters
JavaScript Test Reporting Libraries Comparison
1 Year
mochawesomecucumber-html-reporterjest-html-reportersSimilar Packages:
What's JavaScript Test Reporting Libraries?

JavaScript test reporting libraries are tools designed to generate visually appealing and informative reports from test results, enhancing the visibility and understanding of test outcomes. They provide developers and teams with insights into the performance and reliability of their code through detailed reports, which can include metrics like pass/fail rates, execution times, and error messages. These libraries are essential for maintaining high code quality and facilitating continuous integration and delivery processes by making it easier to analyze test results and identify areas for improvement.

Package Weekly Downloads Trend
Github Stars Ranking
Stat Detail
Package
Downloads
Stars
Size
Issues
Publish
License
mochawesome1,398,9591,06935.7 kB81-MIT
cucumber-html-reporter344,50823512.5 MB916 months agoMIT
jest-html-reporters224,1155273.18 MB19a year agoMIT
Feature Comparison: mochawesome vs cucumber-html-reporter vs jest-html-reporters

Integration

  • mochawesome:

    Mochawesome is built to work with Mocha, providing a robust reporting solution that captures all test results in a structured format. It can be easily integrated into existing Mocha test suites, making it a versatile choice for teams already using Mocha.

  • cucumber-html-reporter:

    Cucumber HTML Reporter integrates seamlessly with Cucumber, allowing it to generate reports directly from Cucumber's output. This makes it highly effective for teams practicing BDD, as it captures the essence of user stories and scenarios in the reports.

  • jest-html-reporters:

    Jest HTML Reporters is designed to work specifically with Jest, leveraging its built-in features to produce reports. This tight integration ensures that the reports reflect the latest test results accurately and efficiently, making it a preferred choice for Jest users.

Report Format

  • mochawesome:

    Mochawesome generates both JSON and HTML reports, providing a comprehensive view of test results. The HTML report is visually appealing and includes detailed information such as test duration, status, and error messages, making it easier to analyze failures.

  • cucumber-html-reporter:

    The reports generated by Cucumber HTML Reporter are designed to be user-friendly, presenting scenarios and steps in a clear, narrative format. This format is particularly beneficial for stakeholders who may not be familiar with technical jargon, as it focuses on the behavior of the application rather than the implementation details.

  • jest-html-reporters:

    Jest HTML Reporters produces customizable HTML reports that can include snapshots and additional information, allowing developers to tailor the output to their needs. This flexibility is advantageous for teams that require specific metrics or formats in their reports.

Customization

  • mochawesome:

    Mochawesome provides customization options for both the JSON and HTML outputs, allowing teams to configure the report to include specific details or change the overall appearance. This flexibility is beneficial for teams that want to ensure their reports meet particular standards.

  • cucumber-html-reporter:

    Cucumber HTML Reporter allows for some level of customization in the report's appearance, enabling teams to align the report with their branding or specific requirements. However, the customization options are somewhat limited compared to others.

  • jest-html-reporters:

    Jest HTML Reporters offers extensive customization options, allowing developers to modify the report's layout, style, and content. This makes it suitable for teams that need specific reporting formats or additional metadata included in their reports.

Ease of Use

  • mochawesome:

    Mochawesome is also user-friendly, with a simple setup process for Mocha users. The dual output of JSON and HTML reports provides flexibility, making it easy for teams to choose their preferred format.

  • cucumber-html-reporter:

    Cucumber HTML Reporter is relatively easy to set up and use, especially for teams already familiar with Cucumber. The simplicity of generating reports from existing test results makes it a straightforward choice for BDD teams.

  • jest-html-reporters:

    Jest HTML Reporters is designed to be easy to integrate with Jest, requiring minimal configuration. Its user-friendly setup process makes it accessible for developers of all skill levels, ensuring quick adoption within teams.

Community Support

  • mochawesome:

    Mochawesome has a dedicated user base and good community support, with resources available for troubleshooting and enhancing the reporting process. The active community contributes to the library's ongoing development and improvement.

  • cucumber-html-reporter:

    Cucumber HTML Reporter benefits from the strong community surrounding Cucumber, which provides ample resources, documentation, and support for users. This community-driven approach helps teams troubleshoot issues and share best practices.

  • jest-html-reporters:

    Jest HTML Reporters is supported by the large Jest community, ensuring that developers have access to extensive documentation, tutorials, and community support. This makes it easier for teams to find solutions and optimize their testing processes.

How to Choose: mochawesome vs cucumber-html-reporter vs jest-html-reporters
  • mochawesome:

    Opt for Mochawesome if you are using Mocha as your testing framework and need a comprehensive report that combines both JSON and HTML outputs. It is particularly useful for projects that require detailed reporting of test results, including screenshots and video support, enhancing the debugging process.

  • cucumber-html-reporter:

    Choose Cucumber HTML Reporter if you are using Cucumber for behavior-driven development (BDD) and need a report that aligns with BDD principles, showcasing scenarios and steps in a clear format. It is ideal for teams that prioritize collaboration and communication with stakeholders through easily understandable reports.

  • jest-html-reporters:

    Select Jest HTML Reporters if you are using Jest as your testing framework and want a seamless integration that provides customizable HTML reports. This package is suitable for projects that require detailed reports with the ability to include snapshots and additional metadata, making it perfect for unit and integration testing.

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.