# jest-sonar-reporter

> A Sonar test reporter for Jest.

Latest version **2.0.0** (published 2018-03-25) · MIT license · 0 weekly downloads

## Install

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

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.0 |
| Published | 2018-03-25 |
| First published | 2017-03-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=8.0.0 |
| Dependencies | 1 |
| Unpacked size | 9.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 68 |
| Author | Christian Wlatschiha |
| Maintainers | 3dmind |
| Keywords | sonar, sonarqube, jest, results, processor |

## Links

- npm: https://www.npmjs.com/package/jest-sonar-reporter
- Repository: https://github.com/3dmind/jest-sonar-reporter
- Homepage: https://github.com/3dmind/jest-sonar-reporter#readme
- Issues: https://github.com/3dmind/jest-sonar-reporter/issues
- npm.io page: https://npm.io/package/jest-sonar-reporter

## Dependencies (1)

- [xml](https://npm.io/package/xml.md) ^1.0.1

## Recent versions

- 2.0.0 (latest) — 2018-03-25
- 1.3.0 — 2017-08-26
- 1.2.0 — 2017-07-01
- 1.1.1 — 2017-04-15
- 1.1.0 — 2017-03-19

## README

# jest-sonar-reporter

[![Build Status](https://travis-ci.org/3dmind/jest-sonar-reporter.svg?branch=master)](https://travis-ci.org/3dmind/jest-sonar-reporter)
[![Quality Gate](https://sonarcloud.io/api/project_badges/measure?project=jest-sonar-reporter&metric=alert_status)](https://sonarcloud.io/dashboard?id=jest-sonar-reporter)

jest-sonar-reporter is a custom results processor for Jest.
The processor converts Jest's output into Sonar's
[generic test data](https://docs.sonarqube.org/display/SONAR/Generic+Test+Data) format.

## Installation

Using npm:

```bash
$ npm i -D jest-sonar-reporter
```

Using yarn:

```bash
$ yarn add -D jest-sonar-reporter
```

## Configuration

Configure Jest in your `package.json` to use `jest-sonar-reporter` as a custom results processor.

```json
{
  "jest": {
    "testResultsProcessor": "jest-sonar-reporter"
  }
}
```

Configure Sonar to import the test results. Add the `sonar.testExecutionReportPaths` property to your
`sonar-project.properties` file.

```properties
sonar.testExecutionReportPaths=test-report.xml
```

## Customization

To customize the reporter you can use `package.json` to store the configuration.

Create a `jestSonar` entry like this:

```json
{
  "jestSonar": {}
}
```

You can customize the following options:
- `reportPath` This will specify the path to put the report in.
- `reportFile` This will specify the file name of the report.
- `indent` This will specify the indentation to format the report.

```json
{
  "jestSonar": {
    "reportPath": "reports",
    "reportFile": "test-reporter.xml",
    "indent": 4
  }
}
```

> Important: Don't forget to update `sonar.testExecutionReportPaths` when you use a custom path and file name.

### Support for Sonarqube 5.6.x

Sonarqube 5.6.x does not support [Generic Test Data](https://docs.sonarqube.org/display/SONAR/Generic+Test+Data) however it has a [Generic Test Coverage plugin](https://docs.sonarqube.org/display/PLUG/Generic+Test+Coverage) which offers similar functionality.

If you have the plugin installed on Sonarqube, you can configure this reporter to produce files in supported format.

```json
{
  "jestSonar": {
    "sonar56x": true
  }
}
```

Configure Sonar to import the test results. Add the `sonar.genericcoverage.unitTestReportPaths` property to your
`sonar-project.properties` file.

```properties
sonar.genericcoverage.unitTestReportPaths=test-report.xml
```

### Support for different configuration environments

To support different environments add the `env` property to the configuration and overwrite the value of the option you want to modify for the specific environment.
You can overwrite the following configuration options: `reportPath`, `reportFile`, `indent`, `sonar56x`

For example: Overwrite the path were the report will be stored.
```json
{
  "jestSonar": {
    "reportPath": "reports",
    "reportFile": "test-reporter.xml",
    "indent": 4,
    "env": {
      "test": {
        "reportPath": "reports-test"
      }
    }
  }
}
``` 

Use the `NODE_ENV` variable to activate the environment specific configuration.
```shell
NODE_ENV=test npm run test
``` 

## Usage

1. Run Jest to execute your tests.

Using npm:

```bash
$ npm run test
```

Using yarn:

```bash
$ yarn run test
```

2. Run sonar-scanner to import the test results.

```bash
$ sonar-scanner
```

## Licence

This project uses the [MIT](LICENSE) licence.

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