We recently upgraded SonarQube from 6.x to 7.9.1. There were a lot of issues to deal with, and I’m still left with at least one more.
Our front-end builds were using a gulp plugin to run the scan, and that was working fine. I don’t remember which plugin we were using, but most recently we were using the one that embeds a copy of sonar-scanner. This was failing due to some weird issue about “not finding zip in path”. I never got an answer to this from any of my queries. In any case, this is moot because I’ve moved on from this.
We are now using a direct call to sonar-scanner in our Jenkinsfile.
This is our resulting sonar-scanner command line, with some elisions:
sonar-scanner -Dsonar.typescript.node=/opt/app/bin/node \
-Dsonar.nodejs.executable=/opt/app/bin/node \
-Dsonar.host.url=http://... \
-Dsonar.login=... \
-Dsonar.password= \
-Dsonar.javascript.lcov.reportPaths=coverage/lcov.info \
-Dsonar.typescript.lcov.reportPaths=coverage/lcov.info \
-Dsonar.branch.name= \
-Dsonar.language=js \
-Dsonar.projectKey=... \
-Dsonar.projectName=... \
'-Dsonar.exclusions=**/*.scss.d.ts, **/*.scss, **/*Props.ts, **/*State.ts, **/*index.ts' \
'-Dsonar.coverage.exclusions=**/*.spec.tsx, **/*.spec.ts, **/*.scss.d.ts, **/*.css.d.ts, **/*.scss' \
-Dsonar.projectVersion=1.0.0 \
'-Dsonar.sources=src/components/,src/api/,src/models/mappers/, src/utils/' \
'-Dsonar.lang.patterns.js=*/.ts,*/.tsx' \
-Dsonar.js.file.suffixes=.ts,.tsx \
-Dsonar.sourceEncoding=UTF-8 \
-Dsonar.tests=src \
'-Dsonar.test.inclusions=**/*.spec.tsx' \
-Dsonar.typescript.tslintconfigpath=tslint.json \
-Dsonar.log.level=DEBUG \
-Dsonar.verbose=true \
'-Dsonar.exec.maxBuffer=1024 * 1024'
The problem we have now is that this is not finding any unit tests and thus not finding any coverage. The resulting sonarqube project does find many lines to cover, but the same number of uncovered lines. In the build process, I run an “ls -lt” of the “coverage” directory, to make sure that the “lcov.info” and associated files are generated. I pass the relative path to that file in the two associated properties in the command line, as seen above.
In the build output, I do see lines like this:
DEBUG: 'src/api/Api.spec.tsx' indexed as test with language 'ts'
So something detected that was a test, but the resulting project has no unit tests. The generated coverage files have coverage for “src/api/Api.tsx”, but this shows no coverage in the generated project.
What could be wrong here?