From 1df51b6b585bc6e32aec478c1ca3b9df0b4e8dda Mon Sep 17 00:00:00 2001 From: Florian Giroud <6267288+fgiroud@users.noreply.github.com> Date: Thu, 8 Jul 2021 14:13:55 +0200 Subject: [PATCH] Speed-up testing time for Cypress in CI/CD (#4042) * Added an environment variable to disable projects cleanup on CI/CD, improve performances * revert DISABLE_PROJECT_CLEANUP to be 0 by default Co-authored-by: Kush Trivedi <44091822+kushthedude@users.noreply.github.com> --- docs/docs/technical-reference/functional-tests.md | 2 ++ main/tests/cypress/cypress.json | 4 +++- main/tests/cypress/cypress/support/index.js | 6 +++++- refine | 2 +- 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/docs/docs/technical-reference/functional-tests.md b/docs/docs/technical-reference/functional-tests.md index 8cece4b5e..afdfbe43c 100644 --- a/docs/docs/technical-reference/functional-tests.md +++ b/docs/docs/technical-reference/functional-tests.md @@ -179,6 +179,8 @@ Cypress execution can be configured with environment variables, they can be decl Available variables are - OPENREFINE_URL, determine on which scheme://url:port to access OpenRefine, default to http://localhost:333 +- DISABLE_PROJECT_CLEANUP, If set to 1, projects will not be deleted after each run. Default to 0 to keep the OpenRefine instance clean + Cypress contains [exaustive documentation](https://docs.cypress.io/guides/guides/environment-variables.html#Setting) about configuration, but here are two simple ways to configure the execution of the tests: diff --git a/main/tests/cypress/cypress.json b/main/tests/cypress/cypress.json index 4b8f38204..51d4e0445 100644 --- a/main/tests/cypress/cypress.json +++ b/main/tests/cypress/cypress.json @@ -6,6 +6,8 @@ "openMode": 0 }, "env": { - "OPENREFINE_URL": "http://localhost:3333" + "OPENREFINE_URL": "http://localhost:3333", + "DISABLE_PROJECT_CLEANUP": 0 + } } diff --git a/main/tests/cypress/cypress/support/index.js b/main/tests/cypress/cypress/support/index.js index dbbd38301..559b0ddd6 100644 --- a/main/tests/cypress/cypress/support/index.js +++ b/main/tests/cypress/cypress/support/index.js @@ -33,7 +33,11 @@ beforeEach(() => { }); afterEach(() => { - cy.cleanupProjects(); + // DISABLE_PROJECT_CLEANUP is used to disable projects deletion + // Mostly used in CI/CD for performances + if(parseInt(Cypress.env('DISABLE_PROJECT_CLEANUP')) != 1){ + cy.cleanupProjects(); + } }); before(() => { diff --git a/refine b/refine index 3a459db72..6bbfea071 100755 --- a/refine +++ b/refine @@ -526,7 +526,7 @@ ui_tests() { # Cypress needs a unique group id # We're hashing the list of files to generate such Group Id CYPRESS_GROUP=$(echo $CYPRESS_BROWSER$CYPRESS_SPECS | shasum) - CYPRESS_RUN_CMD="yarn --cwd ./main/tests/cypress run cypress run --spec "$CYPRESS_SPECS" --browser $CYPRESS_BROWSER --group "$CYPRESS_GROUP" --headless --quiet --reporter list --env OPENREFINE_URL=http://$REFINE_HOST_INTERNAL:$REFINE_PORT" + CYPRESS_RUN_CMD="yarn --cwd ./main/tests/cypress run cypress run --spec "$CYPRESS_SPECS" --browser $CYPRESS_BROWSER --group "$CYPRESS_GROUP" --headless --quiet --reporter list --env DISABLE_PROJECT_CLEANUP=1,OPENREFINE_URL=http://$REFINE_HOST_INTERNAL:$REFINE_PORT" if [ "$CYPRESS_RECORD" = "1" ] ; then # if tests are recorded, project id is added to env vars, and --record flag is added to the cmd-line export CYPRESS_PROJECT_ID=$CYPRESS_PROJECT_ID