From b0a1fe486e2f24b0281a7ddcf859dee3d3c22b47 Mon Sep 17 00:00:00 2001
From: OZGCloud <ozgcloud@mgm-tp.com>
Date: Wed, 11 Oct 2023 10:54:19 +0200
Subject: [PATCH] OZG-3934 OZG-4395 adjust JenkinsFile - run Tests parrallel

---
 goofy-client/apps/goofy-e2e/Jenkinsfile | 169 ++++++++++++------------
 1 file changed, 82 insertions(+), 87 deletions(-)

diff --git a/goofy-client/apps/goofy-e2e/Jenkinsfile b/goofy-client/apps/goofy-e2e/Jenkinsfile
index e6fec69134..1711691dcc 100644
--- a/goofy-client/apps/goofy-e2e/Jenkinsfile
+++ b/goofy-client/apps/goofy-e2e/Jenkinsfile
@@ -190,73 +190,67 @@ pipeline {
             }
         }
 
-//        stage('Pausing to wait for ozg-operator') {
-//			when {
-//                expression { !SKIP_RUN }
-//            }
-//            steps {
-//                sleep(time: 3, unit: 'MINUTES')
-//            }
-//        }
-
-        stage('Run E2E-EA Tests') {
+        stage('Run E2E-Tests') {
             when {
                 expression { !SKIP_RUN }
             }
-			steps {
-				catchError(buildResult: 'FAILURE', stageResult: 'FAILURE') {
-					script {
-						def bezeichner = env.EA_BEZEICHNER
-						def dbPort = 27018
-
-						forwardServices(generateNamespace(bezeichner), dbPort)
-
-						runTests(bezeichner, 'einheitlicher-ansprechpartner', dbPort, env.STAGE_NAME)
-					}
-				}
-			}
-			post {
-				failure {
-					script {
-						FAILED_PARALLEL_STAGE += "${env.STAGE_NAME} "
-					}
-				}
-				always {
-					script {
-						publishE2ETestResult("einheitlicher-ansprechpartner", "Goofy E2E-Tests EA")
-					}
-				}
-			}
-        }
+            failFast false
 
-        stage('Run E2E-Main Tests') {
-            when {
-                expression { !SKIP_RUN }
+            parallel {
+                stage('E2E-EA') {
+                    steps {
+                        catchError(buildResult: 'FAILURE', stageResult: 'FAILURE') {
+                            script {
+                                def bezeichner = env.EA_BEZEICHNER
+                                def dbPort = 27018
+
+                                forwardServices(generateNamespace(bezeichner), dbPort)
+
+                                runTests(bezeichner, 'einheitlicher-ansprechpartner', dbPort, env.STAGE_NAME)
+                            }
+                        }
+                    }
+                    post {
+                        failure {
+                            script {
+                                FAILED_PARALLEL_STAGE += "${env.STAGE_NAME} "
+                            }
+                        }
+                        always {
+                            script {
+                                publishE2ETestResult("einheitlicher-ansprechpartner", "Goofy E2E-Tests EA")
+                            }
+                        }
+                    }
+                }
+
+                stage('E2E-Main') {
+                    steps {
+                        catchError(buildResult: 'FAILURE', stageResult: 'FAILURE') {
+                            script {
+                                def bezeichner = env.MAIN_BEZEICHNER
+                                def dbPort = 27019
+
+                                forwardServices(generateNamespace(bezeichner), dbPort)
+
+                                runTests(bezeichner, 'main-tests', dbPort, env.STAGE_NAME)
+                            }
+                        }
+                    }
+                    post {
+                        failure {
+                            script {
+                                FAILED_PARALLEL_STAGE += "${env.STAGE_NAME} "
+                            }
+                        }
+                        always {
+                            script {
+                                publishE2ETestResult("main-tests", "Goofy E2E-Tests main")
+                            }
+                        }
+                    }
+                }
             }
-			steps {
-				catchError(buildResult: 'FAILURE', stageResult: 'FAILURE') {
-					script {
-						def bezeichner = env.MAIN_BEZEICHNER
-						def dbPort = 27019
-
-						forwardServices(generateNamespace(bezeichner), dbPort)
-
-						runTests(bezeichner, 'main-tests', dbPort, env.STAGE_NAME)
-					}
-				}
-			}
-			post {
-				failure {
-					script {
-						FAILED_PARALLEL_STAGE += "${env.STAGE_NAME} "
-					}
-				}
-				always {
-					script {
-						publishE2ETestResult("main-tests", "Goofy E2E-Tests main")
-					}
-				}
-			}
         }
 
         stage('Delete E2E Namespaces') {
@@ -611,18 +605,14 @@ Void publishE2ETestResult(String reportFolder, String reportName) {
 }
 
 String runTests(String bezeichner, String reportFolder, Integer dbPort, String stageName) {
-    generateCypressConfig(bezeichner, reportFolder, dbPort)
+    def config = generateCypressConfig(bezeichner, reportFolder, dbPort)
 	def specFolder = "apps/goofy-e2e/src/e2e/${reportFolder}"
 
     try {
-        dir("goofy-client") {
-			sh "npx cypress version"
-			// sh "REPORT_FOLDER=${reportFolder} node apps/goofy-e2e/src/support/delete-old-reports.ts"
-			sh "NO_COLOR=1 npx cypress run --project apps/goofy-e2e --spec ${specFolder}"
-			// sh "test=$(echo $?)"
-			// sh "REPORT_FOLDER=${reportFolder} node apps/goofy-e2e/src/support/pre-merge.ts"
-			// sh "mochawesome-merge apps/goofy-e2e/reports/${npm_config_report_folder}/mochawesome-report/**/*.json > apps/goofy-e2e/reports/${npm_config_report_folder}/report.json"
-			// sh "marge apps/goofy-e2e/reports/${npm_config_report_folder}/report.json -f report -o apps/goofy-e2e/reports/${npm_config_report_folder}"
+        dir('goofy-client'){
+      	    sh "npm run cypress:version"
+			sh "ls -al"
+			sh "npm run cypress:ci-run --CONFIG_FILE=${configFile} --REPORT_FOLDER=${reportFolder}"
         }
     } catch (Exception e) {
         printNpmDebugLog()
@@ -661,34 +651,39 @@ String cutBranchNameForKeycloakRealm(String branchName, String stageName) {
 
 String generateCypressConfig(String bezeichner, String testFolder, Integer dbPort) {
     def namespace = generateNamespace(bezeichner)
-    def configName = "cypress.config.json"
+	def configName = "cypress-ci-"+testFolder+".json"
 
-    dir('goofy-client/apps/goofy-e2e/'){
-        def config = readJSON file: 'cypress.config.json'
+	dir('goofy-client/apps/goofy-e2e/'){
+		def config = readJSON file: 'cypress-ci.json'
 
 		def plutoDatabaseSecret = getPlutoDatabaseSecret(namespace);
 		def decodedPassword = decodeString(plutoDatabaseSecret.password);
 		def parsablePassword = makePasswordUrlConform(decodedPassword);
 
-        config.baseUrl = "https://${bezeichner}.${env.CLUSTER_BASE_URL}" as String
-        config.env.dbUrl = "mongodb://${decodeString(plutoDatabaseSecret.username)}:${parsablePassword}@localhost:${dbPort}/admin?ssl=false&directConnection=true" as String
+		config.baseUrl = "https://${bezeichner}.${env.CLUSTER_BASE_URL}" as String
+		config.env.dbUrl = "mongodb://${decodeString(plutoDatabaseSecret.username)}:${parsablePassword}@localhost:${dbPort}/admin?ssl=false&directConnection=true" as String
 		config.env.database = "pluto-database" as String
-        config.env.keycloakUrl = "https://${env.SSO_URL}/" as String
-        config.env.keycloakRealm = namespace as String
-        config.env.keycloakClient = "alfa" as String
+		config.env.keycloakUrl = "https://${env.SSO_URL}/" as String
+		config.env.keycloakRealm = namespace as String
+		config.env.keycloakClient = "alfa" as String
 		config.env.sabineUuid = getKeycloakUuid(namespace, "sabine") as String
-		config.video = true
-        config.videosFolder = "./reports/${testFolder}/videos" as String
-	    config.screenshotsFolder = "./reports/${testFolder}/screenshots" as String
-        config.reporterOptions.reportDir = "./reports/${testFolder}/mochawesome-report" as String
+		config.video = false
+		config.videosFolder = "./reports/${testFolder}/videos" as String
+		config.screenshotsFolder = "./reports/${testFolder}/screenshots" as String
+		config.reporterOptions.reportDir = "./reports/${testFolder}/mochawesome-report" as String
 		config.reporterOptions.quite = true
 		config.reporterOptions.overwrite = false
+		config.specPattern = 'src/e2e/**/*.cy.{js,jsx,ts,tsx}'
 
-        config.env.put("search", getElasticsearchEnv(namespace))
-        config.env.put("userManager", getUserManagerEnv(namespace, dbPort))
+		config.env.put("search", getElasticsearchEnv(namespace))
+		config.env.put("userManager", getUserManagerEnv(namespace, dbPort))
 
-        writeJSON file: configName, json: config
-    }
+		writeJSON file: configName, json: config
+
+		sh "cat ${configName}"
+	}
+
+	return "cypress-ci-"+testFolder+".config.ts"
 }
 
 String makePasswordUrlConform(String password) {
-- 
GitLab