Commit 3da63e01 authored by Mathis Goichon's avatar Mathis Goichon
Browse files

docs: improve jest documentation

parent ab797c25
Loading
Loading
Loading
Loading
+37 −14
Original line number Diff line number Diff line
@@ -69,11 +69,13 @@ order to [integrate your unit tests results to GitLab](https://docs.gitlab.com/e

##### Coverage

For coverage, Jest comes with in-built **Istanbul** package. So no need for extra dependency.
For coverage, Jest comes built-in with **Istanbul** package. So no need for extra dependency.

```js
"jest": {
...
    "coverageDirectory": './reports',
...
},
```

@@ -91,34 +93,55 @@ Then update your `jest.config.js` or `package.json` as follows:

```js
"jest": {
  "reporters": [ "default", "jest-junit" ]
},
"jest-junit": {
...
    "reporters": [
        "default",
        [
            "jest-junit",
            {
                "outputDirectory": "reports",
  "outputName": "unit_test_report.xml"
                "outputName": "junit_test_report.xml"
            }
        ]
    ]
...
},
```

##### Sonar report

By default Jest doesn't generate any test report supported by Sonar. To do so you need to use the [jest-sonar-reporter](https://www.npmjs.com/package/jest-sonar-reporter) package.
By default Jest doesn't generate any test report supported by Sonar. To do so you need to use the [jest-sonar](https://www.npmjs.com/package/jest-sonar) package.

Add the package as a development dependency:

```bash
npm install --save-dev jest-sonar-reporter
npm install --save-dev jest-sonar
```

Then update your `jest.config.js` or `package.json` as follows:

```js
"jest": {
  "testResultsProcessor": "jest-sonar-reporter"
},
"jestSonar": {
  "reportPath": "reports",
  "reportFile": "sonar_test_report.xml"
...
    "reporters": [
        "default",
        [
            "jest-junit",
            {
                "outputDirectory": "reports",
                "outputName": "junit_test_report.xml"
            }
        ],
        [
            "jest-sonar",
            {
                "outputDirectory": "reports",
                "outputName": "sonar_test_report.xml"
            }
        ]
    ],
...
},
```

#### Unit testing with Mocha