anthem-jest-sonar-reporter v2.0.4
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.
Installation
Using npm:
$ npm i -D jest-sonar-reporterUsing yarn:
$ yarn add -D jest-sonar-reporterConfiguration
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.xmlCustomization
To customize the reporter you can use package.json to store the configuration.
Create a jestSonar entry like this:
{
"jestSonar": {}
}You can customize the following options:
reportPathThis will specify the path to put the report in.reportFileThis will specify the file name of the report.indentThis will specify the indentation to format the report.
{
"jestSonar": {
"reportPath": "reports",
"reportFile": "test-reporter.xml",
"indent": 4
}
}Important: Don't forget to update
sonar.testExecutionReportPathswhen you use a custom path and file name.
Support for Sonarqube 5.6.x
Sonarqube 5.6.x does not support Generic Test Data however it has a Generic Test Coverage plugin which offers similar functionality.
If you have the plugin installed on Sonarqube, you can configure this reporter to produce files in supported format.
{
"jestSonar": {
"sonar56x": true
}
}Configure Sonar to import the test results. Add the sonar.genericcoverage.unitTestReportPaths property to your
sonar-project.properties file.
sonar.genericcoverage.unitTestReportPaths=test-report.xmlSupport 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.
{
"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.
NODE_ENV=test npm run testUsage
- Run Jest to execute your tests.
Using npm:
$ npm run testUsing yarn:
$ yarn run test- Run sonar-scanner to import the test results.
$ sonar-scannerLicence
This project uses the MIT licence.