# mocha-sonar-reporter

> Sonar friendly xunit reporter for Mocha

Latest version **0.1.6** (published 2016-07-12) · MIT license · 0 weekly downloads

## Install

```sh
npm install mocha-sonar-reporter
pnpm add mocha-sonar-reporter
yarn add mocha-sonar-reporter
bun add mocha-sonar-reporter
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.6 |
| Published | 2016-07-12 |
| First published | 2014-02-11 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >= 0.10.4 |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 9 |
| Author | Peter Halliday |
| Maintainers | pghalliday |
| Keywords | mocha, sonar, xunit, test |

## Links

- npm: https://www.npmjs.com/package/mocha-sonar-reporter
- Repository: https://github.com/pghalliday/mocha-sonar-reporter
- Issues: https://github.com/pghalliday/mocha-sonar-reporter/issues
- npm.io page: https://npm.io/package/mocha-sonar-reporter

## Dependencies (1)

- [mkdirp](https://npm.io/package/mkdirp.md) ^0.5.0

## Alternatives

- [duck](https://npm.io/package/duck.md) — 4.2M weekly downloads
- [ava](https://npm.io/package/ava.md) — 560.2K weekly downloads
- [storybook-addon-module-mock](https://npm.io/package/storybook-addon-module-mock.md) — 71.7K weekly downloads
- [vest](https://npm.io/package/vest.md) — 50.1K weekly downloads
- [@ethereum-waffle/mock-contract](https://npm.io/package/@ethereum-waffle/mock-contract.md) — 40.0K weekly downloads

## Recent versions

- 0.1.6 (latest) — 2016-07-12
- 0.1.5 — 2016-04-11
- 0.1.4 — 2015-10-19
- 0.1.3 — 2015-07-08
- 0.1.2 — 2014-12-11
- 0.1.1 — 2014-12-08
- 0.1.0 — 2014-02-11

## README

mocha-sonar-reporter
====================

[![Build Status](https://travis-ci.org/pghalliday/mocha-sonar-reporter.png)](https://travis-ci.org/pghalliday/mocha-sonar-reporter)
[![Coverage Status](https://coveralls.io/repos/pghalliday/mocha-sonar-reporter/badge.png)](https://coveralls.io/r/pghalliday/mocha-sonar-reporter)
[![Dependency Status](https://david-dm.org/pghalliday/mocha-sonar-reporter.png?theme=shields.io)](https://david-dm.org/pghalliday/mocha-sonar-reporter)
[![devDependency Status](https://david-dm.org/pghalliday/mocha-sonar-reporter/dev-status.png?theme=shields.io)](https://david-dm.org/pghalliday/mocha-sonar-reporter#info=devDependencies)

`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 &copy; 2015 Peter Halliday  
Licensed under the MIT license.

[![Donate Bitcoins](http://i.imgur.com/b5BZsFH.png)](bitcoin:17LtnRG4WxRLYBWzrBoEKP3F7fZx8vcAsK?amount=0.01&label=grunt-mocha-test)

[17LtnRG4WxRLYBWzrBoEKP3F7fZx8vcAsK](bitcoin:17LtnRG4WxRLYBWzrBoEKP3F7fZx8vcAsK?amount=0.01&label=grunt-mocha-test)

---
_Source: https://npm.io/package/mocha-sonar-reporter · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
