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

76
Jenkinsfile vendored
View File

@ -107,25 +107,20 @@ pipeline {
}
}
stage('E2E: Basic') {
steps {
script {
runTestsInParallel([
// 'test/cypress/integration/vnComponent/',
'test/cypress/integration/outLogin/',
])
}
}
}
// stage('E2E: Basic') {
// steps {
// script {
// runTestsInParallel([
// // 'test/cypress/integration/vnComponent/',
// 'test/cypress/integration/outLogin/',
// ])
// }
// }
// }
stage('E2E: Sections') {
steps {
script {
runTestsInParallel([
'test/cypress/integration/claim/',
'test/cypress/integration/client/',
'test/cypress/integration/entry/',
'test/cypress/integration/invoiceIn/',
])
runTestsInParallel(2)
}
}
@ -179,10 +174,8 @@ def cleanDockerE2E() {
def projectBranch = "${PROJECT_NAME}-${env.BRANCH_NAME}".toLowerCase()
// STOP AND REMOVE
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 """
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) {
if (!folders) { // Si es null o vacío, asigna valores por defecto
folders =sh(script: "ls -d test/cypress/integration/*/ || echo ''", returnStdout: true).trim().split('\n')
def runTestsInParallel(int numParallelGroups) {
def folders = sh(script: "ls -d test/cypress/integration/*/ || echo ''", returnStdout: true).trim().split('\n').findAll { it }
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 = [:]
folders.each { testFolder ->
if (testFolder.trim()) {
def folderName = testFolder.replaceAll('test/cypress/integration/', '').replaceAll('/', '')
folderName = folderName.replaceAll('[^a-zA-Z0-9_-]', '') // Seguridad en nombres de red
tasks["e2e_${folderName}"] = {
script {
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 front"
sh "CYPRESS_SPEC=test/cypress/integration/${folderName}/**/*.spec.js docker-compose -p ${env.NETWORK}_${folderName} -f docker-compose.e2e.yml up e2e"
checkErrors(folderName)
groups.eachWithIndex { group, index ->
tasks["parallel_group_${index + 1}"] = {
script {
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 front"
sh "CYPRESS_SPEC=test/cypress/integration/${folderName}/**/*.spec.js docker-compose -p ${env.NETWORK}_${folderName} -f docker-compose.e2e.yml up e2e"
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
}
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()
if (containerId) {

View File

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