Skip to content
Merge several Mochawesome JSON reports
JavaScript
Branch: master
Clone or download
eltonlauhk01 and Antontelesh fix(merge): handle empty reports
* fix: results array contains false

* chore: add test data

* chore: apply filter in collectReportSuites

fixes: #17
Latest commit 42b2464 Jun 12, 2019

README.md

mochawesome-merge

CircleCI codecov semantic-release

Merge several Mochawesome JSON reports

Installation

via yarn:

$ yarn add mochawesome-merge --dev

via npm:

$ npm install mochawesome-merge --save-dev

Usage

const { merge } = require('mochawesome-merge')

// See Options below
const options = {
  reportDir: 'report',
}
merge(options).then(report => {
  console.log(report)
})

CLI

$ mochawesome-merge --reportDir [directory] > output.json

Options

  • reportDir (optional) — source mochawesome JSON reports directory. Defaults to mochawesome-report.

Cypress

The main motivation to create this library was to be able to use mochawesome together with Cypress.

Since the version 3.0.0, Cypress runs every spec separately, which leads to generating multiple mochawesome reports, one for each spec. mochawesome-merge can be used to merge these reports and then generate one HTML report for all your cypress tests.

First, configure cypress.json:

{
  // use mochawesome reporter as usually
  "reporter": "mochawesome",
  "reporterOptions": {
    // disable overwrite to generate many JSON reports
    "overwrite": false,
    // do not generate intermediate HTML reports
    "html": false,
    // generate intermediate JSON reports
    "json": true
  }
}

Then, write your custom script to run cypress together with mochawesome-merge:

const cypress = require('cypress')
const marge = require('mochawesome-report-generator')
const { merge } = require('mochawesome-merge')

cypress.run().then(
  () => {
    generateReport()
  },
  error => {
    generateReport()
    console.error(error)
    process.exit(1)
  }
)

function generateReport(options) {
  return merge(options).then(report => marge.create(report, options))
}

Alternatively, you can use CLI to merge JSON reports and generate HTML report. For example, an AWS CodeBuild buildspec.yml file might look something like this:

phases:
  install:
    commands:
      - yarn install
  build:
    commands:
      - yarn cypress run
  post_build:
    commands:
      - yarn mochawesome-merge > mochawesome.json
      - yarn marge mochawesome.json
You can’t perform that action at this time.