From 010313ada9f1dc486770533f9812a0b11e046bfb Mon Sep 17 00:00:00 2001 From: alexm Date: Wed, 26 Feb 2025 14:54:05 +0100 Subject: [PATCH] feat: refs #6695 implement parallel Cypress testing and enhance timeout configurations --- Jenkinsfile | 10 +++---- cypress.config.js | 29 ++++++++++++------ test/cypress/cypressParallel.sh | 10 +++++++ .../shelving/parking/parkingBasicData.spec.js | 8 +++-- test/cypress/run.sh | 30 +++++++++++++++++++ 5 files changed, 71 insertions(+), 16 deletions(-) create mode 100644 test/cypress/cypressParallel.sh create mode 100644 test/cypress/run.sh diff --git a/Jenkinsfile b/Jenkinsfile index dc8a10850..a7e2c1db4 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -116,11 +116,11 @@ pipeline { def image = docker.build('lilium-dev', '-f docs/Dockerfile.dev docs') sh "docker-compose ${env.COMPOSE_PARAMS} up -d" image.inside("--network ${env.COMPOSE_PROJECT}_default -e CI -e TZ") { - sh 'cypress run --browser chromium || true' - // sh ''' - // find test/cypress/integration -name "*.spec.js" | xargs -n 1 -P 2 -I {} sh -c "xvfb-run -a cypress run --headless --browser chromium --spec '{}'" - // wait - // ''' + // sh 'cypress run --browser chromium || true' + sh ''' + source test/cypress/cypressParallel.sh + cypressParallel 2 || true + ''' } } } diff --git a/cypress.config.js b/cypress.config.js index 7f430c743..0ac3aa3e8 100644 --- a/cypress.config.js +++ b/cypress.config.js @@ -1,6 +1,6 @@ import { defineConfig } from 'cypress'; -let urlHost, reporter, reporterOptions, defaultCommandTimeout; +let urlHost, reporter, reporterOptions, timeouts; if (process.env.CI) { urlHost = 'front'; @@ -17,7 +17,12 @@ if (process.env.CI) { json: false, }, }; - defaultCommandTimeout = 30000; + timeouts = { + defaultCommandTimeout: 30000, + requestTimeout: 30000, + responseTimeout: 60000, + pageLoadTimeout: 60000, + }; } else { urlHost = 'localhost'; reporter = 'cypress-mochawesome-reporter'; @@ -29,18 +34,19 @@ if (process.env.CI) { reportDir: 'test/cypress/reports', inlineAssets: true, }; - defaultCommandTimeout = 10000; + timeouts = { + defaultCommandTimeout: 10000, + requestTimeout: 10000, + responseTimeout: 30000, + pageLoadTimeout: 60000, + }; } export default defineConfig({ e2e: { baseUrl: `http://${urlHost}:9000`, experimentalStudio: false, - defaultCommandTimeout, trashAssetsBeforeRuns: false, - requestTimeout: 10000, - responseTimeout: 30000, - pageLoadTimeout: 60000, defaultBrowser: 'chromium', fixturesFolder: 'test/cypress/fixtures', screenshotsFolder: 'test/cypress/screenshots', @@ -60,7 +66,12 @@ export default defineConfig({ }, viewportWidth: 1280, viewportHeight: 720, + ...timeouts, + // setupNodeEvents(on, config) { + // process.env.NODE_OPTIONS = '--loader ts-node/esm'; + // return config; + // }, + includeShadowDom: true, + waitForAnimations: true, }, - defaultCommandTimeout, - numTestsKeptInMemory: 0, }); diff --git a/test/cypress/cypressParallel.sh b/test/cypress/cypressParallel.sh new file mode 100644 index 000000000..b38da6e75 --- /dev/null +++ b/test/cypress/cypressParallel.sh @@ -0,0 +1,10 @@ +cypressParallel() { + TEST_PATHS=( + 'test/cypress/integration/claim/claimAction.spec.js' + 'test/cypress/integration/claim/claimDevelopment.spec.js' + ) + # find 'test/cypress/integration' -name "*.spec.js" + printf "%s\n" "${TEST_PATHS[@]}" | xargs -P $1 -I {} sh -c 'xvfb-run -a cypress run --headless --browser chromium --spec {}' + # cypress run --headless --browser chromium --spec 'test/cypress/integration/shelving/parking/parkingBasicData.spec.js' + wait +} diff --git a/test/cypress/integration/shelving/parking/parkingBasicData.spec.js b/test/cypress/integration/shelving/parking/parkingBasicData.spec.js index e28d7eeca..81c158684 100644 --- a/test/cypress/integration/shelving/parking/parkingBasicData.spec.js +++ b/test/cypress/integration/shelving/parking/parkingBasicData.spec.js @@ -6,13 +6,16 @@ describe('ParkingBasicData', () => { beforeEach(() => { cy.login('developer'); cy.visit(`/#/shelving/parking/1/basic-data`); + cy.get('[data-cy="loading-spinner"]', { timeout: 10000 }).should( + 'not.be.visible', + ); }); it('should give an error if the code aldready exists', () => { cy.get(codeInput).eq(0).should('have.value', '700-01').clear(); cy.get(codeInput).eq(0).type('700-02'); cy.saveCard(); - cy.get('.q-notification__message').should('have.text', 'The code already exists'); + cy.checkNotification('The code already exists'); }); it('should edit the code and sector', () => { @@ -24,7 +27,8 @@ describe('ParkingBasicData', () => { cy.dataCy('Picking order_input').clear().type(80230); cy.saveCard(); - cy.get('.q-notification__message').should('have.text', 'Data saved'); + cy.checkNotification('Data saved'); + cy.get(sectorSelect).should('have.value', 'First sector'); cy.get(codeInput).should('have.value', '700-01'); cy.dataCy('Picking order_input').should('have.value', 80230); diff --git a/test/cypress/run.sh b/test/cypress/run.sh new file mode 100644 index 000000000..e66645410 --- /dev/null +++ b/test/cypress/run.sh @@ -0,0 +1,30 @@ +#!/bin/bash +CYPRESS_SPEC_FOLDER="test/cypress/integration" +cleanup() { + docker-compose -p e2e --project-directory . -f test/cypress/docker-compose.yml down || true +} + +trap cleanup SIGINT + +#CLEAN +rm -rf test/cypress/screenshots +rm -rf test/cypress/results +rm -rf junit + +#RUN +CI=true TZ=Europe/Madrid docker-compose -p e2e --project-directory . -f test/cypress/docker-compose.yml up -d +sleep 20 # FIXME: + +docker run -it --rm \ + -v "$(pwd)":/app \ + -e CI=true \ + -e TZ=Europe/Madrid \ + --network e2e_default \ + lilium-dev \ + bash -c ' + source test/cypress/cypressParallel.sh + cypressParallel 4 + ' +cleanup + + # cypress run --headless --browser chromium --spec \"test/cypress/integration\"