From fe092d33c1a44752e9a74892938fea5961da7cbc Mon Sep 17 00:00:00 2001 From: Henry Taeschner Date: Mon, 1 Jan 2024 19:54:17 +0100 Subject: [PATCH] fix: configure SonarQubeUnitReporter --- karma.conf.js | 38 +++++++++++++++++--- package-lock.json | 65 ++++++++++++++++++++++++++++++++-- package.json | 6 ++-- sonar-local-project.properties | 11 +++--- 4 files changed, 107 insertions(+), 13 deletions(-) diff --git a/karma.conf.js b/karma.conf.js index 0482aff..974669e 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -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: { @@ -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 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', diff --git a/package-lock.json b/package-lock.json index 63486b2..5734143 100644 --- a/package-lock.json +++ b/package-lock.json @@ -40,7 +40,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" @@ -96,6 +95,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", @@ -106,6 +107,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", @@ -10802,6 +10804,7 @@ "version": "0.5.10", "resolved": "https://registry.npmjs.org/adm-zip/-/adm-zip-0.5.10.tgz", "integrity": "sha512-x0HvcHqVJNTPk/Bw8JbLWlWoo6Wwnsug0fnYYro1HBrjxZ3G7/AZk7Ahv8JwDe1uIcz8eBqvu86FuF1POiG7vQ==", + "dev": true, "engines": { "node": ">=6.0" } @@ -12643,6 +12646,7 @@ "version": "1.1.3", "resolved": "https://registry.npmjs.org/color-support/-/color-support-1.1.3.tgz", "integrity": "sha512-qiBjkpbMLO/HL68y+lh4q0/O1MZFj2RX6X/KmMa3+gJD3z+WwI1ZzDHysvqHGS3mP6mznPckpXmw1nI9cJjyRg==", + "dev": true, "bin": { "color-support": "bin.js" } @@ -16468,6 +16472,7 @@ "version": "2.0.0", "resolved": "https://registry.npmjs.org/fancy-log/-/fancy-log-2.0.0.tgz", "integrity": "sha512-9CzxZbACXMUXW13tS0tI8XsGGmxWzO2DmYrGuBJOJ8k8q2K7hwfJA5qHjuPPe8wtsco33YR9wc+Rlr5wYFvhSA==", + "dev": true, "dependencies": { "color-support": "^1.1.3" }, @@ -19606,6 +19611,7 @@ "version": "2.0.0", "resolved": "https://registry.npmjs.org/jest-sonar-reporter/-/jest-sonar-reporter-2.0.0.tgz", "integrity": "sha512-ZervDCgEX5gdUbdtWsjdipLN3bKJwpxbvhkYNXTAYvAckCihobSLr9OT/IuyNIRT1EZMDDwR6DroWtrq+IL64w==", + "dev": true, "dependencies": { "xml": "^1.0.1" }, @@ -20300,6 +20306,43 @@ "integrity": "sha512-O236+gd0ZXS8YAjFx8xKaJ94/erqUliEkJTDedyE7iHvv4ZVqi+q+8acJxu05/WJDKm512EUNn809In37nWlAQ==", "dev": true }, + "node_modules/karma-junit-reporter": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/karma-junit-reporter/-/karma-junit-reporter-2.0.1.tgz", + "integrity": "sha512-VtcGfE0JE4OE1wn0LK8xxDKaTP7slN8DO3I+4xg6gAi1IoAHAXOJ1V9G/y45Xg6sxdxPOR3THCFtDlAfBo9Afw==", + "dev": true, + "dependencies": { + "path-is-absolute": "^1.0.0", + "xmlbuilder": "12.0.0" + }, + "engines": { + "node": ">= 8" + }, + "peerDependencies": { + "karma": ">=0.9" + } + }, + "node_modules/karma-junit-reporter/node_modules/xmlbuilder": { + "version": "12.0.0", + "resolved": "https://registry.npmjs.org/xmlbuilder/-/xmlbuilder-12.0.0.tgz", + "integrity": "sha512-lMo8DJ8u6JRWp0/Y4XLa/atVDr75H9litKlb2E5j3V3MesoL50EBgZDWoLT3F/LztVnG67GjPXLZpqcky/UMnQ==", + "dev": true, + "engines": { + "node": ">=6.0" + } + }, + "node_modules/karma-sonarqube-unit-reporter": { + "version": "0.0.23", + "resolved": "https://registry.npmjs.org/karma-sonarqube-unit-reporter/-/karma-sonarqube-unit-reporter-0.0.23.tgz", + "integrity": "sha512-Mp1b8pkZzFxRWS2eeEDzkrPXIlotRckLJ0C2fXUiUoilAVYJ5AiAyYN14cJzxGbRx65DdXBpu5LI+lt+MHigWA==", + "dev": true, + "dependencies": { + "xmlbuilder": "^13.0.2" + }, + "peerDependencies": { + "karma": ">=0.9" + } + }, "node_modules/karma-source-map-support": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/karma-source-map-support/-/karma-source-map-support-1.4.0.tgz", @@ -22357,6 +22400,7 @@ "version": "2.1.9", "resolved": "https://registry.npmjs.org/node-downloader-helper/-/node-downloader-helper-2.1.9.tgz", "integrity": "sha512-FSvAol2Z8UP191sZtsUZwHIN0eGoGue3uEXGdWIH5228e9KH1YHXT7fN8Oa33UGf+FbqGTQg3sJfrRGzmVCaJA==", + "dev": true, "bin": { "ndh": "bin/ndh" }, @@ -24975,6 +25019,7 @@ "version": "2.0.3", "resolved": "https://registry.npmjs.org/progress/-/progress-2.0.3.tgz", "integrity": "sha512-7PiHtLll5LdnKIMw100I+8xJXR5gW2QwWYkT6iJva0bXitZKa/XMrSbdmg3r2Xnaidz9Qumd0VPaMrZlF9V9sA==", + "dev": true, "engines": { "node": ">=0.4.0" } @@ -26977,6 +27022,7 @@ "version": "1.8.1", "resolved": "https://registry.npmjs.org/shell-quote/-/shell-quote-1.8.1.tgz", "integrity": "sha512-6j1W9l1iAs/4xYBI1SYOVZyFcCis9b4KCLQ8fgAGG07QvzaRLVVRQvAy85yNmmZSjYjg4MWh4gNvlPujU/5LpA==", + "dev": true, "funding": { "url": "https://github.com/sponsors/ljharb" } @@ -27210,6 +27256,7 @@ "version": "1.6.6", "resolved": "https://registry.npmjs.org/slugify/-/slugify-1.6.6.tgz", "integrity": "sha512-h+z7HKHYXj6wJU+AnS/+IH8Uh9fdcX1Lrhg1/VMdf9PwoBQXFcXiAdsy2tSK0P6gKwJLXp02r90ahUCqHk9rrw==", + "dev": true, "engines": { "node": ">=8.0.0" } @@ -27328,6 +27375,7 @@ "version": "3.3.0", "resolved": "https://registry.npmjs.org/sonarqube-scanner/-/sonarqube-scanner-3.3.0.tgz", "integrity": "sha512-G1A6nXT3GwoK5eRwHfFrR/7ThiDfaRefWPIFQ+ifwFOQ/V9OwziLpZBdWZgmZp21kBRnzAMvjcTzgZMqGBXQKA==", + "dev": true, "dependencies": { "adm-zip": "^0.5.10", "fancy-log": "^2.0.0", @@ -27350,6 +27398,7 @@ "version": "7.1.0", "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-7.1.0.tgz", "integrity": "sha512-o/zjMZRhJxny7OyEF+Op8X+efiELC7k7yOjMzgfzVqOzXqkBkWI79YoTdOtsuWd5BWhAGAuOY/Xa6xpiaWXiNg==", + "dev": true, "dependencies": { "debug": "^4.3.4" }, @@ -27361,6 +27410,7 @@ "version": "7.0.2", "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-7.0.2.tgz", "integrity": "sha512-NmLNjm6ucYwtcUmL7JQC1ZQ57LmHP4lT15FQ8D61nak1rO6DH+fz5qNK2Ap5UN4ZapYICE3/0KodcLYSPsPbaA==", + "dev": true, "dependencies": { "agent-base": "^7.0.2", "debug": "4" @@ -27373,6 +27423,7 @@ "version": "3.0.1", "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-3.0.1.tgz", "integrity": "sha512-+NsyUUAZDmo6YVHzL/stxSu3t9YS1iljliy3BSDrXJ/dkn1KYdmtZODGGjLcc9XLgVVpH4KshHB8XmZgMhaBXg==", + "dev": true, "bin": { "mkdirp": "dist/cjs/src/bin.js" }, @@ -30359,7 +30410,17 @@ "node_modules/xml": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/xml/-/xml-1.0.1.tgz", - "integrity": "sha512-huCv9IH9Tcf95zuYCsQraZtWnJvBtLVE0QHMOs8bWyZAFZNDcYjsPq1nEx8jKA9y+Beo9v+7OBPRisQTjinQMw==" + "integrity": "sha512-huCv9IH9Tcf95zuYCsQraZtWnJvBtLVE0QHMOs8bWyZAFZNDcYjsPq1nEx8jKA9y+Beo9v+7OBPRisQTjinQMw==", + "dev": true + }, + "node_modules/xmlbuilder": { + "version": "13.0.2", + "resolved": "https://registry.npmjs.org/xmlbuilder/-/xmlbuilder-13.0.2.tgz", + "integrity": "sha512-Eux0i2QdDYKbdbA6AM6xE4m6ZTZr4G4xF9kahI2ukSEMCzwce2eX9WlTI5J3s+NU7hpasFsr8hWIONae7LluAQ==", + "dev": true, + "engines": { + "node": ">=6.0" + } }, "node_modules/xtend": { "version": "4.0.2", diff --git a/package.json b/package.json index b2b319c..2875b03 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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" @@ -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", @@ -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", diff --git a/sonar-local-project.properties b/sonar-local-project.properties index 9d09f7d..963c743 100644 --- a/sonar-local-project.properties +++ b/sonar-local-project.properties @@ -1,17 +1,20 @@ # sonar.verbose=true -# sonar.host.url=http://localhost:9000 -# sonar.token= +sonar.host.url=http://localhost:9000 +#sonar.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 \ No newline at end of file