Angular Application - Could not resolve path in lcov.info

  • I am using SonarScanner 4.7.0.2747
  • I am trying to run sonar scanner on angular application and push output to Sonarqube.

I created a sample angular application via the Angular CLI and configured karma for coverage report. When I run the ng test command, test are run as expected and coverage folder is created.

Now I try to run sonar scanner to analyze the source code and push the output to Sonrqube. I run the below command to do it.

sonar-scanner -Dsonar.projectKey=TestXpsSpaSonar -Dsonar.projectVersion=1.0.0 -Dsonar.host.url=http://sonarqub:8081 -Dsonar.login=**************** -Dsonar.projectBaseDir=.\src -Dsonar.javascript.lcov.reportPaths=C:\Users\narayanasamys\Workspace\Angular\xpssonar\coverage\lcov.info -Dsonar.typescript.tsconfigPath=C:\Users\narayanasamys\Workspace\Angular\xpssonar\tsconfig.json

The source files are getting analyzed based on passed in tsconfig.json but the analysis of lcov.info fails resulting in zero coverage in Sonarqube for the project.

INFO: Analysing [C:\Users\narayanasamys\Workspace\Angular\xpssonar\coverage\lcov.info]
WARN: Could not resolve 3 file paths in [C:\Users\narayanasamys\Workspace\Angular\xpssonar\coverage\lcov.info]
WARN: First unresolved path: src\polyfills.ts (Run in DEBUG mode to get full list of unresolved paths)

The lcov.info file content looks as below.

TN:
SF:src\polyfills.ts
FNF:0
FNH:0
LF:0
LH:0
BRF:0
BRH:0
end_of_record
TN:
SF:src\test.ts
FNF:0
FNH:0
DA:18,1
DA:25,1
DA:27,1
LF:3
LH:3
BRF:0
BRH:0
end_of_record
TN:
SF:src\app\app.component.ts
FNF:0
FNH:0
DA:8,1
DA:9,3
LF:2
LH:2
BRF:0
BRH:0
end_of_record

Can anyone please let me know why the coverage data is missing ?
Is it because of -Dsonar.projectBaseDir being set to “.\src” ?

Thank you,
S N.

Hey there.

If you’re project base directory is set to src… it’s probably not going to find src/src/polyfills.ts. I would recommend starting back a directory.

Hello Colin - Thank you for taking the time to respond.

We want to scan only “src” folder and not any other folder. Especially we want to ignore “node_modules”. I’ve attached the screenshot of the folder structure.

In Sonarqube, I see that the scanned files path does not include “src” folder. For example in my source control, the path for a file is “src\polyfill.ts” whereas in Sonarqube the path is just “polyfill.ts” .

If I manually edit the content of lcov.info file then things will work. But that’s a hack which I would like to avoid.

I would just suggest starting your scan from the previous directory and narrowing the focus to just the src folder.

Thank you Colin. That worked.

1 Like