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

@glartek/mocha-sonar-reporter

v0.1.7

Published

Sonar friendly xunit reporter for Mocha

Downloads

3

Readme

mocha-sonar-reporter

Build Status Coverage Status Dependency Status devDependency Status

Sonar friendly xunit reporter.

This is a modification of the existing xunit reporter that ships with Mocha. There are 2 problems that become apparent when standard xunit reports are submitted to Sonar using the sonar javascript plugin.

  • Sonar will reject reports that have a classname that mirrors a source file, eg. if you have a source file called MyClass.js then you cannot have a test with a classname of MyClass
  • Sonar interprets the classname field as a filename resulting in hard to read test reports in the Sonar UI (this is probably also the cause of the first issue)

This reporter will generate xunit output that uses the concatenation of the suite and test titles as the test name and set the classname to:

  • if testdir is defined in config, the test file relative path
  • else a configurable constant so that name collisions can be avoided. If no classname is configured it will default to Test.

Usage

Install and save to your devDependencies

npm install --save-dev mocha-sonar-reporter

Configure the classname in package.json (optional)

  ...
  "config": {
    "mocha-sonar-reporter": {
      "classname": "Test"
    }
  },
  ...

Configure the testdir in package.json (optional)

  ...
  "config": {
    "mocha-sonar-reporter": {
      "testdir": "tests",
      // Optionally configure a suffix for the extracted class names.
      // It has been reported that some versions of the sonar javascript
      // plugin require class names to have a `.js` suffix
      "classnameSuffix": ".js"
    }
  },
  ...

Configure the outputfile in package.json, to generate data in file instead of stdout (optional)

  ...
  "config": {
    "mocha-sonar-reporter": {
      "outputfile": "test/TEST-all.xml"
    }
  },
  ...

Add the following to your /sonar-project.properties file

sonar.javascript.jstestdriver.reportsPath=reports

Specify the mocha-sonar-reporter when running mocha

mocha -R mocha-sonar-reporter

NB. feel free to change paths and file names above ;)

NNB. Although not documented here, you may also like to use Grunt and the grunt-mocha-test plugin to do this and get coverage data, etc

A note on use outside of npm

The options for the reporter are added to package.json. This means that they are only loaded if mocha is run via npm (eg. via npm test). If you wish to use the reporter without npm then the options can still be specified in environment variables using the naming conventions that npm uses internally. ie:

npm_package_config_mocha_sonar_reporter_outputfile
npm_package_config_mocha_sonar_reporter_classname
npm_package_config_mocha_sonar_reporter_testdir
npm_package_config_mocha_sonar_reporter_classnameSuffix

Contributing

Add tests for changes and run

npm test

LICENSE

Copyright © 2015 Peter Halliday
Licensed under the MIT license.

Donate Bitcoins

17LtnRG4WxRLYBWzrBoEKP3F7fZx8vcAsK