Registry / devops / jest-to-sonar

jest-to-sonar

JSON →
library1.3.0jsnpmunverified

jest-to-sonar is a utility library designed to convert Jest test results into the SonarQube Generic Test Execution Report format (XML). This enables developers to integrate JavaScript and TypeScript project test coverage and execution results directly into SonarQube for quality analysis. The current stable version is 1.3.0. Releases are made on an as-needed basis to address bug fixes and new features, such as supporting custom output paths introduced in v1.1.0 and fixing report data format in v1.3.0. Its primary differentiator is its seamless integration as a Jest reporter, simplifying the setup for SonarQube analysis within CI/CD pipelines without requiring manual conversion scripts.

npm install jest-to-sonar
INSTALL
IMPORT
SIG · JEST-TO-SONAR
J
jest-to-sonar
devopsjavascriptv1.3.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-to-sonar'
module.exports = { reporters: ['default', 'jest-to-sonar'], };
import jestToSonar from 'jest-to-sonar';
This package is configured as a string literal within your `jest.config.js` reporters array; it is not meant for direct programmatic import.
'jest-to-sonar' with options
module.exports = { reporters: [ 'default', ['jest-to-sonar', { outputFile: './coverage/sonar-report.xml' }] ], };
const reporter = require('jest-to-sonar').defaultReporter({ outputFile: '...' });
Configuration options like `outputFile` are passed as an array entry where the second element is an object of options, directly within the `jest.config.js` file.

This quickstart demonstrates how to set up `jest-to-sonar` in a `jest.config.js` file, define a basic test, and generate a SonarQube generic test execution report after running tests.

{ "name": "my-project", "version": "1.0.0", "description": "Example project using jest-to-sonar", "main": "index.js", "scripts": { "test": "jest --coverage" }, "devDependencies": { "jest": "^29.0.0", "jest-to-sonar": "^1.3.0" } } // jest.config.js module.exports = { testEnvironment: 'node', collectCoverage: true, coverageDirectory: 'coverage', reporters: [ 'default', ['jest-to-sonar', { outputFile: './coverage/sonar-report.xml', }] ] }; // index.test.js describe('My test suite', () => { test('should add two numbers', () => { expect(1 + 2).toBe(3); }); test('should multiply two numbers', () => { expect(2 * 3).toBe(6); }); }); // To run: // npm install // npm test
Debug
Known issues
gotchaPrior to v1.3.0, `jest-to-sonar` might have generated generic test execution reports with an incorrect data format. If you're using older versions and experiencing issues with SonarQube parsing, upgrading is recommended.
fix
Upgrade to `jest-to-sonar@^1.3.0` or newer: `npm install jest-to-sonar@latest` or `yarn add jest-to-sonar@latest`.
affects: <1.3.0
gotchaWhen configuring `jest-to-sonar`, ensure `collectCoverage` is enabled and `coverageDirectory` is set in your Jest configuration. The `outputFile` path for the Sonar report should typically reside within the `coverageDirectory` for consistency.
fix
In `jest.config.js`, set `collectCoverage: true` and define `coverageDirectory: './coverage'`. Then configure `outputFile: './coverage/sonar-report.xml'` (or your preferred path within `coverageDirectory`) in the `jest-to-sonar` reporter options.
affects: >=1.0.0
Errors
Common errors & fixes
Unknown reporter: jest-to-sonar
The `jest-to-sonar` package is either not installed or Jest cannot find it in your project's `node_modules`.
fix
Ensure `jest-to-sonar` is installed as a dev dependency: `npm install --save-dev jest-to-sonar` or `yarn add --dev jest-to-sonar`.
SonarQube: Generic test execution report parsing failed.
The generated `sonar-report.xml` file might be malformed or contain invalid data, preventing SonarQube from processing it correctly. This could be due to a bug in `jest-to-sonar` or an unexpected output from Jest.
fix
First, ensure you are using `jest-to-sonar@^1.3.0` or newer to avoid known formatting issues. Verify the `sonar-report.xml` file is generated and check its content for obvious syntax errors. Also, review your Jest tests for any non-standard outputs that might interfere with the reporter's parsing.
Upgrade
Version history
1.3.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
jest-to-sonar — npm install jest-to-sonar · libregistry