jest-sonar-reporter is a custom Jest test results processor designed to convert Jest's JSON output into an XML format consumable by SonarQube. Specifically, it generates reports in Sonar's generic test data format (or a legacy format for older SonarQube versions), enabling seamless integration of Jest test results into SonarQube for quality gate analysis and code quality metrics. The current stable version is 2.0.0, released in late 2020, and the project appears to be actively maintained, with releases primarily driven by new features or breaking changes in Jest or SonarQube itself. A key differentiator is its ability to handle both modern SonarQube generic test data and provide backwards compatibility for SonarQube 5.6.x via a specific configuration flag. All configuration is handled within the `package.json` file, allowing for granular customization of report paths, filenames, indentation, and environment-specific settings, making it flexible for various CI/CD setups.
npm install jest-sonar-reporterVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to configure Jest and `jest-sonar-reporter` in `package.json` to generate SonarQube-compatible test reports and integrate them into a SonarQube analysis.
Migrate to using the `jestSonar.reportPath` and `jestSonar.reportFile` properties within your `package.json` for all report path and filename configurations.
Ensure your Node.js environment is version 8.0.0 or higher. Update Node.js if your current version is older than 8.0.0.
Carefully verify that `sonar.testExecutionReportPaths` (or `sonar.genericcoverage.unitTestReportPaths` for SonarQube 5.6.x) points to the exact XML file generated by `jest-sonar-reporter`.
Add `"sonar56x": true` to your `jestSonar` configuration in `package.json` and update your `sonar-project.properties` file to use `sonar.genericcoverage.unitTestReportPaths` accordingly.
Prepend your test command with `NODE_ENV=yourEnv npm run test` (e.g., `NODE_ENV=test npm run test`) to apply the environment-specific `jestSonar` settings.
Ensure `jest-sonar-reporter` is installed as a dev dependency (`npm i -D jest-sonar-reporter` or `yarn add -D jest-sonar-reporter`) and that your Jest configuration in `package.json` correctly points to the module string `"jest-sonar-reporter"`.
Verify that the `sonar.testExecutionReportPaths` (or `sonar.genericcoverage.unitTestReportPaths`) in `sonar-project.properties` precisely matches the actual output path and filename configured in `jestSonar` within `package.json`. Ensure Jest tests ran successfully and generated the report.
This can sometimes occur with very old SonarQube versions, specific environments, or if there's an issue during report generation. Ensure you are using a recent version of `jest-sonar-reporter` and SonarQube. If using SonarQube 5.6.x, ensure `sonar56x: true` is set, as this might change the output format.
No dependency data recorded yet.