npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

mochawesome-merge

v4.3.0

Published

Merge several Mochawesome JSON reports

Downloads

3,938,943

Readme

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

Examples

JavaScript API

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

// See Params section below
const options = {
  files: [
    './report/*.json',

    // you can specify more files or globs if necessary:
    './mochawesome-report/*.json',
  ],
}

merge(options).then(report => {
  console.log(report)
})

CLI

$ npx mochawesome-merge ./report/*.json -o output.json

or legacy usage

$ npx mochawesome-merge ./report/*.json > output.json

You can specify as many paths as you wish:

$ npx mochawesome-merge ./report/*.json ./mochawesome-report/*.json -o output.json

You can also use a named option for the files like so:

$ npx mochawesome-merge -f ./report/*.json ./mochawesome-report/*.json -o output.json

Params

  • files: list of source report file paths. Can include glob patterns.
  • Aliases: -f | --files or first positional argument
  • Defaults to ["./mochawesome-report/mochawesome*.json"].

  • output: a file path to the bundled results. Should be a json file
  • Aliases: -o | --output
  • Defaults to stdout.

Migration to v4

Version 4 has come with a breaking change — it no more accepts params like reportDir or rootDir. Instead, it now accepts a list of file paths or glob patterns to source report files. If you are migrating to version 4 you likely have to change your params accordignly.

JavaScript API

Let's say you have a bunch of reports that you want to merge under ./mochawesome-report directory. Then you're probably using mochawesome-merge like this:

merge({
  reportDir: "mochawesome-report",
});

After switching to version 4 you need to rename reportDir param to files and change the value to point to your files rather than the directory:

merge({
-  reportDir: "mochawesome-report",
+  files: ["./mochawesome-report/*.json"],
})

CLI

After upgrading to version 4 all you need is to remove the --reportDir option and instead specify a glob pattern or several ones if necessary, separating each one with a space:

- npx mochawesome-merge --reportDir mochawesome-report > mochawesome.json
+ npx mochawesome-merge ./mochawesome-report/*.json > mochawesome.json

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