Al Ferguson
Al Ferguson

Reputation: 41

How to publish Javascript test execution + coverage to SonarQube?

How can I publish results and coverage of Javascript (Jasmine + Karma) tests in Sonar. Java test execution and coverage are fine. I am trying to add the tests for Javascript executed by Karma (lcov coverageReporter + sonarQubeUnitReporter).

Q1. What Sonar properties (e.g., sources, inclusions, tests, test.inclusion, sonar.javascript.lcov.reportPath) should I define?

Q2. In which pom (multi-module pom or submodule pom)?

Q3. To what values must these properties be set?

my-multi-modules-project
|-- a_module-project
|   |-- child.pom
|   |-- src/
|   |   |-- main/
|   |   |   |-- java/
|   |   |   |-- javascript/
|   |   |   |   |-- com/mycompany/project/javascript/
|   |   |   |   |   |-- totest.js
|   |   |   |-- resources/
|   |   |-- test/
|   |   |   |-- java/
|   |   |   |-- javascript/
|   |   |   |   |-- com/mycompany/project/javascript/
|   |   |   |   |   |-- specs/
|   |   |   |   |   |   |-- mytest.spec.js
|   |   |   |   | karma.conf.js
|   |   |   |-- package.json
|   |-- target/
|   |   |-- surefire-reports/
|   |   |-- test-results/
|   |   |   |-- lcov.info
|   |   |   |-- sonarQubeUnitReporter.xml
|-- root.pom
|-- target/

I want to be reported in Sonar (in addition to already existing Java):

  1. Execution of Javascript tests;

  2. Coverage for these tests;

  3. The link to the Javascript source code (No "Test execution data ignored for n unknown files" message).

Versions: jasmine 2.99.0 Java 1.8 karma 1.7.1 karma-coverage 1.1.2 Maven 3.5.4 node 7.5 npm 3.0 sonarqube-unit-reporter 0.0.18 SonarQube 7.4

Upvotes: 1

Views: 2821

Answers (1)

Vinay sharma
Vinay sharma

Reputation: 745

Thanks for the question.

Refer below code-

sonar.sources=src/main/javascript sonar.tests=src/test/javascript/spec sonar.testExecutionReportPaths=test-results/ut_report.xml // for unit tests sonar.javascript.lcov.reportPaths=test-results/lcov.info //for coverage

The path can be relative or absolute depending upon the path of sonar property file location. This should cover your queries. Please refer this https://docs.sonarqube.org/latest/analysis/coverage/ for details of properties.

Upvotes: 1

Related Questions