Skip to content

Commit

Permalink
Adding Cypress integration tests (#354)
Browse files Browse the repository at this point in the history
  • Loading branch information
antoinejaussoin authored Mar 4, 2022
1 parent 7c39cbb commit 43e6a6e
Show file tree
Hide file tree
Showing 20 changed files with 1,552 additions and 2 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/alpha.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: 'Alpha Build'

on:
push:
branches: [v4120/db_conventions]
branches: [v4120/integrationxxx]

jobs:
build:
Expand Down Expand Up @@ -54,6 +54,9 @@ jobs:
tags: retrospected/frontend:alpha
platforms: linux/amd64
push: true

- name: Run Integration Tests
run: docker-compose -f ./integration/docker-compose.ci.alpha.yml up --exit-code-from cypress

- name: Trivy - Frontend
uses: aquasecurity/trivy-action@master
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/canary.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ jobs:
platforms: linux/amd64,linux/arm64,linux/arm/v7
push: true

- name: Run Integration Tests
run: docker-compose -f ./integration/docker-compose.ci.canary.yml up --exit-code-from cypress

- name: Trivy - Frontend
uses: aquasecurity/trivy-action@master
with:
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,6 @@ jobs:
tags: retrospected/maintenance:latest,retrospected/maintenance:${{ steps.package.outputs.current-version }}
platforms: linux/amd64,linux/arm64,linux/arm/v7
push: true

- name: Run Integration Tests
run: docker-compose -f ./integration/docker-compose.ci.master.yml up --exit-code-from cypress
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ This will run a demo version, which you can turn into a fully licenced version b

- Changing naming convention for the database. All fields and tables are now `snake_case`.
- Simplified the configuration of TypeORM, removed the generation of `ormconfig.json`.
- Added Integration tests using Cypress to catch Docker-specific errors and have some basic smoke tests.

### Version 4.11.5 (hotfix)

Expand Down
1 change: 1 addition & 0 deletions integration/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.mp4
11 changes: 11 additions & 0 deletions integration/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
master:
docker-compose -f docker-compose.ci.master.yml up --exit-code-from cypress

local:
docker build -f ../backend/Dockerfile -t retrospected/backend:local ../backend
docker build -f ../frontend/Dockerfile -t retrospected/frontend:local ../frontend
docker-compose down
docker-compose up -d
yarn
yarn test
docker-compose down
3 changes: 3 additions & 0 deletions integration/cypress.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"baseUrl": "http://localhost:1800"
}
5 changes: 5 additions & 0 deletions integration/cypress/fixtures/example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "Using fixtures to represent data",
"email": "[email protected]",
"body": "Fixtures are a great way to mock data for responses to routes"
}
30 changes: 30 additions & 0 deletions integration/cypress/integration/test.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
describe('Home Page', () => {
it('Should load correctly', () => {
cy.visit('/')

cy.get('div.marketing-content')
.should('contain', 'Real-time Retrospectives')
});

it('Should login and write a post', () => {
cy.get('.MuiButton-root').click();
cy.get('.MuiTabs-flexContainer > [tabindex="-1"]').click();
cy.get('.MuiInput-input').focus().type('Zelensky');
cy.get('.MuiDialogContent-root .MuiButton-root').click();

// Home page should display the user name
cy.get('#content').should('contain', 'Welcome, Zelensky');

// And then allow creating a new session
cy.get('button').contains('Create a new session').click();

// And write a post
cy.get('input[placeholder*="What went well"]').focus().type('Slava Ukraini!{enter}');

// Reload the page
cy.reload();

// The post should still be there
cy.get('#content').should('contain', 'Slava Ukraini!');
});
});
22 changes: 22 additions & 0 deletions integration/cypress/plugins/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/// <reference types="cypress" />
// ***********************************************************
// This example plugins/index.js can be used to load plugins
//
// You can change the location of this file or turn off loading
// the plugins file with the 'pluginsFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/plugins-guide
// ***********************************************************

// This function is called when a project is opened or re-opened (e.g. due to
// the project's config changing)

/**
* @type {Cypress.PluginConfig}
*/
// eslint-disable-next-line no-unused-vars
module.exports = (on, config) => {
// `on` is used to hook into various events Cypress emits
// `config` is the resolved Cypress config
}
25 changes: 25 additions & 0 deletions integration/cypress/support/commands.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// ***********************************************
// This example commands.js shows you how to
// create various custom commands and overwrite
// existing commands.
//
// For more comprehensive examples of custom
// commands please read more here:
// https://on.cypress.io/custom-commands
// ***********************************************
//
//
// -- This is a parent command --
// Cypress.Commands.add('login', (email, password) => { ... })
//
//
// -- This is a child command --
// Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... })
//
//
// -- This is a dual command --
// Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... })
//
//
// -- This will overwrite an existing command --
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
20 changes: 20 additions & 0 deletions integration/cypress/support/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// ***********************************************************
// This example support/index.js is processed and
// loaded automatically before your test files.
//
// This is a great place to put global configuration and
// behavior that modifies Cypress.
//
// You can change the location of this file or turn off
// automatically serving support files with the
// 'supportFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/configuration
// ***********************************************************

// Import commands.js using ES2015 syntax:
import './commands'

// Alternatively you can use CommonJS syntax:
// require('./commands')
67 changes: 67 additions & 0 deletions integration/docker-compose.ci.alpha.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
version: '3'
services:
cypress:
image: "cypress/included:4.4.0"
ipc: host
depends_on:
- frontend
environment:
- CYPRESS_baseUrl=http://frontend
working_dir: /e2e
volumes:
- ./:/e2e

postgres:
image: postgres:11.6
hostname: postgres
environment:
POSTGRES_PASSWORD: some-password
POSTGRES_USER: postgres
POSTGRES_DB: retroboard
volumes:
- database:/var/lib/postgresql/data
restart: unless-stopped
logging:
driver: 'json-file'
options:
max-size: '50m'

backend:
image: retrospected/backend:alpha
depends_on:
- redis
environment:
SELF_HOSTED_ADMIN: '[email protected]'
DB_PASSWORD: some-password
SESSION_SECRET: im-a-secret

restart: unless-stopped
logging:
driver: 'json-file'
options:
max-size: '50m'

frontend:
image: retrospected/frontend:alpha
depends_on:
- backend
restart: unless-stopped
logging:
driver: 'json-file'
options:
max-size: '50m'

redis:
image: redis:latest
depends_on:
- postgres
restart: unless-stopped
logging:
driver: 'json-file'
options:
max-size: '50m'


volumes:
database:
pgadmin:
67 changes: 67 additions & 0 deletions integration/docker-compose.ci.canary.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
version: '3'
services:
cypress:
image: "cypress/included:4.4.0"
ipc: host
depends_on:
- frontend
environment:
- CYPRESS_baseUrl=http://frontend
working_dir: /e2e
volumes:
- ./:/e2e

postgres:
image: postgres:11.6
hostname: postgres
environment:
POSTGRES_PASSWORD: some-password
POSTGRES_USER: postgres
POSTGRES_DB: retroboard
volumes:
- database:/var/lib/postgresql/data
restart: unless-stopped
logging:
driver: 'json-file'
options:
max-size: '50m'

backend:
image: retrospected/backend:canary
depends_on:
- redis
environment:
SELF_HOSTED_ADMIN: '[email protected]'
DB_PASSWORD: some-password
SESSION_SECRET: im-a-secret

restart: unless-stopped
logging:
driver: 'json-file'
options:
max-size: '50m'

frontend:
image: retrospected/frontend:canary
depends_on:
- backend
restart: unless-stopped
logging:
driver: 'json-file'
options:
max-size: '50m'

redis:
image: redis:latest
depends_on:
- postgres
restart: unless-stopped
logging:
driver: 'json-file'
options:
max-size: '50m'


volumes:
database:
pgadmin:
67 changes: 67 additions & 0 deletions integration/docker-compose.ci.master.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
version: '3'
services:
cypress:
image: "cypress/included:4.4.0"
ipc: host
depends_on:
- frontend
environment:
- CYPRESS_baseUrl=http://frontend
working_dir: /e2e
volumes:
- ./:/e2e

postgres:
image: postgres:11.6
hostname: postgres
environment:
POSTGRES_PASSWORD: some-password
POSTGRES_USER: postgres
POSTGRES_DB: retroboard
volumes:
- database:/var/lib/postgresql/data
restart: unless-stopped
logging:
driver: 'json-file'
options:
max-size: '50m'

backend:
image: retrospected/backend:latest
depends_on:
- redis
environment:
SELF_HOSTED_ADMIN: '[email protected]'
DB_PASSWORD: some-password
SESSION_SECRET: im-a-secret

restart: unless-stopped
logging:
driver: 'json-file'
options:
max-size: '50m'

frontend:
image: retrospected/frontend:latest
depends_on:
- backend
restart: unless-stopped
logging:
driver: 'json-file'
options:
max-size: '50m'

redis:
image: redis:latest
depends_on:
- postgres
restart: unless-stopped
logging:
driver: 'json-file'
options:
max-size: '50m'


volumes:
database:
pgadmin:
Loading

0 comments on commit 43e6a6e

Please sign in to comment.