refactor: refs #6695 update E2E test execution to support parallel groups and improve
gitea/salix-front/pipeline/pr-dev There was a failure building this commit Details

This commit is contained in:
Alex Moreno 2025-02-13 09:24:14 +01:00
parent 4d0b03a480
commit 8eb60e1700
2 changed files with 44 additions and 33 deletions

66
Jenkinsfile vendored
View File

@ -107,25 +107,20 @@ pipeline {
} }
} }
stage('E2E: Basic') { // stage('E2E: Basic') {
steps { // steps {
script { // script {
runTestsInParallel([ // runTestsInParallel([
// 'test/cypress/integration/vnComponent/', // // 'test/cypress/integration/vnComponent/',
'test/cypress/integration/outLogin/', // 'test/cypress/integration/outLogin/',
]) // ])
} // }
} // }
} // }
stage('E2E: Sections') { stage('E2E: Sections') {
steps { steps {
script { script {
runTestsInParallel([ runTestsInParallel(2)
'test/cypress/integration/claim/',
'test/cypress/integration/client/',
'test/cypress/integration/entry/',
'test/cypress/integration/invoiceIn/',
])
} }
} }
@ -179,10 +174,8 @@ def cleanDockerE2E() {
def projectBranch = "${PROJECT_NAME}-${env.BRANCH_NAME}".toLowerCase() def projectBranch = "${PROJECT_NAME}-${env.BRANCH_NAME}".toLowerCase()
// STOP AND REMOVE // STOP AND REMOVE
sh """ sh """
docker ps -a --filter 'name=^${projectBranch}' | awk 'NR>1 {print \"\$1\"}' | xargs -r docker rm -v || true docker ps -a --filter 'name=^${projectBranch}' | awk 'NR>1 {print \"\$1\"}' | xargs -r -I {} sh -c 'docker stop {} && docker rm -v {}' || true
""" """
sh """ sh """
docker network ls --filter 'name=^${projectBranch}' | awk 'NR>1 {print \"\$1\"}' | xargs -r docker network rm || true docker network ls --filter 'name=^${projectBranch}' | awk 'NR>1 {print \"\$1\"}' | xargs -r docker network rm || true
""" """
@ -190,23 +183,39 @@ def cleanDockerE2E() {
} }
} }
def runTestsInParallel(List<String> folders) { def runTestsInParallel(int numParallelGroups) {
if (!folders) { // Si es null o vacío, asigna valores por defecto def folders = sh(script: "ls -d test/cypress/integration/*/ || echo ''", returnStdout: true).trim().split('\n').findAll { it }
folders =sh(script: "ls -d test/cypress/integration/*/ || echo ''", returnStdout: true).trim().split('\n')
if (folders.isEmpty()) {
echo "No se encontraron carpetas de pruebas."
return
} }
// Divide las carpetas en grupos para paralelizar
def groups = folders.collate(Math.ceil(folders.size() / numParallelGroups) as int)
def tasks = [:] def tasks = [:]
folders.each { testFolder -> groups.eachWithIndex { group, index ->
if (testFolder.trim()) { tasks["parallel_group_${index + 1}"] = {
def folderName = testFolder.replaceAll('test/cypress/integration/', '').replaceAll('/', '')
folderName = folderName.replaceAll('[^a-zA-Z0-9_-]', '') // Seguridad en nombres de red
tasks["e2e_${folderName}"] = {
script { script {
env.CYPRESS_SPEC="test/cypress/integration/${folderName}/**/*.spec.js" group.each { testFolder ->
def folderName = testFolder.replaceAll('test/cypress/integration/', '').replaceAll('/', '')
folderName = folderName.replaceAll('[^a-zA-Z0-9_-]', '') // Sanitización de nombres
stage("Run ${folderName}") {
try {
env.CYPRESS_SPEC = "test/cypress/integration/${folderName}/**/*.spec.js"
sh "docker-compose -p ${env.NETWORK}_${folderName} -f docker-compose.e2e.yml up -d back" sh "docker-compose -p ${env.NETWORK}_${folderName} -f docker-compose.e2e.yml up -d back"
sh "docker-compose -p ${env.NETWORK}_${folderName} -f docker-compose.e2e.yml up -d front" sh "docker-compose -p ${env.NETWORK}_${folderName} -f docker-compose.e2e.yml up -d front"
sh "CYPRESS_SPEC=test/cypress/integration/${folderName}/**/*.spec.js docker-compose -p ${env.NETWORK}_${folderName} -f docker-compose.e2e.yml up e2e" sh "CYPRESS_SPEC=test/cypress/integration/${folderName}/**/*.spec.js docker-compose -p ${env.NETWORK}_${folderName} -f docker-compose.e2e.yml up e2e"
checkErrors(folderName) checkErrors(folderName)
} catch (Exception e) {
echo "Error en la ejecución de ${folderName}: ${e.message}"
currentBuild.result = 'UNSTABLE'
} finally {
sh "docker-compose -p ${env.NETWORK}_${folderName} -f docker-compose.e2e.yml down || true"
}
}
} }
} }
} }
@ -215,6 +224,7 @@ def runTestsInParallel(List<String> folders) {
parallel tasks parallel tasks
} }
def checkErrors(String folderName){ def checkErrors(String folderName){
def containerId = sh(script: "docker-compose -p ${env.NETWORK}_${folderName} -f docker-compose.e2e.yml ps -q e2e", returnStdout: true).trim() def containerId = sh(script: "docker-compose -p ${env.NETWORK}_${folderName} -f docker-compose.e2e.yml ps -q e2e", returnStdout: true).trim()
if (containerId) { if (containerId) {

View File

@ -28,6 +28,7 @@ services:
- TZ=Europe/Madrid - TZ=Europe/Madrid
volumes: volumes:
- .:/app - .:/app
- cypress-cache:/root/.cache/Cypress
working_dir: /app working_dir: /app
vn-database: vn-database:
image: alexmorenovn/vn_db:latest image: alexmorenovn/vn_db:latest