From 44d8606d1aa2e8e059e97e26fc0a6e6fbfd6457b Mon Sep 17 00:00:00 2001 From: Francis Cao Date: Wed, 28 Feb 2024 15:01:13 -0800 Subject: [PATCH] add cypress docker compose file --- .../cypress.config.ts | 4 ++ cypress/docker-compose.yml | 47 +++++++++++++++++++ cypress/e2e/login.cy.ts | 26 ++++++---- package.json | 3 +- 4 files changed, 69 insertions(+), 11 deletions(-) rename cypress.config.ts => cypress/cypress.config.ts (63%) create mode 100644 cypress/docker-compose.yml diff --git a/cypress.config.ts b/cypress/cypress.config.ts similarity index 63% rename from cypress.config.ts rename to cypress/cypress.config.ts index 5bed49b8..c52aeb49 100644 --- a/cypress.config.ts +++ b/cypress/cypress.config.ts @@ -4,4 +4,8 @@ export default defineConfig({ e2e: { baseUrl: 'http://localhost:3000', }, + env: { + umami_user: 'admin', + umami_password: 'pennydoodoo', + }, }); diff --git a/cypress/docker-compose.yml b/cypress/docker-compose.yml new file mode 100644 index 00000000..8ce1c938 --- /dev/null +++ b/cypress/docker-compose.yml @@ -0,0 +1,47 @@ +--- +version: '3' +services: + umami: + image: ghcr.io/umami-software/umami:postgresql-latest + ports: + - '3000:3000' + environment: + DATABASE_URL: postgresql://umami:umami@db:5432/umami + DATABASE_TYPE: postgresql + APP_SECRET: replace-me-with-a-random-string + depends_on: + db: + condition: service_healthy + restart: always + healthcheck: + test: ['CMD-SHELL', 'curl http://localhost:3000/api/heartbeat'] + interval: 5s + timeout: 5s + retries: 5 + db: + image: postgres:15-alpine + environment: + POSTGRES_DB: umami + POSTGRES_USER: umami + POSTGRES_PASSWORD: umami + volumes: + - umami-db-data:/var/lib/postgresql/data + restart: always + healthcheck: + test: ['CMD-SHELL', 'pg_isready -U $${POSTGRES_USER} -d $${POSTGRES_DB}'] + interval: 5s + timeout: 5s + retries: 5 + cypress: + image: 'cypress/included:13.6.0' + depends_on: + - umami + - db + environment: + - CYPRESS_baseUrl=http://localhost:3000 + entrypoint: /bin/sh -c "yarn install" + working_dir: /cypress + volumes: + - ./:/cypress +volumes: + umami-db-data: diff --git a/cypress/e2e/login.cy.ts b/cypress/e2e/login.cy.ts index f0490560..4bd6a6b7 100644 --- a/cypress/e2e/login.cy.ts +++ b/cypress/e2e/login.cy.ts @@ -1,12 +1,18 @@ describe('Login test', () => { - it('logs user in with correct credentials and logs user out', () => { - cy.visit('/login'); - cy.dataCy('input-username').type(Cypress.env('umami_user')); - cy.dataCy('input-password').type(Cypress.env('umami_password')); - cy.dataCy('button-submit').click(); - cy.url().should('eq', Cypress.config().baseUrl + '/dashboard'); - cy.dataCy('button-profile').click(); - cy.dataCy('item-logout').click(); - cy.url().should('eq', Cypress.config().baseUrl + '/login'); - }); + it( + 'logs user in with correct credentials and logs user out', + { + defaultCommandTimeout: 10000, + }, + () => { + cy.visit('/login'); + cy.dataCy('input-username').type(Cypress.env('umami_user')); + cy.dataCy('input-password').type(Cypress.env('umami_password')); + cy.dataCy('button-submit').click(); + cy.url().should('eq', Cypress.config().baseUrl + '/dashboard'); + cy.dataCy('button-profile').click(); + cy.dataCy('item-logout').click(); + cy.url().should('eq', Cypress.config().baseUrl + '/login'); + }, + ); }); diff --git a/package.json b/package.json index 24946e3f..16658e2e 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,8 @@ "lint": "next lint --quiet", "prepare": "node -e \"if (process.env.NODE_ENV !== 'production'){process.exit(1)} \" || husky install", "postbuild": "node scripts/postbuild.js", - "cypress-open": "cypress open" + "cypress-open": "cypress open cypress run --config-file cypress/cypress.config.ts", + "cypress-run": "cypress run cypress run --config-file cypress/cypress.config.ts" }, "lint-staged": { "**/*.{js,jsx,ts,tsx}": [