mochawesome vs jest-html-reporter
JavaScript Testing Reporters Comparison
3 Years
mochawesomejest-html-reporterSimilar Packages:
What's JavaScript Testing Reporters?

JavaScript testing reporters are tools that format and present test results in a human-readable way, enhancing the visibility and understanding of test outcomes. They are essential for developers to quickly assess the success or failure of their tests, providing insights into code quality and potential issues. Jest-html-reporter and mochawesome are popular choices, each with unique features that cater to different testing frameworks and reporting needs.

Package Weekly Downloads Trend
Github Stars Ranking
Stat Detail
Package
Downloads
Stars
Size
Issues
Publish
License
mochawesome1,396,947
1,06735.7 kB81-MIT
jest-html-reporter323,529
28142.9 kB12 months agoMIT
Feature Comparison: mochawesome vs jest-html-reporter

Integration

  • mochawesome:

    mochawesome is built to work with Mocha, providing a robust integration that allows for detailed reporting of Mocha test results. It can be easily set up with Mocha's command-line interface and supports various reporters.

  • jest-html-reporter:

    jest-html-reporter is specifically designed to work with Jest, making it easy to integrate into Jest test suites. It leverages Jest's built-in capabilities and allows for straightforward configuration through Jest's configuration file.

Output Format

  • mochawesome:

    mochawesome produces an extensive HTML report that includes not only pass/fail status but also detailed information about each test case, including error messages, stack traces, and even screenshots of failed tests.

  • jest-html-reporter:

    jest-html-reporter generates a clean and simple HTML report that displays test results in a user-friendly format. The report includes pass/fail status, duration, and can be customized to include additional information as needed.

Customization

  • mochawesome:

    mochawesome provides extensive customization options, allowing users to modify the report's layout, style, and content. Users can configure the report to include additional metadata, screenshots, and even videos, making it highly adaptable.

  • jest-html-reporter:

    jest-html-reporter offers basic customization options, allowing users to modify the report's appearance and content through configuration settings. This makes it easy to tailor the reports to fit specific project needs without extensive coding.

Ease of Use

  • mochawesome:

    mochawesome requires a bit more setup compared to jest-html-reporter, but it offers rich features that justify the initial investment in time. It is well-documented, making it easier for developers to get started.

  • jest-html-reporter:

    jest-html-reporter is straightforward to set up and use, especially for developers already familiar with Jest. Its simplicity makes it an excellent choice for teams looking for quick reporting solutions without a steep learning curve.

Community Support

  • mochawesome:

    mochawesome has a strong community and is widely used in the Mocha ecosystem. It has extensive documentation and community-contributed resources, making it easier to troubleshoot issues and find best practices.

  • jest-html-reporter:

    jest-html-reporter has a growing community, benefiting from Jest's popularity. This means that users can find resources, examples, and community support relatively easily.

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

    Choose mochawesome if you are using Mocha as your testing framework and need a comprehensive reporting solution that includes detailed information about test results, including screenshots and video recordings. It is suitable for projects that require extensive reporting features and integration with CI/CD pipelines.

  • jest-html-reporter:

    Choose jest-html-reporter if you are using Jest as your testing framework and require a simple, customizable HTML report that integrates seamlessly with Jest's output. It is ideal for projects where you want to generate visually appealing reports without extensive configuration.

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.