My Nestjs project is undergoing Sonarqube analysis. Despite passing all unit tests with jest and achieving an 80% code coverage, Sonarqube still displays a 0% coverage.
Here is my configuration in the sonar-project.properties file:
sonar.projectKey=<project-key>
sonar.projectName=
sonar.sources=src
sonar.tests=src
sonar.inclusions=**
sonar.test.inclusions=src/**/*.spec.ts
sonar.testExecutionReportPaths=test-report.xml
sonar.exclusions=node_modules
The jest.json setup looks like this:
{
"moduleFileExtensions": [
"ts",
"tsx",
"js",
"json"
],
"transform": {
"^.+\\.tsx?$": "ts-jest"
},
"testRegex": "/src/.*\\.(test|spec).(ts|tsx|js)$",
"testCoverageFrom" : ["src/**/*.{js,jsx,tsx,ts}", "!**/node_modules/**", "!**/vendor/**"],
"coverageReporters": ["json", "lcov"]
}
Extract from my package.json:
"devDependencies": {
// List of dependencies
},
"jest": {
// Jest configuration details
}
All source code and respective unit tests are located together, with test files having the .spec.ts extension. The local tests pass successfully and generate a test-report.xml locally. Running unit tests on Jenkins before scanning with Sonar scanner.
Ensuring adequate code coverage is critical for our pipeline to progress. Any suggestions?
Sonarqube Enterprise Edition Version 7.9.5 (build 38598)