Skip to content

Commit

Permalink
Merge pull request #1701 from compdemocracy/test-clarity
Browse files Browse the repository at this point in the history
Test clarity
  • Loading branch information
ballPointPenguin authored Nov 10, 2023
2 parents 2a28bbb + 0758fcc commit ef7bf53
Show file tree
Hide file tree
Showing 10 changed files with 425 additions and 260 deletions.
14 changes: 9 additions & 5 deletions .github/workflows/cypress-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,13 @@ on:

jobs:
cypress-run:
runs-on: ubuntu-latest
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Build and Run Application
uses: isbang/compose-action@v1.4.1
env:
GOOGLE_CREDENTIALS_BASE64: ${{ secrets.GOOGLE_CREDENTIALS_BASE64 }}
with:
compose-file: |
docker-compose.yml
Expand All @@ -33,8 +31,14 @@ jobs:
uses: jtalk/url-health-check-action@v3
with:
url: http://localhost/api/v3/testConnection
max-attempts: 12
retry-delay: 5s
max-attempts: 10
retry-delay: 10s

- name: Dump Application Logs
if: failure()
run: |
echo "Health check failed. Dumping Docker logs..."
docker-compose logs
- name: Cypress Run
uses: cypress-io/github-action@v5
Expand Down
27 changes: 7 additions & 20 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
# update TAG

SHELL=/bin/bash
E2E_RUN = cd e2e;

BASEURL ?= https://127.0.0.1.sslip.io
E2E_RUN = cd e2e; CYPRESS_BASE_URL=$(BASEURL)
export ENV_FILE = .env
export TAG = $(shell grep -e ^TAG ${ENV_FILE} | awk -F'[=]' '{gsub(/ /,""); print $$2}')
export GIT_HASH = $(shell git rev-parse --short HEAD)
Expand Down Expand Up @@ -76,25 +75,14 @@ start-FULL-REBUILD: echo_vars stop rm-ALL ## Remove and restart all Docker conta
e2e-install: e2e/node_modules ## Install Cypress E2E testing tools
$(E2E_RUN) npm install

e2e-prepare: ## Prepare to run Cypress E2E tests
@# Testing embeds requires a override of a file prior to build.
cp e2e/cypress/fixtures/html/embed.html client-admin/embed.html

e2e-run-minimal: ## Run E2E tests: minimal (smoke test)
$(E2E_RUN) npm run e2e:minimal

e2e-run-standalone: ## Run E2E tests: standalone (no credentials required)
$(E2E_RUN) npm run e2e:standalone

e2e-run-secret: ## Run E2E tests: secret (credentials required)
$(E2E_RUN) npm run e2e:secret

e2e-run-subset: ## Run E2E tests: filter tests by TEST_FILTER envvar (without browser exit)
$(E2E_RUN) npm run e2e:subset
e2e-run: ## Run E2E tests except those which require 3rd party services
$(E2E_RUN) npm run test

e2e-run-all: ## Run E2E tests: all
$(E2E_RUN) npm run e2e:all
$(E2E_RUN) npm run test:all

e2e-run-interactive: ## Run E2E tests: interactively
$(E2E_RUN) npx cypress open

# Helpful CLI shortcuts
rbs: start-rebuild
Expand All @@ -103,8 +91,7 @@ rbs: start-rebuild
@true

.PHONY: help pull start stop rm-containers rm-volumes rm-images rm-ALL hash build-no-cache start-rebuild \
start-recreate restart-FULL-REBUILD e2e-install e2e-prepare e2e-run-minimal e2e-run-standalone e2e-run-secret \
e2e-run-subset e2e-run-all
start-recreate restart-FULL-REBUILD e2e-install e2e-run e2e-run-all e2e-run-some

help:
@echo 'Usage: make <command>'
Expand Down
1 change: 1 addition & 0 deletions e2e/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.vscode
cypress/downloads
cypress/logs
cypress/screenshots
cypress/videos
Expand Down
36 changes: 35 additions & 1 deletion e2e/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,35 @@ End-To-End Tests written with cypress.io

- node `>= 18`

## Quickstart

from the polis root directory:

```sh
make TEST start
```

and in another shell:

```sh
make e2e-install
make e2e-run
```

## Setup

(from within the e2e directory)

```sh
npm install
```

(or, from the root directory)

```sh
make e2e-install
```

See [System Requirements](https://docs.cypress.io/guides/getting-started/installing-cypress#System-requirements) for additional needs that your operating system might have.

There are few ways to run the end-to-end (e2e) test suite. They can be run in a browser, or headless. They can be run within a dockerized environment or directly on a development machine, or in a cloud system such as GitHub Actions. In any case, you need 3 things:
Expand All @@ -22,16 +45,27 @@ There are few ways to run the end-to-end (e2e) test suite. They can be run in a

Running `docker compose` with either the `docker-compose.dev.yml` or `docker-compose.test.yml` overlay will get you #1 and #2. (See the top-level documentation for configuring and running polis.)

The helpful shortcut `make TEST start` will build (if necessary) and start all of the dockerized services in a test environment,
making use of `docker-compose.test.yml` and the `test.env` configuration values. This is the preferred way.

If you want to run tests that require integration with Google Translation API, refer to the Byzantine [documentation at Google Cloud](https://cloud.google.com/docs/authentication/client-libraries).

## Running the tests

To run the tests "headlessly" from the command line, simply run:

(from within the e2e directory)

```sh
npm test
```

(or from the root directory)

```sh
make e2e-run
```

To open a Cypress user interface and run the tests in a browser of your choosing, run:

```sh
Expand All @@ -49,7 +83,7 @@ Read more about the [Cypress command line options here](https://docs.cypress.io/

## Notes

- The default base url for running tests against, is http://localhost
- The default base url for running tests against, is <http://localhost>
- The default browser is electron. On the command line the default is headless electron unless you include a `--browser` option.
- You may override the base url with a command like so: `CYPRESS_BASE_URL=http://123.45.67.89.sslip.io npm test`
- `cypress/support/commands.js`: where we keep oft-used commands, e.g., for logging in, creating conversations, etc.
Expand Down
4 changes: 4 additions & 0 deletions e2e/cypress/e2e/client-admin/conversation.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ describe('Conversation: Configure', function () {

cy.get('input[data-test-id="topic"]')
.type('Test topic')

cy.get('input[data-test-id="topic"]')
.then(() => cy.focused().blur())

cy.wait('@updateConversation').then(({ response }) =>
Expand All @@ -53,6 +55,8 @@ describe('Conversation: Configure', function () {

cy.get('textarea[data-test-id="description"]')
.type('Test description')

cy.get('textarea[data-test-id="description"]')
.then(() => cy.focused().blur())

cy.wait('@updateConversation').then(({ response }) =>
Expand Down
2 changes: 1 addition & 1 deletion e2e/cypress/support/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { faker } from '@faker-js/faker'

export function generateRandomUser() {
return {
name: faker.name.findName(),
name: faker.person.fullName(),
email: faker.internet.email(),
password: faker.internet.password(),
}
Expand Down
32 changes: 21 additions & 11 deletions e2e/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,30 @@
services:
e2e-electron:
image: cypress/included:12.5.1
image: cypress/included:12.17.3
environment:
- CYPRESS_BASE_URL=http://host.docker.internal:80
- CYPRESS_MAILDEV_URL=http://host.docker.internal:1080
volumes:
- ./cypress:/cypress
- ./cypress.config.js:/cypress.config.js
- .:/e2e
working_dir: /e2e
command: npm run test

e2e-chrome:
image: cypress/included:12.5.1
image: cypress/included:12.17.3
environment:
- CYPRESS_BASE_URL=http://host.docker.internal:80
- CYPRESS_MAILDEV_URL=http://host.docker.internal:1080
volumes:
- ./cypress:/cypress
- ./cypress.config.js:/cypress.config.js
command: --browser chrome
- .:/e2e
working_dir: /e2e
command: npm run test --browser chrome

e2e-firefox:
image: cypress/included:12.5.1
image: cypress/included:12.17.3
environment:
- CYPRESS_BASE_URL=http://host.docker.internal:80
- CYPRESS_MAILDEV_URL=http://host.docker.internal:1080
volumes:
- ./cypress:/cypress
- ./cypress.config.js:/cypress.config.js
command: --browser firefox
- .:/e2e
working_dir: /e2e
command: npm run test --browser firefox
Loading

0 comments on commit ef7bf53

Please sign in to comment.