From ad95f2c57598bec9ec4bea00be48db8a1ade7249 Mon Sep 17 00:00:00 2001
From: Simon Reis <simon.reis@pta.de>
Date: Mon, 7 Mar 2022 14:55:23 +0100
Subject: [PATCH] changes to successfully run fe untitests and publish results
 to sonarcloud

---
 .gitlab-ci.yml           | 14 ++++++++------
 package.json             |  4 +++-
 sonar-project.properties | 11 ++++-------
 src/karma.conf.js        | 11 ++++++++++-
 4 files changed, 25 insertions(+), 15 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 07309c7f..8662d484 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -5,10 +5,10 @@ variables:
   TRANSFER_METER_FREQUENCY: 5s # will display transfer progress every 5 seconds for artifacts and remote caches.
   SONAR_USER_HOME: ${CI_PROJECT_DIR}/.sonar  # Defines the location of the analysis task cache
   GIT_DEPTH: 0  # Tells git to fetch all the branches of the project, required by the analysis task
-  CLI_VERSION: latest
+  CLI_VERSION: 6.0.3
   DOCKER_BUILDKIT: 1 # With BuildKit, you don't need to pull the remote images before building since it caches each build layer in your image registry. Then, when you build the image, each layer is downloaded as needed during the build.
 
-image: node:10
+image: node:8.9.4
 
 #-----------------------------------------------------------------------------------------------------------------------
 stages:
@@ -47,7 +47,7 @@ stages:
     - test -d "node_modules" && echo "Found/Exists" || echo "Does not exist"
     - |
       if [[ ! -d node_modules ]]; then
-        npm ci --cache .npm --prefer-offline
+        npm install --cache .npm --prefer-offline
       fi
 
 
@@ -64,21 +64,21 @@ stage-build:
 
 
 #-----------------------------------------------------------------------------------------------------------------------
-.stage-test:
+stage-test:
 #-----------------------------------------------------------------------------------------------------------------------
   stage: Test
   extends: .cache
   image: trion/ng-cli-karma:${CLI_VERSION}
   allow_failure: false
   script:
-    - ./node_modules/@angular/cli/bin/ng test --code-coverage --progress false --watch false
+    - ./node_modules/@angular/cli/bin/ng test --browsers=HeadlessChrome --progress false --watch false --code-coverage
   artifacts:
     paths:
       - coverage/
 
 
 #-----------------------------------------------------------------------------------------------------------------------
-.sonarqube:
+sonarqube:
 #-----------------------------------------------------------------------------------------------------------------------
   stage: Sonarqube
   image:
@@ -90,6 +90,8 @@ stage-build:
       - .sonar/cache
   script:
     - echo ${CI_PROJECT_DIR}
+    - ls -la
+    - ls coverage -la
     - sonar-scanner -Dsonar.qualitygate.wait=true -Dsonar.branch.name="${CI_COMMIT_REF_NAME}"
   allow_failure: true
   dependencies:
diff --git a/package.json b/package.json
index 1a341ee6..04b65d1f 100644
--- a/package.json
+++ b/package.json
@@ -5,7 +5,7 @@
     "ng": "ng",
     "start": "ng serve",
     "build": "ng build --prod --base-href /spfe/ --output-path ./dist --no-progress",
-    "test": "ng test --browsers=ChromeHeadless --watch=false --code-coverage",
+    "test": "ng test --browsers=HeadlessChrome --watch=false --code-coverage",
     "build:QA": "ng build --prod --configuration qa --base-href /spfe/ --output-path ./dist --no-progress",
     "testAndBuild": "npm run test && npm run build",
     "testAndBuild:QA": "npm run test && npm run build:QA",
@@ -32,6 +32,7 @@
     "core-js": "2.5.4",
     "file-saver": "^2.0.0",
     "font-awesome": "4.7.0",
+    "node-sass": "4.5.3",
     "primeicons": "1.0.0-beta.9",
     "primeng": "6.1.3",
     "rxjs": "6.2.2",
@@ -56,6 +57,7 @@
     "karma-jasmine": "1.1.1",
     "karma-jasmine-html-reporter": "1.2.0",
     "protractor": "5.3.0",
+    "puppeteer": "0.13.0",
     "ts-node": "7.0.0",
     "tslint": "5.10.0"
   }
diff --git a/sonar-project.properties b/sonar-project.properties
index eb86c744..37636805 100644
--- a/sonar-project.properties
+++ b/sonar-project.properties
@@ -2,18 +2,15 @@
 sonar.organization=openkonsequenz
 sonar.projectKey=openkonsequenz_standbyplanning.frontend
 # this is the name and version displayed in the SonarQube UI. Was mandatory prior to SonarQube 6.1.
-sonar.projectName=sonar.projectName=standbyplanning.frontend
+sonar.projectName=standbyplanning.frontend
 sonar.projectVersion=0.0.1_Snapshot
 
 # Language
-sonar.language=ts
-
+sonar.language=ts,css
 sonar.sourceEncoding=UTF-8
 sonar.sources=src
-sonar.exclusions=**/node_modules/**,src/environments/**,e2e/*.ts,**/*.spec.ts,**/test-data/*.ts,**/testing/*.ts,**/assets/js/*.js,**/*.model.*,**/*.action.*,**/*.module.*,**/*column-definition*,**/*animation*,**/*api-client.*,**/styles.scss,src/assets/userDocumentation/**
+sonar.exclusions=**/node_modules/**
 sonar.tests=src
 sonar.test.inclusions=**/*.spec.ts
-sonar.test.exclusions=
 sonar.ts.tslintconfigpath=tslint.json
-sonar.typescript.lcov.reportPaths=coverage/lcov.info
-
+sonar.javascript.lcov.reportPaths=coverage/lcov.info
diff --git a/src/karma.conf.js b/src/karma.conf.js
index 4ee67fd7..5975af59 100644
--- a/src/karma.conf.js
+++ b/src/karma.conf.js
@@ -10,6 +10,9 @@
 // Karma configuration file, see link for more information
 // https://karma-runner.github.io/1.0/config/configuration-file.html
 
+const process = require('process');
+process.env.CHROME_BIN = require('puppeteer').executablePath();
+
 module.exports = function (config) {
   config.set({
     basePath: '',
@@ -31,7 +34,13 @@ module.exports = function (config) {
     },
     reporters: ['progress', 'kjhtml'],
     port: 9876,
-    browsers:['ChromeHeadless'],
+    browsers: ['HeadlessChrome'],
+    customLaunchers:{
+      HeadlessChrome:{
+        base: 'ChromeHeadless',
+        flags: ['--no-sandbox']
+      }
+    },
     colors: true,
     logLevel: config.LOG_INFO,
     autoWatch: true,
-- 
GitLab