Skip to content

Commit

Permalink
fix: configure SonarQubeUnitReporter
Browse files Browse the repository at this point in the history
  • Loading branch information
HenryT-CG committed Jan 1, 2024
1 parent 7a61c50 commit fe092d3
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 13 deletions.
38 changes: 33 additions & 5 deletions karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@
module.exports = function (config) {
config.set({
basePath: '',
logLevel: config.LOG_INFO,
frameworks: ['jasmine', '@angular-devkit/build-angular'],
plugins: [
require('karma-chrome-launcher'),
require('karma-coverage'),
require('karma-jasmine'),
require('karma-jasmine-html-reporter'),
require('karma-junit-reporter'),
require('karma-sonarqube-unit-reporter'),
require('@angular-devkit/build-angular/plugins/karma')
],
client: {
Expand All @@ -24,19 +27,44 @@ module.exports = function (config) {
jasmineHtmlReporter: {
suppressAll: true // removes the duplicated traces
},
junitReporter: {
outputDir: 'reports/unit-test-results', // results will be saved as $outputDir/$browserName.xml
outputFile: 'results-junit-tests.xml', // if included, results will be saved as $outputDir/$browserName/$outputFile
suite: 'models', // suite will become the package name attribute in xml testsuite element
useBrowserName: false, // add browser name to report and classes names
nameFormatter: undefined, // function (browser, result) to customize the name attribute in xml testcase element
classNameFormatter: undefined, // function (browser, result) to customize the classname attribute in xml testcase element
properties: {} // key value pair of properties to add to the <properties> section of the report
},
sonarqubeReporter: {
basePath: 'src/app', // test files folder
filePattern: '**/*.spec.ts', // test files glob pattern
encoding: 'utf-8', // test files encoding
outputFolder: 'sonar', // report destination
legacyMode: false, // report for Sonarqube < 6.2 (disabled)
reportName: 'sonarqube_report.xml'
},
sonarQubeUnitReporter: {
sonarQubeVersion: 'LATEST',
outputFile: 'reports/sonarqube_report.xml',
testPaths: ['./src/app'],
testFilePattern: '**/*.spec.ts',
useBrowserName: false
},
coverageReporter: {
dir: require('path').join(__dirname, './reports/coverage'),
subdir: '.',
includeAllSources: true,
dir: 'reports',
subdir: 'coverage',
reporters: [{ type: 'html' }, { type: 'text-summary' }, { type: 'lcov' }]
},
reporters: ['progress', 'kjhtml'],
reporters: ['progress', 'kjhtml', 'coverage', 'sonarqubeUnit', 'junit'],
preprocessors: { 'src/**/*.js': ['coverage'] },
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['HeadlessChrome'],
singleRun: false,
restartOnFileChange: true,
browsers: ['HeadlessChrome'],
customLaunchers: {
HeadlessChrome: {
base: 'ChromeHeadless',
Expand Down
65 changes: 63 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"browsers": "npx browserslist",
"sonar": "npx sonarqube-scanner -Dproject.settings=sonar-local-project.properties",
"test": "ng test",
"test:ci": "ng test --watch=false --browsers=ChromeHeadless --code-coverage",
"karma": "rm -rf reports && ng test --watch=false --browsers=ChromeHeadless --code-coverage",
"apigen-cleanup": "rm -rf $npm_package_config_openapiOutput",
"apigen-format": "npx prettier $npm_package_config_openapiYaml --write && npx prettier $npm_package_config_openapiOutput/**/* --write",
"apigen-generate": "openapi-generator-cli generate -i $npm_package_config_openapiYaml -g typescript-angular -c apigen.yaml -o $npm_package_config_openapiOutput --type-mappings AnyType=object",
Expand Down Expand Up @@ -75,7 +75,6 @@
"primeng": "^15.3.0",
"regenerator-runtime": "0.13.11",
"rxjs": "7.8.1",
"sonarqube-scanner": "^3.3.0",
"tslib": "^2.5.0",
"zod": "^3.22.1",
"zone.js": "~0.12.0"
Expand Down Expand Up @@ -131,6 +130,8 @@
"karma-coverage-istanbul-reporter": "^3.0.3",
"karma-jasmine": "^5.1.0",
"karma-jasmine-html-reporter": "^2.0.0",
"karma-junit-reporter": "^2.0.1",
"karma-sonarqube-unit-reporter": "^0.0.23",
"msw": "^1.2.1",
"msw-storybook-addon": "^1.8.0",
"ng-packagr": "15.2.2",
Expand All @@ -141,6 +142,7 @@
"postcss-preset-env": "~8.3.2",
"postcss-url": "~10.1.3",
"prettier": "^2.8.8",
"sonarqube-scanner": "^3.3.0",
"style-loader": "^3.3.2",
"stylus": "^0.59.0",
"stylus-loader": "^7.1.0",
Expand Down
11 changes: 7 additions & 4 deletions sonar-local-project.properties
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
# sonar.verbose=true
# sonar.host.url=http://localhost:9000
# sonar.token=<local-created-token>
sonar.host.url=http://localhost:9000
#sonar.token=<local-created-token>
sonar.token=sqp_4f516f122209fad902530dc69bf59664457ab48e
# remote
sonar.host.url=https://sonarcloud.io
#sonar.host.url=https://sonarcloud.io
sonar.organization=onecx
sonar.projectKey=onecx-theme-ui
sonar.projectName=onecx-theme-ui
sonar.javascript.lcov.reportPaths=reports/lcov.info
sonar.javascript.coveragePlugin=lcov
sonar.javascript.lcov.reportPaths=reports/coverage/lcov.info
sonar.testExecutionReportPaths=reports/sonarqube_report.xml
#sonar.eslint.reportPaths=eslint_report
sonar.sourceEncoding=UTF-8
sonar.sources=src/app
sonar.working.directory=dist/sonar
sonar.coverage.exclusions=*.js,src/*,src/test/*,src/environments/*,src/assets/**/*,src/app/generated/**/*
sonar.exclusions=node_modules/**
sonar.tests=src/app
sonar.test.inclusions=src/app/**/*.spec.ts

0 comments on commit fe092d3

Please sign in to comment.