Registry / testing / jest-sonar-reporter

jest-sonar-reporter

JSON →
library2.0.0jsnpmunverified

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-reporter
INSTALL
IMPORT
SIG · JEST-SONAR-REPORTE
J
jest-sonar-reporter
testingjavascriptv2.0.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

jest-sonar-reporter
{ "jest": { "testResultsProcessor": "jest-sonar-reporter" } }
import jestSonarReporter from 'jest-sonar-reporter'
This package is a Jest results processor, not a library imported directly into user code. It is configured as a string in your `package.json` Jest settings.
jestSonar
{ "jestSonar": { "reportPath": "reports" } }
{ "config": { "jestSonar": { ... } } }
The `jestSonar` object is a top-level property in `package.json` for custom configuration options like report paths, filenames, and SonarQube version compatibility.
env
{ "jestSonar": { "env": { "test": { "reportPath": "reports-test" } } } }
{ "jestSonar": { "test": { "reportPath": "reports-test" } } }
Environment-specific configurations are nested under the `env` property within `jestSonar` and activated by the `NODE_ENV` environment variable.

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.

{ "name": "my-jest-project", "version": "1.0.0", "scripts": { "test": "jest --passWithNoTests" }, "devDependencies": { "jest": "^29.0.0", "jest-sonar-reporter": "^2.0.0" }, "jest": { "testResultsProcessor": "jest-sonar-reporter" }, "jestSonar": { "reportPath": "./test-reports", "reportFile": "sonar-report.xml", "indent": 4 } } // Then, in your terminal: // npm install // npm run test // // And for SonarQube, create a sonar-project.properties: // sonar.projectKey=my-jest-project // sonar.sources=src // sonar.tests=src // sonar.javascript.lcov.reportPaths=coverage/lcov.info // sonar.testExecutionReportPaths=test-reports/sonar-report.xml // // And run the scanner: // sonar-scanner
Debug
Known issues
breakingThe `TEST_REPORT_PATH` environment variable for configuring the report output path was removed.
fix
Migrate to using the `jestSonar.reportPath` and `jestSonar.reportFile` properties within your `package.json` for all report path and filename configurations.
affects: >=2.0.0
breakingSupport for Node.js version 4 has been dropped, requiring a more modern Node.js runtime.
fix
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.
affects: >=2.0.0
gotchaThe `sonar.testExecutionReportPaths` property in your `sonar-project.properties` file must precisely match the actual output path and filename configured in `jestSonar.reportPath` and `jestSonar.reportFile` within your `package.json`.
fix
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`.
affects: >=1.1.0
gotchaTo enable compatibility with SonarQube 5.6.x, you must set `jestSonar.sonar56x: true` in your `package.json` and configure `sonar.genericcoverage.unitTestReportPaths` in your `sonar-project.properties` instead of `sonar.testExecutionReportPaths`.
fix
Add `"sonar56x": true` to your `jestSonar` configuration in `package.json` and update your `sonar-project.properties` file to use `sonar.genericcoverage.unitTestReportPaths` accordingly.
affects: >=1.3.0
gotchaWhen using environment-specific configurations within `jestSonar.env`, the `NODE_ENV` environment variable must be set to activate the desired configuration (e.g., for different report paths in CI vs. local).
fix
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.
affects: >=2.0.0
Errors
Common errors & fixes
Cannot find module 'jest-sonar-reporter' from '...' or '.../node_modules'
The `jest-sonar-reporter` package is not installed, or Jest cannot resolve its path.
fix
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"`.
java.lang.IllegalStateException: Report path '...' doesn't exist
The SonarQube scanner could not find the test report XML file at the specified path.
fix
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.
Failed to parse XML report: Invalid byte 1 of 1-byte UTF-8 sequence.
The generated XML report is malformed, contains invalid characters, or is not valid UTF-8, causing SonarQube to fail parsing.
fix
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.
Upgrade
Version history
2.0.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources