From b5342cc130f5c5eef55bb693a2666f2a43fcfc57 Mon Sep 17 00:00:00 2001 From: alexm Date: Thu, 20 Feb 2025 14:06:37 +0100 Subject: [PATCH] fix: refs #6695 update Cypress configuration and Docker setup for improved testing --- Jenkinsfile | 79 +++++++++---------- cypress.config.js | 2 +- quasar.config.js | 2 +- test/cypress/Dockerfile | 11 +-- test/cypress/back/datasources.json | 2 +- .../cypress/docker-compose.yml | 10 +-- 6 files changed, 47 insertions(+), 59 deletions(-) rename docker-compose.e2e.yml => test/cypress/docker-compose.yml (74%) diff --git a/Jenkinsfile b/Jenkinsfile index 235a52398..79d42181c 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -64,58 +64,53 @@ pipeline { } steps { sh 'pnpm install --prefer-offline' + sh 'pnpm exec cypress install' } } - // stage('Test: Unit') { - // when { - // expression { !PROTECTED_BRANCH } - // } - // environment { - // NODE_ENV = "" - // } - // steps { - // sh 'pnpm run test:unit:ci' - // } - // post { - // always { - // junit( - // testResults: 'junitresults.xml', - // allowEmptyResults: true - // ) - // } - // } - // } - stage('Test: E2E') { + stage('Test') { when { expression { !PROTECTED_BRANCH } } environment { NODE_ENV = "" - CREDENTIALS = credentials('docker-registry') } - steps { - script { - def packageJson = readJSON file: 'package.json' - env.NETWORK = "${PROJECT_NAME}-${env.BRANCH_NAME}-${env.BUILD_ID}" - - sh "docker-compose -p ${env.NETWORK} -f docker-compose.e2e.yml up -d" - - def networkLowerCase = env.NETWORK.toLowerCase() - def image = docker.build('cypress-setup:latest', '-f ./test/cypress/Dockerfile .') - image.inside(""" - --network ${networkLowerCase}_default - -e TZ=Europe/Madrid - -e DOCKER=true - -e CI=true - """.stripIndent()) { - sh 'pnpm exec cypress install' - sh 'pnpm exec cypress run --browser chromium' + parallel { + stage('Unit') { + steps { + sh 'pnpm run test:unit:ci' + } + post { + always { + junit( + testResults: 'junitresults.xml', + allowEmptyResults: true + ) + } } } - } - post { - always { - sh "docker-compose -p ${env.NETWORK} -f docker-compose.e2e.yml down" + stage('E2E') { + environment { + CREDENTIALS = credentials('docker-registry') + CI = "true" + TZ = 'Europe/Madrid' + COMPOSE_PROJECT = "${PROJECT_NAME}-${env.BRANCH_NAME}-${env.BUILD_ID}".toLowerCase() + COMPOSE_PARAMS = "--project-name ${env.COMPOSE_PROJECT} --project-directory . --file test/cypress/docker-compose.yml" + } + steps { + script { + sh "docker-compose ${env.COMPOSE_PARAMS} up -d" + + def image = docker.build('cypress-setup', '-f ./test/cypress/Dockerfile .') + image.inside("--network ${env.COMPOSE_PROJECT}_default -e TZ -e CI") { + sh 'cypress run --browser chromium --spec test/cypress/integration/claim/claimAction.spec.js' + } + } + } + post { + always { + sh "docker-compose ${env.COMPOSE_PARAMS} down" + } + } } } } diff --git a/cypress.config.js b/cypress.config.js index fef415092..d62444869 100644 --- a/cypress.config.js +++ b/cypress.config.js @@ -2,7 +2,7 @@ import { defineConfig } from 'cypress'; // https://docs.cypress.io/app/tooling/reporters // https://docs.cypress.io/app/references/configuration // https://www.npmjs.com/package/cypress-mochawesome-reporter -const baseUrl = `http://${process.env.DOCKER ? 'front' : 'localhost'}:9000`; +const baseUrl = `http://${process.env.CI ? 'front' : 'localhost'}:9000`; export default defineConfig({ e2e: { diff --git a/quasar.config.js b/quasar.config.js index 5df9250ad..8b6125a90 100644 --- a/quasar.config.js +++ b/quasar.config.js @@ -11,7 +11,7 @@ import { configure } from 'quasar/wrappers'; import VueI18nPlugin from '@intlify/unplugin-vue-i18n/vite'; import path from 'path'; -const target = `http://${process.env.DOCKER ? 'back' : 'localhost'}:3000`; +const target = `http://${process.env.CI ? 'back' : 'localhost'}:3000`; export default configure(function (/* ctx */) { return { diff --git a/test/cypress/Dockerfile b/test/cypress/Dockerfile index 33a8f2210..7d630f479 100644 --- a/test/cypress/Dockerfile +++ b/test/cypress/Dockerfile @@ -1,12 +1,5 @@ FROM alexmorenovn/vndev:latest -WORKDIR /app - -# Copiar los archivos de package.json y pnpm-lock.yaml para evitar reinstalar dependencias innecesariamente -COPY package.json pnpm-lock.yaml ./ - -# Instalar solo Cypress sin instalar todas las dependencias del proyecto -RUN pnpm install --frozen-lockfile && pnpm exec cypress install - -# Definir el directorio de trabajo por defecto +RUN pnpm install --global cypress@13.6.6 && cypress install + WORKDIR /app diff --git a/test/cypress/back/datasources.json b/test/cypress/back/datasources.json index 1fbacd099..fa7b81e1c 100644 --- a/test/cypress/back/datasources.json +++ b/test/cypress/back/datasources.json @@ -7,7 +7,7 @@ "connector": "vn-mysql", "database": "vn", "debug": false, - "host": "vn-database", + "host": "db", "port": "3306", "username": "root", "password": "root", diff --git a/docker-compose.e2e.yml b/test/cypress/docker-compose.yml similarity index 74% rename from docker-compose.e2e.yml rename to test/cypress/docker-compose.yml index 0eeb676f1..e09f03273 100644 --- a/docker-compose.e2e.yml +++ b/test/cypress/docker-compose.yml @@ -6,7 +6,7 @@ services: - ./test/cypress/storage:/salix/storage - ./test/cypress/back/datasources.json:/salix/loopback/server/datasources.json depends_on: - - vn-database + - db front: image: alexmorenovn/vndev:latest command: quasar dev @@ -14,7 +14,7 @@ services: - .:/app working_dir: /app environment: - - TZ=Europe/Madrid - - DOCKER=true - vn-database: - image: registry.verdnatura.es/salix-db:dev + - TZ + - CI + db: + image: registry.verdnatura.es/salix-db:25.10.0-build1343