From 4e5959fac46a93b8e8a7c8d2978099da33c8dd3e Mon Sep 17 00:00:00 2001 From: fastium Date: Tue, 24 Jun 2025 18:48:43 +0200 Subject: [PATCH] test(webapp): provide an environment variable for e2e tests --- .env.template | 1 + web-app/.gitlab-ci.yml | 7 ++----- web-app/cypress/e2e/fetch_process.cy.ts | 2 +- web-app/test.md | 10 ++++++++++ 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/.env.template b/.env.template index e267436..f5f6a17 100644 --- a/.env.template +++ b/.env.template @@ -10,3 +10,4 @@ REST_USERNAME= REST_PASSWORD= REST_URL= REST_PAGE= +CYPRESS_TEST_URL= diff --git a/web-app/.gitlab-ci.yml b/web-app/.gitlab-ci.yml index 2969ba0..e50d881 100644 --- a/web-app/.gitlab-ci.yml +++ b/web-app/.gitlab-ci.yml @@ -40,17 +40,14 @@ web-app-unit-tests: web-app-e2e-tests: image: $NODE_IMAGE stage: web-app-tests - - # services: - # - name: $DOCKER_IMAGE - # alias: app script: + - export CYPRESS_TEST_URL=$TEST_URL - echo "Running e2e tests" - apt-get update - apt-get install curl - cd ./web-app - npm install --include=dev - echo "Wait web-app app is running" - - for i in {1..6}; do curl -f https://app.mse.kb28.ch/ && break || sleep 5; done + - for i in {1..6}; do curl -f $CYPRESS_TEST_URL && break || sleep 5; done - echo "App is running" - npm run test:e2e diff --git a/web-app/cypress/e2e/fetch_process.cy.ts b/web-app/cypress/e2e/fetch_process.cy.ts index 0e3cfc3..dc81896 100644 --- a/web-app/cypress/e2e/fetch_process.cy.ts +++ b/web-app/cypress/e2e/fetch_process.cy.ts @@ -2,7 +2,7 @@ describe("Test fetch measurments button in the main page", () => { beforeEach(() => { - cy.visit("https://app.mse.kb28.ch"); + cy.visit(Cypress.env("TEST_URL")); }); it("Fetch timeseries with valid user-room-device", () => { diff --git a/web-app/test.md b/web-app/test.md index 1d605e5..a2efbde 100644 --- a/web-app/test.md +++ b/web-app/test.md @@ -25,6 +25,16 @@ cd ./web-app npm install --inlude=dev ``` +### Before Running Tests +A test url is needed to perform the tests in local: +```bash +export CYPRESS_TEST_URL=http://your-test-url.com +``` +Note: most of the time, if you are testing in local, you can use: +```bash +export CYPRESS_TEST_URL=http://localhost:8080/ +``` + ### Run unit Tests ```bash npm run test:unit