Skip to content

Instantly share code, notes, and snippets.

@KiranMantha
Last active March 5, 2024 09:51
Show Gist options
  • Save KiranMantha/bc84535aadcc67c6332c9023ce790064 to your computer and use it in GitHub Desktop.
Save KiranMantha/bc84535aadcc67c6332c9023ce790064 to your computer and use it in GitHub Desktop.
Setting sonar with jest

Setting sonar with jest

  1. install jdk12 or above
  2. add JAVA_HOME variable path to environment variables with value C:\Program Files\Java\jdk-<version-number>\
  3. download sonarqube community edition from https://www.sonarqube.org/downloads/
  4. extract zip folder and run the StartSonar.bat from sonarqube\bin\windows-x86–64
  5. navigate to http://localhost:9000 to see sonar dashboard.
  6. navigate to angular project and create sonar-project.properties file
  7. add below content to analyze sonar results in local machine:
sonar.projectKey=<your-project-key>
sonar.projectName=<your-project-name>
sonar.sourceEncoding=UTF-8
sonar.sources=src
sonar.host.url=http://localhost:9000
sonar.login=admin
sonar.password=admin
sonar.typescript.lcov.reportPaths=build/coverage/lcov.info
sonar.exclusions=**/node_modules/**,**/*.spec.ts, **/*.test.ts
sonar.inclusions = **/*.component.ts, **/*.service.ts, **/*.component.html, **/*.pipe.ts
sonar.tests=src
sonar.test.inclusions=**/*.spec.ts
sonar.ts.tslintconfigpath=tslint.json
sonar.testExecutionReportPaths=test-report.xml
  1. run npm i -D sonarqube-scanner jest-sonar-reporter
  2. add script "sonar": "sonar-scanner" to scripts in package.json
  3. to jest.config.js add "testResultsProcessor": "jest-sonar-reporter"
  4. run npm run sonar and wait for completion.
  5. navigate to http://localhost:9000/dashboard?id=<your-project-key-in-sonar-properties-file>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment