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 format.
This project is inspired by Michael Allen's jest-junit-reporter
project.
Installation
Using npm:
$ npm i -D jest-sonar-reporter
Using yarn:
$ yarn add -D jest-sonar-reporter
Configuration
Configure Jest in your package.json
to use jest-sonar-reporter
as a custom results processor.
{
"jest": {
"testResultsProcessor": "jest-sonar-reporter"
}
}
Configure Sonar to import the test results. Add the sonar.testExecutionReportPaths
property to your
sonar-project.properties
file.
sonar.testExecutionReportPaths=test-report.xml
The custom reporter generates the test-report.xml
file.
To specify a different location set the TEST_REPORT_PATH
environment variable.
Use cross-env
to specify the report path in your package.json
.
{
"scripts": {
"test": "cross-env TEST_REPORT_PATH=reports jest"
}
}
Or use env-cmd
to specify a test environment configuration.
- Add the environment variable to your
.env-cmdrc
file.
{
"test": {
"TEST_REPORT_PATH": "reports"
}
}
- Configure a test script in your
package.json
{
"scripts": {
"test": "env-cmd test jest"
}
}
Usage
- Run Jest to execute your tests.
Using npm:
$ npm run test
Using yarn:
$ yarn run test
- Run sonar-scanner to import the test results.
$ sonar-scanner
Licence
This project uses the MIT licence.