0 coverage vuejs sonarcloud

I am working with vuejs files, the scanner works well but I have 0% coverage on sonarcloud.io
When I run coverage in local, it shows that my tests works fine.

sonar.projectKey=MYKEY
sonar.organization=MYORGANIZATION
sonar.projectName = Front
sonar.sources=adapters,api,assets
sonar.javascript.lcov.reportPaths=coverage/lcov.info
# sonar.coverageReportPaths=
# sonar.testExecutionReportPaths=
sonar.python.version=3.8
sonar.tests=tests

Any idea ?

Hey there.

What do your logs say? Look for logs from the scanner like this:

INFO: Sensor JavaScript/TypeScript Coverage [javascript]

I went further and now i have new errors,
I added these to sonar-project.properties

sonar.javascript.lcov.reportPaths=coverage/lcov.info
sonar.testExecutionReportPaths=test-report.xml
sonar.coverageReportPaths=coverage/cobertura-coverage.xml

So after tests, a cobertura-coverage.xml file is created and can’t be parsed by sonar scanner

ERROR: Error during parsing of the generic coverage report '/builds/Core4Tech/drowsiness/front/coverage/cobertura-coverage.xml'. Look at SonarQube documentation to know the expected XML format.
ERROR: Caused by: Unknown XML node, expected "file" but got "sources" at line 4

The cobertura-coverage.xml file looks like that :

<?xml version="1.0" ?>
<!DOCTYPE coverage SYSTEM "http://cobertura.sourceforge.net/xml/coverage-04.dtd">
<coverage lines-valid="142" lines-covered="1" line-rate="0.006999999999999999" branches-valid="222" branches-covered="2" branch-rate="0.009000000000000001" timestamp="1653300216984" complexity="0" version="0.1">
  <sources>
    <source>C:\Users\me\Documents\VisualCode\front</source>
  </sources>
  <packages>
    <package name="components" line-rate="0.14279999999999998" branch-rate="0.3333">
      <classes>
        <class name="breadcrumb.vue" filename="components\breadcrumb.vue" line-rate="0" branch-rate="1">
          <methods>
            <method name="(anonymous_0)" hits="0" signature="()V">
              <lines>
                <line number="1" hits="0"/>
              </lines>
            </method>
          </methods>
          <lines>
            <line number="1" hits="0" branch="false"/>
          </lines>
        </class>

I have read that it is possible to convert this file with a plugin but I have no idea of how to it

And also, I have this in logs

INFO: Sensor JavaScript/TypeScript Coverage [javascript]
INFO: No LCOV files were found using coverage/lcov.info
WARN: No coverage information will be saved because all LCOV files cannot be found.

but when i run tests, a lcov.info file is created too :

TN:
SF:components\breadcrumb.vue
FN:1,(anonymous_0)
FNF:1
FNH:0
FNDA:0,(anonymous_0)
DA:1,0
LF:1
LH:0
BRF:0
BRH:0
end_of_record
TN:
SF:components\drowsiNumber.vue
FN:1,(anonymous_0)
FNF:1
FNH:0
FNDA:0,(anonymous_0)
DA:1,0
LF:1
LH:0

Thanks

I wouldn’t focus at all on your Cobertura report and return to passing your lcov.info file to sonar.javascript.lcov.reportPaths.

What’s the file path for your lcov.info report? Is it located in a coverage directory? Does it exist when analysis is executed?

lcov.info file is located in coverage/ directory.
He is created after running “npm run test”
“test”: “NODE_ENV=test jest --reporters=jest-junit --reporters=default --coverage”

After tests, two files are imported, cobertura-coverage.xml & junit.xml

Should I declare lcov.info as an artifact in my gitlab-ci.yml ?

After deleting all coding lines in link with cobertura.
I have now a succesful pipeline but 0 coverage on sonarcloud.
Still in the logs I have this

INFO: Sensor JavaScript/TypeScript Coverage [javascript]
INFO: No LCOV files were found using coverage/lcov.info
WARN: No coverage information will be saved because all LCOV files cannot be found.

My sonar-project.properties :

sonar.projectKey=key
sonar.organization=orga
sonar.projectName = Front
sonar.language=js
sonar.sources=.vscode,adapters,api,assets,components,domain,layouts,locales,middleware,pages,plugins,services,static,store
sonar.tests=tests
sonar.javascript.lcov.reportPaths=coverage/lcov.info
#sonar.testExecutionReportPaths=test-report.xml

He also don’t find test-report.xml but he’s created when I run tests in local

ERROR: Caused by: /builds/Core4Tech/drowsiness/front/test-report.xml (No such file or directory)

If you are running your tests in a separate docker container than the scanner is running (feel free to share your gitlab-ci.yml file), naturally the scanner is not going to be able to pick up the report because as far as it’s concerned… it doesn’t exist.

This sounds like the right path. It will be important that you’re able to run a cat coverage/lcov.info before the sonar-scanner and that your coverage data exists.

Yep, so it works now, lcov.info file is parsed
I added paths : coverage/ im my gitlab-ci.yml like that :

test:
  stage: tests
  script:
    - docker build -t cft-front-img .
    - docker run  --rm --entrypoint /usr/src/nuxt-app/entrypoint-test.sh -v ${PWD}:/usr/src/nuxt-app/ cft-front-img
  artifacts:
    when: always
    reports:
      junit:
        - junit.xml
    paths:
      - coverage/
  only:
    - merge_requests
    - master

Thanks for you help @Colin

1 Like

Thanks for the follow-up! Glad you’re in good shape now.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.