2022-05-18 07:26:57 +00:00
|
|
|
# Testing
|
|
|
|
|
|
2023-02-10 10:11:23 +00:00
|
|
|
## Unit Tests
|
2022-05-18 07:26:57 +00:00
|
|
|
|
2023-02-10 10:11:23 +00:00
|
|
|
We are using Vitest.
|
2022-12-28 09:37:23 +00:00
|
|
|
|
|
|
|
|
Simply run `pnpm test` to run all the tests locally.
|
2022-05-18 07:26:57 +00:00
|
|
|
|
|
|
|
|
## Integration Tests
|
|
|
|
|
|
2023-02-10 10:11:23 +00:00
|
|
|
We are using Vitest to test the following concerns:
|
2022-05-18 07:26:57 +00:00
|
|
|
|
|
|
|
|
1. Main application flows and integration of different services
|
2022-12-20 14:34:46 +00:00
|
|
|
2. Containerize execution of all services
|
|
|
|
|
3. Cross-service network calls
|
2022-05-18 07:26:57 +00:00
|
|
|
|
2022-12-20 14:34:46 +00:00
|
|
|
Integration tests are based pre-built Docker images, so you can run it in 2 modes:
|
|
|
|
|
|
2023-02-10 10:11:23 +00:00
|
|
|
#### Running from Source Code
|
2022-12-20 14:34:46 +00:00
|
|
|
|
2023-07-27 11:34:29 +00:00
|
|
|
**TL;DR**: Use `pnpm integration:prepare` command to set up the complete environment from locally
|
2023-06-12 14:56:27 +00:00
|
|
|
running integration tests. You can ignore the rest of the commands in this section, if this script
|
|
|
|
|
worked for you, and just run `pnpm test:integration` to run the actual tests.
|
2023-03-16 07:37:28 +00:00
|
|
|
|
2022-12-28 09:37:23 +00:00
|
|
|
To run integration tests locally, from the local source code, you need to build a valid Docker
|
|
|
|
|
image.
|
|
|
|
|
|
|
|
|
|
To do so, follow these instructions:
|
2022-05-18 07:26:57 +00:00
|
|
|
|
2023-07-27 11:34:29 +00:00
|
|
|
1. Install all deps: `pnpm i`
|
|
|
|
|
2. Generate types: `pnpm graphql:generate`
|
|
|
|
|
3. Build source code: `pnpm build`
|
|
|
|
|
4. Set env vars:
|
|
|
|
|
```bash
|
|
|
|
|
export COMMIT_SHA="local"
|
|
|
|
|
export RELEASE="local"
|
|
|
|
|
export BRANCH_NAME="local"
|
|
|
|
|
export BUILD_TYPE=""
|
|
|
|
|
export DOCKER_TAG=":local"
|
|
|
|
|
```
|
|
|
|
|
5. Compile a local Docker image by running:
|
2023-01-24 18:15:24 +00:00
|
|
|
`docker buildx bake -f docker/docker.hcl integration-tests --load`
|
2023-07-27 11:34:29 +00:00
|
|
|
6. Use Docker Compose to run the built containers (based on `community` compose file), along with
|
2022-12-28 09:37:23 +00:00
|
|
|
the extra containers:
|
|
|
|
|
|
2023-07-27 11:34:29 +00:00
|
|
|
```bash
|
|
|
|
|
export DOCKER_TAG=":local"
|
|
|
|
|
export DOCKER_REGISTRY=""
|
|
|
|
|
|
|
|
|
|
docker compose -f ./docker/docker-compose.community.yml -f ./integration-tests/docker-compose.integration.yaml --env-file ./integration-tests/.env up -d --wait
|
|
|
|
|
```
|
2022-12-28 09:37:23 +00:00
|
|
|
|
2023-07-27 11:34:29 +00:00
|
|
|
7. Run the tests: `pnpm --filter integration-tests test:integration`
|
2022-12-20 14:34:46 +00:00
|
|
|
|
2023-02-10 10:11:23 +00:00
|
|
|
#### Running from Pre-Built Docker Image
|
2022-12-20 14:34:46 +00:00
|
|
|
|
|
|
|
|
To run integration tests locally, from the pre-build Docker image, follow:
|
|
|
|
|
|
2022-12-28 09:37:23 +00:00
|
|
|
1. Install all deps: `pnpm i`
|
|
|
|
|
2. Generate types: `pnpm graphql:generate`
|
|
|
|
|
3. Build only addition, local CF Workers source code, by running:
|
|
|
|
|
`pnpm --filter integration-tests prepare:env`
|
|
|
|
|
4. Decide on the commit ID / Docker image tag you would like to use (make sure `build-and-dockerize`
|
|
|
|
|
is done successfully)
|
|
|
|
|
5. Set the needed env vars, and use Docker Compose to run all local services:
|
2022-12-20 14:34:46 +00:00
|
|
|
|
2023-07-27 11:34:29 +00:00
|
|
|
```bash
|
|
|
|
|
export DOCKER_REGISTRY="ghcr.io/kamilkisiela/graphql-hive/"
|
|
|
|
|
export DOCKER_TAG=":IMAGE_TAG_HERE"
|
|
|
|
|
|
|
|
|
|
docker compose -f ./docker/docker-compose.community.yml -f ./integration-tests/docker-compose.integration.yaml --env-file ./integration-tests/.env up -d --wait
|
|
|
|
|
```
|
2022-12-20 14:34:46 +00:00
|
|
|
|
2022-12-28 09:37:23 +00:00
|
|
|
6. Run the tests: `pnpm --filter integration-tests test:integration`
|
2022-12-20 14:34:46 +00:00
|
|
|
|
2023-02-10 10:11:23 +00:00
|
|
|
## E2E Tests
|
2022-12-20 14:34:46 +00:00
|
|
|
|
|
|
|
|
e2e Tests are based on Cypress, and matches files that ends with `.cy.ts`. The tests flow runs from
|
|
|
|
|
a pre-build Docker image.
|
|
|
|
|
|
2023-02-10 10:11:23 +00:00
|
|
|
#### Running from Source Code
|
2022-12-20 14:34:46 +00:00
|
|
|
|
|
|
|
|
To run e2e tests locally, from the local source code, follow:
|
|
|
|
|
|
|
|
|
|
1. Make sure you have Docker installed. If you are having issues, try to run `docker system prune`
|
|
|
|
|
to clean the Docker caches.
|
|
|
|
|
2. Install all deps: `pnpm i`
|
|
|
|
|
3. Generate types: `pnpm graphql:generate`
|
|
|
|
|
4. Build source code: `pnpm build`
|
|
|
|
|
5. Set env vars:
|
2023-07-27 11:34:29 +00:00
|
|
|
```bash
|
|
|
|
|
export COMMIT_SHA="local"
|
|
|
|
|
export RELEASE="local"
|
|
|
|
|
export BRANCH_NAME="local"
|
|
|
|
|
export BUILD_TYPE=""
|
|
|
|
|
export DOCKER_TAG=":local"
|
|
|
|
|
```
|
2023-01-24 18:15:24 +00:00
|
|
|
6. Compile a local Docker image by running: `docker buildx bake -f docker/docker.hcl build --load`
|
2022-12-20 14:34:46 +00:00
|
|
|
7. Run the e2e environment, by running:
|
2023-04-12 11:17:07 +00:00
|
|
|
`docker compose -f ./docker/docker-compose.community.yml -f ./docker/docker-compose.end2end.yml --env-file ./integration-tests/.env up -d --wait`
|
2022-12-20 14:34:46 +00:00
|
|
|
8. Run Cypress: `pnpm test:e2e`
|
|
|
|
|
|
2023-02-10 10:11:23 +00:00
|
|
|
#### Running from Pre-Built Docker Image
|
2022-12-20 14:34:46 +00:00
|
|
|
|
|
|
|
|
To run integration tests locally, from the pre-build Docker image, follow:
|
|
|
|
|
|
|
|
|
|
1. Make sure you have Docker installed. If you are having issues, try to run `docker system prune`
|
|
|
|
|
to clean the Docker caches.
|
|
|
|
|
2. Install all deps: `pnpm i`
|
|
|
|
|
3. Generate types: `pnpm graphql:generate`
|
|
|
|
|
4. Build source code: `pnpm build`
|
2023-01-02 11:05:23 +00:00
|
|
|
5. Decide on the commit ID / Docker image tag you would like to use and set it as env var:
|
2023-07-27 11:34:29 +00:00
|
|
|
```bash
|
|
|
|
|
export DOCKER_REGISTRY="ghcr.io/kamilkisiela/graphql-hive/"
|
|
|
|
|
export DOCKER_TAG=":IMAGE_TAG_HERE"
|
|
|
|
|
```
|
2022-12-28 09:37:23 +00:00
|
|
|
6. Run the e2e environment, by running:
|
2023-01-24 18:15:24 +00:00
|
|
|
`docker compose -f ./docker/docker-compose.community.yml --env-file ./integration-tests/.env up -d --wait`
|
2022-12-28 09:37:23 +00:00
|
|
|
7. Run Cypress: `pnpm test:e2e`
|
2022-12-20 14:34:46 +00:00
|
|
|
|
2023-02-10 10:11:23 +00:00
|
|
|
#### Docker Compose Configuration
|
2022-12-20 14:34:46 +00:00
|
|
|
|
2022-12-28 09:37:23 +00:00
|
|
|
Keep in mind that integration tests are running a combination of 2 Docker Compose files:
|
|
|
|
|
|
|
|
|
|
1. `docker-compose.community.yml` - this is also used for self-hosting Hive, so this file contains
|
2023-03-08 09:17:43 +00:00
|
|
|
all services and configurations needed for running Hive core (without Cloud-specific services,
|
2022-12-28 09:37:23 +00:00
|
|
|
like billing).
|
|
|
|
|
2. `docker-compose.integration.yaml` - An extension and overrides file: we are using that file to
|
|
|
|
|
run local services such as CloudFlare CDN mock, external composition service and so on - this is
|
2023-03-08 09:17:43 +00:00
|
|
|
done in order to mock a complete Hive Cloud environment and test all features. **This file also
|
2022-12-28 09:37:23 +00:00
|
|
|
includes overrides such as environment variables that are specific only for integration testing -
|
|
|
|
|
so make sure to choose wisely where to add environment variables!**
|
|
|
|
|
|
|
|
|
|
## Troubleshoot
|
|
|
|
|
|
|
|
|
|
If you are having issues with running Docker images, follow these instructions:
|
|
|
|
|
|
2023-02-10 10:11:23 +00:00
|
|
|
1. Make sure you have the latest Docker installed.
|
2023-07-27 11:34:29 +00:00
|
|
|
2. Make sure no containers are running (`docker ps` and then `docker stop CONTAINER_ID`).
|
|
|
|
|
3. Delete the local volume used for testing, it's located under `.hive` directory.
|
|
|
|
|
4. Try to run `docker system prune` to clean all the Docker images, containers, networks and caches.
|