{"id":13381,"library":"jest-sonar-reporter","title":"Jest Sonar Reporter","description":"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.","status":"active","version":"2.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/3dmind/jest-sonar-reporter","tags":["javascript","sonar","sonarqube","jest","results","processor"],"install":[{"cmd":"npm install jest-sonar-reporter","lang":"bash","label":"npm"},{"cmd":"yarn add jest-sonar-reporter","lang":"bash","label":"yarn"},{"cmd":"pnpm add jest-sonar-reporter","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"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.","wrong":"import jestSonarReporter from 'jest-sonar-reporter'","symbol":"jest-sonar-reporter","correct":"{ \"jest\": { \"testResultsProcessor\": \"jest-sonar-reporter\" } }"},{"note":"The `jestSonar` object is a top-level property in `package.json` for custom configuration options like report paths, filenames, and SonarQube version compatibility.","wrong":"{ \"config\": { \"jestSonar\": { ... } } }","symbol":"jestSonar","correct":"{ \"jestSonar\": { \"reportPath\": \"reports\" } }"},{"note":"Environment-specific configurations are nested under the `env` property within `jestSonar` and activated by the `NODE_ENV` environment variable.","wrong":"{ \"jestSonar\": { \"test\": { \"reportPath\": \"reports-test\" } } }","symbol":"env","correct":"{ \"jestSonar\": { \"env\": { \"test\": { \"reportPath\": \"reports-test\" } } } }"}],"quickstart":{"code":"{\n  \"name\": \"my-jest-project\",\n  \"version\": \"1.0.0\",\n  \"scripts\": {\n    \"test\": \"jest --passWithNoTests\"\n  },\n  \"devDependencies\": {\n    \"jest\": \"^29.0.0\",\n    \"jest-sonar-reporter\": \"^2.0.0\"\n  },\n  \"jest\": {\n    \"testResultsProcessor\": \"jest-sonar-reporter\"\n  },\n  \"jestSonar\": {\n    \"reportPath\": \"./test-reports\",\n    \"reportFile\": \"sonar-report.xml\",\n    \"indent\": 4\n  }\n}\n\n// Then, in your terminal:\n// npm install\n// npm run test\n//\n// And for SonarQube, create a sonar-project.properties:\n// sonar.projectKey=my-jest-project\n// sonar.sources=src\n// sonar.tests=src\n// sonar.javascript.lcov.reportPaths=coverage/lcov.info\n// sonar.testExecutionReportPaths=test-reports/sonar-report.xml\n//\n// And run the scanner:\n// sonar-scanner","lang":"json","description":"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."},"warnings":[{"fix":"Migrate to using the `jestSonar.reportPath` and `jestSonar.reportFile` properties within your `package.json` for all report path and filename configurations.","message":"The `TEST_REPORT_PATH` environment variable for configuring the report output path was removed.","severity":"breaking","affected_versions":">=2.0.0"},{"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.","message":"Support for Node.js version 4 has been dropped, requiring a more modern Node.js runtime.","severity":"breaking","affected_versions":">=2.0.0"},{"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`.","message":"The `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`.","severity":"gotcha","affected_versions":">=1.1.0"},{"fix":"Add `\"sonar56x\": true` to your `jestSonar` configuration in `package.json` and update your `sonar-project.properties` file to use `sonar.genericcoverage.unitTestReportPaths` accordingly.","message":"To 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`.","severity":"gotcha","affected_versions":">=1.3.0"},{"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.","message":"When 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).","severity":"gotcha","affected_versions":">=2.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"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\"`.","cause":"The `jest-sonar-reporter` package is not installed, or Jest cannot resolve its path.","error":"Cannot find module 'jest-sonar-reporter' from '...' or '.../node_modules'"},{"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.","cause":"The SonarQube scanner could not find the test report XML file at the specified path.","error":"java.lang.IllegalStateException: Report path '...' doesn't exist"},{"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.","cause":"The generated XML report is malformed, contains invalid characters, or is not valid UTF-8, causing SonarQube to fail parsing.","error":"Failed to parse XML report: Invalid byte 1 of 1-byte UTF-8 sequence."}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":"","cli_version":null}