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

junit-xml-mocha-reporter

v1.0.1

Published

A JUnit XML reporter for mocha.

Downloads

161

Readme

junit-xml-mocha-reporter

NPM Version GitHub Release GitHub License

This mocha reporter produces JUnit-style XML test results and allows you to split the same test into different test cases by jira id.

Table of Contents

Installation

 pnpm install junit-xml-mocha-reporter --save-dev
 npm install junit-xml-mocha-reporter --save-dev

Usage

Run mocha with junit-xml-mocha-reporter:

 mocha test --reporter junit-xml-mocha-reporter

This will output a results file at ./results.xml. You may optionally declare an alternate location for results XML file by setting the environment variable MOCHA_FILE or specifying mochaFile in reporterOptions:

 MOCHA_FILE=./path_to_your/file.xml mocha test --reporter junit-xml-mocha-reporter

or

 mocha test --reporter junit-xml-mocha-reporter --reporter-options mochaFile=./path_to_your/file.xml

or

const mocha = new Mocha({
    reporter: 'junit-xml-mocha-reporter',
    reporterOptions: {
        mochaFile: './path_to_your/file-results.xml'
    }
});

Split the same test case by id of jira

You can also add the jira key in the reporterOptions or in environment variables to split the same test into different test cases. This is useful if you want to test different tests in the same test in Cypress without affecting performance. If you want provided more than one jira id you should divide the ids with the , separator. e.g: title one JIRA.KEY.1,JIRA.KEY.2,JIRA.KEY.3

[!IMPORTANT] You shoult put the jira ids in the end of the title. e.g: title one JIRA.KEY.1,JIRA.KEY.2,JIRA.KEY.3.

To do this, enter them using the environment variable:

PROPERTIES=JIRA.KEY mocha test --reporter junit-xml-mocha-reporter

or

const mocha = new Mocha({
    reporter: 'junit-xml-mocha-reporter',
    reporterOptions: {
        jiraId: 'JIRA.KEY'
    }
})

If the test case it's this:

describe("test", () => {
  it("testcase JIRA.KEY.1,JIRA.KEY.2,JIRA.KEY.3", () => {
      expect(2).to.be.greaterThan(1);
    }
  );
});

the result it's this:

<testsuites>
  <testsuite>
    <testcase name="test testcase JIRA.KEY.1" time="0.022" classname="test test JIRA.KEY.1">
    </testcase>
    <testcase name="test testcase JIRA.KEY.2" time="0.022" classname="test test JIRA.KEY.2">
    </testcase>
    <testcase name="test testcase JIRA.KEY.3" time="0.022" classname="test test JIRA.KEY.3">
    </testcase>
  </testsuite>
</testsuites>

Append properties to testsuite

You can also add properties to the report under testsuite. This is useful if you want your CI environment to add extra build props to the report for analytics purposes

<testsuites>
  <testsuite>
    <properties>
      <property name="PROPERTY_ID" value="12345"/>
    </properties>
    <testcase/>
  </testsuite>
</testsuites>

To do so pass them in via env variable:

PROPERTIES=PROPERTY_ID:12345 mocha test --reporter junit-xml-mocha-reporter

or

const mocha = new Mocha({
    reporter: 'junit-xml-mocha-reporter',
    reporterOptions: {
        properties: {
            PROPERTY_ID: 12345
        }
    }
})

Results Report

Results XML filename can contain [hash], e.g. ./path_to_your/results.[hash].xml. [hash] is replaced by MD5 hash of test results XML. This enables support of parallel execution of multiple junit-xml-mocha-reporter's writing test results in separate files. In addition to this these placeholders can also be used:

| placeholder | output | | ------------------- | ------------------------------------------------- | | [testSuitesTitle] | will be replaced by the testSuitesTitle setting | | [rootSuiteTitle] | will be replaced by the rootSuiteTitle setting | | [suiteFilename] | will be replaced by the filename of the spec file | | [suiteName] | will be replaced by the name the first test suite |

In order to display full suite title (including parents) just specify testSuitesTitle option

const mocha = new Mocha({
    reporter: 'junit-xml-mocha-reporter',
    reporterOptions: {
        testSuitesTitle: true,
    }
});

You can also configure the testsuites.name attribute by setting reporterOptions.testSuitesTitle and the root suite's name attribute by setting reporterOptions.rootSuiteTitle.

Configuration options

| Parameter | Default | Effect | | ------------------------------ | ---------------------- | ----------------------------------------------------------------------------------------------------------------------- | | mochaFile | results.xml | Configures the file to write reports to | | jiraId | null | A key to check if testcaase titles contain jira ids with the key provided. | | properties | null | A hash of additional properties to add to each test suite | | rootSuiteTitle | Root Suite | The name for the root suite. (defaults to 'Root Suite') | | testSuitesTitle | Mocha Tests | The name for the testsuites tag (defaults to 'Mocha Tests') |

Debug mode

If you need see the log when it's executed you can provide the DEBUG envionment variable.

DEBUG=true

License

MIT, see LICENSE for details.