Registry / testing / karma-sonarqube-reporter

karma-sonarqube-reporter

JSON →
library1.4.0jsnpmunverified

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.

npm install karma-sonarqube-reporter
INSTALL
IMPORT
SIG · KARMA-SONARQUBE-RE
K
karma-sonarqube-reporter
testingjavascriptv1.4.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.

karma-sonarqube-reporter
plugins: [require('karma-sonarqube-reporter')]
import { SonarqubeReporter } from 'karma-sonarqube-reporter';
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.
reporters
reporters: ['sonarqube']
reporters: ['karma-sonarqube-reporter']
The reporter is referenced by its short name 'sonarqube' in the `reporters` array after being loaded as a plugin.

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.

const path = require('path'); module.exports = function (config) { config.set({ basePath: '', frameworks: ['jasmine', '@angular-devkit/build-angular'], plugins: [ require('karma-jasmine'), require('karma-chrome-launcher'), require('@angular-devkit/build-angular/plugins/karma'), require('karma-sonarqube-reporter') // Load the plugin ], files: [ // Your test files here ], preprocessors: { // Preprocessors for your files }, reporters: ['progress', 'sonarqube'], // Activate the reporter sonarqubeReporter: { basePath: 'src/app', // Base path to resolve test files filePattern: '**/*spec.ts', // Glob pattern for test files encoding: 'utf-8', // Encoding of test files outputFolder: path.join(__dirname, 'reports'), // Output directory for reports legacyMode: false, // Set to true for SonarQube < 6.2 reportName: (metadata) => { // Example dynamic report name generation return `test-report-${metadata[0].toLowerCase()}-${metadata[1].split('.')[0]}.xml`; } }, port: 9876, colors: true, logLevel: config.LOG_INFO, autoWatch: true, browsers: ['Chrome'], singleRun: false, restartOnFileChange: true }); }; // To run this, install dependencies: npm install --save-dev karma karma-jasmine karma-chrome-launcher @angular-devkit/build-angular karma-sonarqube-reporter
Debug
Known issues
gotchaThe `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.
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`.
affects: >=1.2.0
gotchaThe 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.
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`.
affects: >=1.2.0
breakingNode.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.
fix
Upgrade your Node.js environment to version 8.10.0 or higher to ensure compatibility and stability with the reporter plugin.
affects: <1.2.3
Errors
Common errors & fixes
Error: Cannot find module 'karma-sonarqube-reporter'
The package `karma-sonarqube-reporter` is not installed or not accessible in the project's `node_modules`.
fix
Run `npm install karma-sonarqube-reporter --save-dev` to install the package.
TypeError: Cannot read properties of undefined (reading 'basePath') at createSonarqubeReporter
The `sonarqubeReporter` configuration object is missing or malformed in `karma.conf.js` when the reporter is activated.
fix
Ensure `sonarqubeReporter: { ... }` is correctly defined in your `karma.conf.js` with all required properties, even if using default values.
WARN [reporter]: Can not find any test file for Sonarqube analysis
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.
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.
Upgrade
Version history
1.4.0latest on npm
Audit
Dependencies
karmarequiredThis is a Karma plugin and requires Karma as its runtime test runner environment.
Agent activity
4 hits · last 30 days
node
4
Resources
karma-sonarqube-reporter — npm install karma-sonarqube-reporter · libregistry