{"id":13417,"library":"karma-sonarqube-reporter","title":"Karma SonarQube Reporter","description":"karma-sonarqube-reporter is a Karma reporter plugin designed to generate generic test execution reports compatible with SonarQube. The current stable version is 1.4.0. It aims to bridge the gap between JavaScript/TypeScript unit test results run by Karma and the SonarQube analysis platform, enabling projects to integrate test coverage and outcomes directly into their SonarQube quality gate processes. Releases are primarily driven by bug fixes, dependency updates, and minor feature enhancements, with a new feature release (1.3.0) and dynamic test support (1.4.0) indicating ongoing, albeit not rapid, development. A key differentiator is its `legacyMode` option, which allows it to support both modern and older SonarQube versions, providing flexibility for diverse project environments. It focuses solely on test reporting for SonarQube, making it a specialized tool for this specific integration.","status":"active","version":"1.4.0","language":"javascript","source_language":"en","source_url":"https://github.com/fadc80/karma-sonarqube-reporter","tags":["javascript","karma-reporter","sonarqube","typescript"],"install":[{"cmd":"npm install karma-sonarqube-reporter","lang":"bash","label":"npm"},{"cmd":"yarn add karma-sonarqube-reporter","lang":"bash","label":"yarn"},{"cmd":"pnpm add karma-sonarqube-reporter","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"This is a Karma plugin and requires Karma as its runtime test runner environment.","package":"karma","optional":false}],"imports":[{"note":"Karma configuration files are typically CommonJS. The plugin is loaded directly into the `plugins` array, not imported as a class or function for direct usage.","wrong":"import { SonarqubeReporter } from 'karma-sonarqube-reporter';","symbol":"karma-sonarqube-reporter","correct":"plugins: [require('karma-sonarqube-reporter')]"},{"note":"The reporter is referenced by its short name 'sonarqube' in the `reporters` array after being loaded as a plugin.","wrong":"reporters: ['karma-sonarqube-reporter']","symbol":"reporters","correct":"reporters: ['sonarqube']"}],"quickstart":{"code":"const path = require('path');\n\nmodule.exports = function (config) {\n  config.set({\n    basePath: '',\n    frameworks: ['jasmine', '@angular-devkit/build-angular'],\n    plugins: [\n      require('karma-jasmine'),\n      require('karma-chrome-launcher'),\n      require('@angular-devkit/build-angular/plugins/karma'),\n      require('karma-sonarqube-reporter') // Load the plugin\n    ],\n    files: [\n      // Your test files here\n    ],\n    preprocessors: {\n      // Preprocessors for your files\n    },\n    reporters: ['progress', 'sonarqube'], // Activate the reporter\n    sonarqubeReporter: {\n      basePath: 'src/app', // Base path to resolve test files\n      filePattern: '**/*spec.ts', // Glob pattern for test files\n      encoding: 'utf-8', // Encoding of test files\n      outputFolder: path.join(__dirname, 'reports'), // Output directory for reports\n      legacyMode: false, // Set to true for SonarQube < 6.2\n      reportName: (metadata) => {\n        // Example dynamic report name generation\n        return `test-report-${metadata[0].toLowerCase()}-${metadata[1].split('.')[0]}.xml`;\n      }\n    },\n    port: 9876,\n    colors: true,\n    logLevel: config.LOG_INFO,\n    autoWatch: true,\n    browsers: ['Chrome'],\n    singleRun: false,\n    restartOnFileChange: true\n  });\n};\n\n// To run this, install dependencies: npm install --save-dev karma karma-jasmine karma-chrome-launcher @angular-devkit/build-angular karma-sonarqube-reporter","lang":"typescript","description":"This configuration demonstrates how to set up `karma-sonarqube-reporter` in a `karma.conf.js` file, loading it as a plugin, activating it, and configuring its options to generate SonarQube compatible XML reports."},"warnings":[{"fix":"Ensure `legacyMode` is set to `true` if your SonarQube instance is older than version 6.2. For SonarQube 6.2 and newer, set `legacyMode` to `false`.","message":"The `legacyMode` configuration option is critical for SonarQube compatibility. Setting it incorrectly (e.g., `false` for older SonarQube versions or `true` for newer ones) will result in SonarQube failing to parse or import the generated test reports.","severity":"gotcha","affected_versions":">=1.2.0"},{"fix":"Verify that your `sonar-project.properties` file contains the correct property for your `legacyMode` setting and that the path (or comma-delimited list of paths) accurately reflects the `outputFolder` configured in `karma.conf.js`.","message":"The SonarQube scanner property `sonar.testExecutionReportPaths` (for `legacyMode: false`) or `sonar.genericcoverage.unitTestReportPaths` (for `legacyMode: true`) must correctly point to the generated XML report files. An incorrect path will cause SonarQube not to find or process the test results.","severity":"gotcha","affected_versions":">=1.2.0"},{"fix":"Upgrade your Node.js environment to version 8.10.0 or higher to ensure compatibility and stability with the reporter plugin.","message":"Node.js versions below 8.10.0 are not supported and may lead to unexpected errors or failures during report generation. This requirement was explicitly fixed in v1.2.3.","severity":"breaking","affected_versions":"<1.2.3"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Run `npm install karma-sonarqube-reporter --save-dev` to install the package.","cause":"The package `karma-sonarqube-reporter` is not installed or not accessible in the project's `node_modules`.","error":"Error: Cannot find module 'karma-sonarqube-reporter'"},{"fix":"Ensure `sonarqubeReporter: { ... }` is correctly defined in your `karma.conf.js` with all required properties, even if using default values.","cause":"The `sonarqubeReporter` configuration object is missing or malformed in `karma.conf.js` when the reporter is activated.","error":"TypeError: Cannot read properties of undefined (reading 'basePath') at createSonarqubeReporter"},{"fix":"Adjust `basePath` and `filePattern` to accurately reflect the location and naming convention of your unit test files (e.g., `**/*spec.ts` for Angular projects) and ensure Karma is configured to run those tests.","cause":"The `basePath` and `filePattern` in the `sonarqubeReporter` configuration do not match any actual test files in your project, or the Karma runner didn't execute tests in those files.","error":"WARN [reporter]: Can not find any test file for Sonarqube analysis"}],"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}