Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial integration testing configuration #122

Merged
merged 13 commits into from
Oct 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"runServices": ["dev", "docs", "server"],
"workspaceFolder": "/home/calitp/app",
"postStartCommand": ["/bin/bash", "bin/init.sh"],
"postAttachCommand": ["/bin/bash", "bin/pre-commit.sh"],
"postAttachCommand": ["/bin/bash", "localhost/bin/init.sh"],

// Set *default* container specific settings.json values on container create.
"settings": {
Expand Down
44 changes: 44 additions & 0 deletions docs/getting-started/testing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Automated tests

## Integration

End-to-end integration tests are implemented with [`cypress`](https://www.cypress.io/) and can be found in the
[`tests/e2e`](https://github.com/cal-itp/benefits/tree/dev/tests/e2e) directory in the repository.

See the [`cypress` Command Line](https://docs.cypress.io/guides/guides/command-line) guide for more information.

### Using Docker Compose

Run the tests with Docker Compose against the `client` service.

1. Ensure your `.env` file has an updated `CYPRESS_baseUrl` variable:

```env
# using the Docker Compose service address
CYPRESS_baseURL=http://client:8000
```

2. From within the `localhost` directory:

```bash
docker compose run tests-e2e
```

### From the Dev Container

`cypress` is installed and available to run directly in the devcontainer.

1. Ensure your `.env` file has an updated `CYPRESS_baseUrl` variable:

```env
# using localhost since we're inside the container
CYPRESS_baseURL=http://localhost:8000
```

2. Rebuild and Reopen the devcontainer
3. Start the `benefits` app with `F5`
4. From within the `tests/e2e` directory:

```bash
npx cypress run
```
3 changes: 3 additions & 0 deletions localhost/.env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,6 @@ DJANGO_DEBUG=true
DJANGO_INIT_PATH=data/client.json
DJANGO_LOG_LEVEL=DEBUG
DJANGO_SECRET_KEY=secret

# tests config
CYPRESS_baseUrl=http://client:8000
8 changes: 7 additions & 1 deletion localhost/Dockerfile.dev
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ RUN apt-get install -qq --no-install-recommends curl git jq ssh && \
python -m pip install --upgrade pip && \
pip install --no-cache-dir flake8 debugpy pre-commit

COPY docs/requirements.txt docs/requirements.txt
# install node.js
# see https://github.com/nodesource/distributions#installation-instructions

RUN curl -fsSL https://deb.nodesource.com/setup_16.x | bash
RUN apt-get install -qq nodejs libgtk2.0-0 libgtk-3-0 libgbm-dev libnotify-dev \
libgconf-2-4 libnss3 libxss1 libasound2 libxtst6 xauth xvfb

COPY docs/requirements.txt docs/requirements.txt
RUN pip install --no-cache-dir -r docs/requirements.txt
3 changes: 3 additions & 0 deletions bin/pre-commit.sh → localhost/bin/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ pre-commit install --install-hooks --overwrite

# manage commit-msg hooks
pre-commit install --hook-type commit-msg

# install cypress
cd tests/e2e && npm install && npx cypress install
11 changes: 11 additions & 0 deletions localhost/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ services:
image: benefits_client:dev
environment:
- ANALYTICS_KEY
- CYPRESS_baseUrl
- DJANGO_ADMIN
- DJANGO_ALLOWED_HOSTS
- DJANGO_DB
Expand Down Expand Up @@ -91,5 +92,15 @@ services:
volumes:
- configvolume:/aws

tests-e2e:
image: cypress/included:8.5.0
depends_on:
- client
environment:
- CYPRESS_baseUrl
working_dir: /usr/src/e2e
volumes:
- ../tests/e2e:/usr/src/e2e

volumes:
configvolume:
3 changes: 3 additions & 0 deletions tests/e2e/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules/
screenshots/
videos/
4 changes: 4 additions & 0 deletions tests/e2e/cypress.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"pluginsFile": false,
"supportFile": false
}
25 changes: 25 additions & 0 deletions tests/e2e/cypress/integration/index.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
describe("Index page spec", () => {
it("Gives user transit provider options", () => {
cy.visit("/")

cy.contains("Choose your transit provider")
.siblings(".btn")
.should('not.be.empty')
.each(($e) => {
expect($e).attr("href").to.match(/\/[a-z]{3,}$/)
})
})

it("Takes user to transit provider page", () => {
cy.visit("/")

cy.get(".buttons .btn")
.first()
.click()

cy.contains("Let’s do it!")
.then(($e) => {
expect($e).attr("href").to.match(/\/eligibility\/$/)
})
})
})
Loading