ci(sonarqube): generate and report server test coverage
SonarQube reported 0% coverage because the analysis workflow never ran the test suite — the scanner does static analysis only and was handed no coverage report, and sonar-project.properties defined no report path. Generate an LCOV report in sonarqube.yml before the scan using Node's built-in test coverage (run from the repo root so SF: paths are server/src/... and resolve against the project base dir), and point the scanner at it via sonar.javascript.lcov.reportPaths. Node's lcov coverage reporter needs Node >= 22, so the coverage job pins node 22. Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -41,6 +41,31 @@ jobs:
|
||||
# compute "new code". A shallow clone degrades both.
|
||||
fetch-depth: 0
|
||||
|
||||
# SonarQube runs static analysis only — it never executes the test suite,
|
||||
# so we must produce a coverage report ourselves and hand it to the
|
||||
# scanner (see sonar.javascript.lcov.reportPaths in sonar-project.properties).
|
||||
# Node's built-in `lcov` coverage reporter needs Node >= 22.
|
||||
- uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: 22
|
||||
cache: npm
|
||||
cache-dependency-path: server/package-lock.json
|
||||
|
||||
- name: Install server deps
|
||||
run: npm ci --prefix server
|
||||
|
||||
- name: Generate server test coverage (LCOV)
|
||||
# Run from the repo root (not `--prefix server`) so the LCOV `SF:` paths
|
||||
# are emitted as `server/src/...`, matching sonar.sources and letting the
|
||||
# scanner resolve them against the project base dir. The server tests stub
|
||||
# their models and point the DB pool at a dead port, so no MariaDB is needed.
|
||||
run: |
|
||||
mkdir -p server/coverage
|
||||
node --test --experimental-test-coverage \
|
||||
--test-reporter=spec --test-reporter-destination=stdout \
|
||||
--test-reporter=lcov --test-reporter-destination=server/coverage/lcov.info \
|
||||
server/test/*.test.js
|
||||
|
||||
- name: Run SonarQube scan
|
||||
uses: sonarsource/sonarqube-scan-action@v4
|
||||
env:
|
||||
|
||||
Reference in New Issue
Block a user