Version note: references describe SonarQube Server 2025.2 behaviour. Check your server, scanner and edition requirements. These examples were not run against a live SonarQube server.
What this guide covers
SonarQube imports coverage reports; it does not run your tests. For JavaScript and TypeScript, a test tool can produce an LCOV file listing which source lines were executed.
Before you start
This example assumes a Node.js project with a lockfile, tests, and a test:coverage script. Install and configure a test tool such as Jest before running these commands.
Step 1: Configure the coverage report
For Jest, merge these options into your existing configuration:
export default {
collectCoverageFrom: ['src/**/*.{js,ts}', '!src/**/*.d.ts'],
coverageDirectory: 'coverage',
coverageReporters: ['lcov', 'text-summary', 'html'],
};
Use paths that match your project. collectCoverageFrom includes source files even when tests never import them.
Step 2: Run tests before scanning
From the project root:
npm ci
npm run test:coverage
test -s coverage/lcov.info
Do not continue if tests fail or the report is empty.
Step 3: Set the report path
Add the following to your project’s scanner configuration:
sonar.sources=src
sonar.tests=test
sonar.javascript.lcov.reportPaths=coverage/lcov.info
The same LCOV setting covers JavaScript and TypeScript. Adjust source and test paths, then run sonar-scanner with the server URL and analysis token supplied securely.
Step 4: Check imported file paths
Inspect the source-file entries in the report:
grep '^SF:' coverage/lcov.info | head
Each SF: path must point to a source file visible to the scanner. In the scanner output, check for the coverage import and warnings about unresolved files.
Check the result
Open a known source file in SonarQube. Its covered and uncovered lines should match the report for the same commit. Coverage shows execution, not whether tests made useful assertions.
Conversation
0 commentsNo comments yet. Start the conversation below.