Skip to content

Instantly share code, notes, and snippets.

@cassilup
Last active February 24, 2021 09:06
Show Gist options
  • Save cassilup/91e90af9c9ec108c4440ba0a0f538a17 to your computer and use it in GitHub Desktop.
Save cassilup/91e90af9c9ec108c4440ba0a0f538a17 to your computer and use it in GitHub Desktop.
[3Pillar KDB] Plug-n-Play SonarQube for TS Projects
  1. Start SonarQube via Docker
# in the folder with docker-compose.yml
docker-compose up -d

(wait until server successfully started)

  1. Access SonarQube and change default (admin/admin) password

http://localhost:9000/

  1. Run Jest with coverage enabled

jest --coverage --detectOpenHandles --forceExit

  1. Tweak sonar-project.properties to match the correct paths

  2. Install SonarQube Scanner

npm install sonarqube-scanner

  1. Run SonarQube Scanner

node_modules/.bin/sonar-scanner -X # -X is for debug, it can be omitted

  1. Navigate to SonarQube and observe new analysis

http://localhost:9000/

version: '3'
services:
sonarqube:
container_name: sonarqube
image: sonarqube:latest
ports:
- '9000:9000'
- '9092:9092'
module.exports = {
// The directory where Jest should output its coverage files
coverageDirectory: "coverage",
// A list of reporter names that Jest uses when writing coverage reports
coverageReporters: [
// "json",
// "text",
"lcov",
// "clover"
],
preset: 'ts-jest'
};
sonar.projectKey=<my-project-key>
sonar.projectName=<Project Name>
sonar.projectVersion=<version>
sonar.language=ts
sonar.scm.provide=git
sonar.sources=<path-to-src-folder>
sonar.sourceEncoding=UTF-8
sonar.exclusions=<path-to-src-folder>/**/*.tests.ts
sonar.test.inclusions=<path-to-src-folder>/**/*.tests.ts
sonar.login=admin
sonar.password=admin1
sonar.coverage.exclusions=src/**/*.tests.ts,src/**/*.mock.ts,node_modules/*,coverage/lcov-report/*
sonar.javascript.lcov.reportPaths=coverage/lcov.info
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment