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 🙏

© 2026 – Pkg Stats / Ryan Hefner

mocha-xunit-reporter

v2.3.0

Published

A Mocha xunit reporter

Downloads

21,945

Readme

mocha-xunit-reporter

A Mocha xunit reporter. Produces XUnit-style XML test results. Adapted from and Inspired by mocha-junit-reporter.

Installation

$ npm install mocha-xunit-reporter --save-dev

or as a global module

$ npm install -g mocha-xunit-reporter

Usage

Run mocha with mocha-xunit-reporter:

$ mocha test --reporter mocha-xunit-reporter

or, in .mocharc.json (or the exported object from .mocharc.js):

{
    "reporter": "mocha-xunit-reporter",
    ...
}

Output

Format

The generated test results file conforms to XUnit's XML format.

failure element

In case of an error or failure during a test run, a failure element will be included as a child element with its corresponding test element. This element will contain information about the failed test.

<failure exception-type="Error">
  <message><![CDATA[This test threw an error]]></message>
  <stack-trace><![CDATA[Error: testing123
at Context.<anonymous> (example.spec.ts-1:1:1)]]></stack-trace>
</failure>

More information about the failure element.

Configuration

Configuration options (all optional):

| Parameter | Type | Effect | | --------- | ---- | ------ | | mochaFile | string | configures the file to write reports to | | includePending | boolean | if set to a truthy value pending tests will be included in the report | | toConsole | boolean | if set to a truthy value the produced XML will be logged to the console | | assemblyName | string | the name for the assembly element. (defaults to 'Mocha Tests') | | addTags | boolean | if set to a truthy value will parse the test title for tags |

Specifying Reporter Options

In general, configuration options may be specified any of the following ways. There may be additional ways to specify individual options (see below).

  • Command-line reporter options; e.g.

    $ mocha test --reporter mocha-xunit-reporter --reporter-options mochaFile=./path_to_your/file.xml
  • Mocha constructor reporterOptions; e.g.

    var mocha = new Mocha({
        reporter: 'mocha-xunit-reporter',
        reporterOptions: {
            mochaFile: './path_to_your/file.xml'
        }
    });
  • .mocharc.js/.mocharc.json:

    {
        "reporter": "mocha-xunit-reporter",
        "reporterOptions": {
            "mochaFile": "./path_to_your/file.xml"
        }
    }

Details about some configuration options are included below.


mochaFile or MOCHA_FILE

The generated test results file conforms to XUnit's XML format.

Default location: ./test-results.xml

This option may additionally be specified by the environment variable MOCHA_FILE:

$ MOCHA_FILE=./path_to_your/file.xml mocha test --reporter mocha-xunit-reporter

Magic filename

If the string [hash] is present in the received file path, it will be replaced with an MD5 hash of the output XML.

For example, for this received file path:

test-results.[hash].xml

...the output file might be test-results.320ae2121e02b35c30dc16b8b7a2215e.xml

addTags

If set to true, will parse the test title for tags in format @tagName=tagValue and will add them as attribute of the test XML element. It will also clean the outputted tags from the test name XML attribute.

Example behavior:

Consider a test with this title:

'test should behave like so @aid=EPM-DP-C1234 @sid=EPM-1234 @type=Integration'

The outputted test element will look as follows:

<test name="test should behave like so" aid="EPM-DP-C1234" sid="EPM-1234" type="Integration" />