0
votes

I'm working on integrating Karma tests in maven and using SonarQube for test coverage reporting.

While i'm able to view HTML karma test coverage reports(coverage type HTML in karma.conf.js), i'm not able to view the results in SonarQube when the type is lcov in karma.conf.js.

Content of pom.xml

<properties>
    <sonar.language>js</sonar.language>
    <sonar.exclusions>src/main/content/jcr_root/etc/clientlibs/${apps.project.path}/js/vendor/**</sonar.exclusions>
    <sonar.dynamicAnalysis>reuseReports</sonar.dynamicAnalysis>
    <sonar.javascript.lcov.reportPath>src/main/content/jcr_root/etc/clientlibs/${apps.project.path}/karma_target/lcov.info</sonar.javascript.lcov.reportPath>
</properties>



<build>
    <!-- Karma test sonar coverage properties: Start-->   
    <sourceDirectory>${basedir}/src/main/content/jcr_root/etc/clientlibs/${apps.project.path}/js</sourceDirectory>
    <testSourceDirectory>${basedir}/src/main/content/jcr_root/etc/clientlibs/${apps.project.path}/js_test</testSourceDirectory>

When i run mvn clean install sonar:sonar it creates lcov.info file in the <sonar.javascript.lcov.reportPath> mentioned in the properties.

Content of lcov.info file:

TN:
SF:D:\Workspace\Workspace_MasterCard\Issuer_53\loyalty\aem\loyalty-aem-web\trunk\loyalty-aem-web-ui\src\main\content\jcr_root\etc\clientlibs\loyalty\js\config\namespace.js
FN:15,(anonymous_1)
FNF:1
FNH:1
FNDA:5,(anonymous_1)
DA:2,1
DA:15,1
DA:17,5
DA:21,5
DA:22,0
DA:25,5
DA:28,8
DA:30,5
DA:33,8
DA:36,5
LF:10
LH:9
BRDA:2,1,0,1
BRDA:2,1,1,1
BRDA:21,2,0,0
BRDA:21,2,1,5
BRDA:28,3,0,5
BRDA:28,3,1,3
BRF:6
BRH:5
end_of_record

After the run, SonarQube dashboard shows js code violations but does not populate code coverage. enter image description here

Configuration in karma.conf.js:

preprocessors: {
      'tpl/*.html': 'ng-html2js',
      '!(vendor)/*.js': 'coverage'
    },

    coverageReporter: {
      // specify a common output directory
      type: 'lcov',
      dir : 'karma_target/karma-coverage'
    },

SonarQube version being used is 5.0.1 and js plugin verison is 2.11

I'm guessing the issue is with relative paths, i did go through these links here and here, tried updating SF path to relatively point to lcov.info file manually, all to no avail. % is still 0.

Please let me know if i'm doing anything wrong here. Console log below, all the paths being referred are correct.

[INFO] [13:21:32.877] Base dir: D:\Workspace\Workspace_MasterCard\Issuer_53\loyalty\aem\loyalty-aem-web\trunk\loyalty-aem-web-ui
[INFO] [13:21:32.877] Working dir: D:\Workspace\Workspace_MasterCard\Issuer_53\loyalty\aem\loyalty-aem-web\trunk\loyalty-aem-web-ui\target\sonar
[INFO] [13:21:32.886] Source paths: pom.xml, src/main/content/jcr_root/etc/clientlibs/loyalty/js
[INFO] [13:21:32.888] Test paths: src/main/content/jcr_root/etc/clientlibs/loyalty/js_test

[INFO] [13:21:34.441] Analysing D:\Workspace\Workspace_MasterCard\Issuer_53\loyalty\aem\loyalty-aem-web\trunk\loyalty-aem-web-ui\src\main\content\jcr_root\etc\clientlibs\loyalty\karma_target\lcov.info
[INFO] [13:21:34.441] 25/25 source files have been analyzed
1
Does lcov.info only contains these 9 lines?Pierre-Yves
nope, i've just grabbed the screenshot of first few linesSubSul
lcov.info should contain lines starting with DA to indicate lines which should be covered: is that the case? You could also provide a bigger part of your logs, at least lines above and below Analysing...lcov.info.Pierre-Yves
updated lcov.info file contentSubSul
lcov.info now looks ok. It would be easier to help you if could give the full logs. If a file path cannot be resolved, a warning should appear.Pierre-Yves

1 Answers

0
votes

Got it working finally. It was this vicious problem of relative paths! Issue was with location of karma.conf.js file relative to the target and other folders. It's all working fine now.