{"id":13383,"library":"jest-to-sonar","title":"Jest to Sonar Report Converter","description":"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.","status":"active","version":"1.3.0","language":"javascript","source_language":"en","source_url":"https://github.com/santoshshinde2012/jest-to-sonar","tags":["javascript","jest","typescript","sonarqube","test","report"],"install":[{"cmd":"npm install jest-to-sonar","lang":"bash","label":"npm"},{"cmd":"yarn add jest-to-sonar","lang":"bash","label":"yarn"},{"cmd":"pnpm add jest-to-sonar","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"This package is configured as a string literal within your `jest.config.js` reporters array; it is not meant for direct programmatic import.","wrong":"import jestToSonar from 'jest-to-sonar';","symbol":"'jest-to-sonar'","correct":"module.exports = {\n  reporters: ['default', 'jest-to-sonar'],\n};"},{"note":"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.","wrong":"const reporter = require('jest-to-sonar').defaultReporter({ outputFile: '...' });","symbol":"'jest-to-sonar' with options","correct":"module.exports = {\n  reporters: [\n    'default',\n    ['jest-to-sonar', { outputFile: './coverage/sonar-report.xml' }]\n  ],\n};"}],"quickstart":{"code":"{\n  \"name\": \"my-project\",\n  \"version\": \"1.0.0\",\n  \"description\": \"Example project using jest-to-sonar\",\n  \"main\": \"index.js\",\n  \"scripts\": {\n    \"test\": \"jest --coverage\"\n  },\n  \"devDependencies\": {\n    \"jest\": \"^29.0.0\",\n    \"jest-to-sonar\": \"^1.3.0\"\n  }\n}\n\n// jest.config.js\nmodule.exports = {\n  testEnvironment: 'node',\n  collectCoverage: true,\n  coverageDirectory: 'coverage',\n  reporters: [\n    'default',\n    ['jest-to-sonar', {\n      outputFile: './coverage/sonar-report.xml',\n    }]\n  ]\n};\n\n// index.test.js\ndescribe('My test suite', () => {\n  test('should add two numbers', () => {\n    expect(1 + 2).toBe(3);\n  });\n\n  test('should multiply two numbers', () => {\n    expect(2 * 3).toBe(6);\n  });\n});\n\n// To run:\n// npm install\n// npm test","lang":"typescript","description":"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."},"warnings":[{"fix":"Upgrade to `jest-to-sonar@^1.3.0` or newer: `npm install jest-to-sonar@latest` or `yarn add jest-to-sonar@latest`.","message":"Prior 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.","severity":"gotcha","affected_versions":"<1.3.0"},{"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.","message":"When 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.","severity":"gotcha","affected_versions":">=1.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-to-sonar` is installed as a dev dependency: `npm install --save-dev jest-to-sonar` or `yarn add --dev jest-to-sonar`.","cause":"The `jest-to-sonar` package is either not installed or Jest cannot find it in your project's `node_modules`.","error":"Unknown reporter: jest-to-sonar"},{"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.","cause":"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.","error":"SonarQube: Generic test execution report parsing failed."}],"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}