Skip to content

Commit

Permalink
chore(tests): use the same testing method for local and CI (#400)
Browse files Browse the repository at this point in the history
* chore: use the same testing method for local and CI

* fix: don't break CI

* fix: don't break CI

* fix: use correct env vars

* fix: don't break CI

* fix: use correct env vars

* fix: use correct env vars

* chore: remove artifact upload step from CI
  • Loading branch information
szilarddoro committed Jun 19, 2023
1 parent 60dcbf4 commit 7a07b50
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 61 deletions.
75 changes: 17 additions & 58 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,73 +10,32 @@ on:
- '!*.md'

env:
HASURA_GRAPHQL_ADMIN_SECRET: test_secret_key
JWT_ALGORITHM: HS256
JWT_KEY: never_use_this_secret_key_in_production_this_is_only_for_CI_testing_098hu32r4389ufb4n38994321
POSTGRES_PASSWORD: postgrespassword
HASURA_GRAPHQL_ADMIN_SECRET: test_secret_key
HASURA_GRAPHQL_JWT_SECRET: '{"type":"HS256", "key":"never_use_this_secret_key_in_production_this_is_only_for_CI_testing_098hu32r4389ufb4n38994321","issuer":"hasura-auth"}'
HASURA_GRAPHQL_DATABASE_URL: postgres://postgres:postgrespassword@localhost:5432/postgres
HASURA_GRAPHQL_GRAPHQL_URL: http://localhost:8080/v1/graphql
AUTH_SERVER_URL: http://localhost:4000
AUTH_CLIENT_URL: http://localhost:3000
AUTH_SMTP_HOST: localhost
AUTH_SMTP_PORT: 1025
AUTH_SMTP_USER: user
AUTH_SMTP_PASS: password
AUTH_SMTP_SENDER: [email protected]
AUTH_SMTP_SECURE: false
AUTH_EMAIL_PASSWORDLESS_ENABLED: true
AUTH_LOG_LEVEL: info

jobs:
test:
name: Service tests
runs-on: ubuntu-latest
services:
postgres:
# TODO bump
image: nhost/postgres:12-v0.0.6
env:
POSTGRES_PASSWORD: ${{ env.POSTGRES_PASSWORD }}
options: >-
--restart always
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
graphql-engine:
image: hasura/graphql-engine:v2.15.2
env:
HASURA_GRAPHQL_ENABLE_TELEMETRY: 'false'
HASURA_GRAPHQL_ADMIN_SECRET: ${{ env.HASURA_GRAPHQL_ADMIN_SECRET }}
HASURA_GRAPHQL_DATABASE_URL: postgres://postgres:${{ env.POSTGRES_PASSWORD }}@postgres:5432/postgres
HASURA_GRAPHQL_JWT_SECRET: '{"type": "${{ env.JWT_ALGORITHM }}", "key": "${{ env.JWT_KEY }}"}'
options: >-
--restart always
mailhog:
image: mailhog/mailhog
env:
SMTP_HOST: mailhog
SMTP_PORT: 1025
SMTP_PASS: password
SMTP_USER: user
SMTP_SECURE: 'false'
SMTP_SENDER: [email protected]
container:
image: node:16
env:
AUTH_PORT: 4000
HASURA_GRAPHQL_ADMIN_SECRET: ${{ env.HASURA_GRAPHQL_ADMIN_SECRET }}
HASURA_GRAPHQL_DATABASE_URL: postgres://postgres:${{env.POSTGRES_PASSWORD }}@postgres:5432/postgres
HASURA_GRAPHQL_GRAPHQL_URL: 'http://graphql-engine:8080/v1/graphql'
HASURA_GRAPHQL_JWT_SECRET: '{"type": "${{ env.JWT_ALGORITHM }}", "key": "${{ env.JWT_KEY }}"}'
AUTH_SMTP_HOST: mailhog
AUTH_SMTP_PORT: 1025
AUTH_SMTP_USER: user
AUTH_SMTP_PASS: password
AUTH_SMTP_SENDER: [email protected]
AUTH_SMTP_SECURE: false
AUTH_CLIENT_URL: http://localhost:3000
options: --hostname hasura-auth
steps:
- uses: actions/checkout@v3

- name: Install Node and dependencies
uses: ./.github/actions/install-dependencies

- name: Run Jest tests
# env:
# AUTH_LOCALE_ALLOWED_LOCALES: en,fr
run: pnpm run test --coverage
- name: Upload test results
uses: actions/upload-artifact@v1
with:
name: coverage
path: coverage
- name: Run tests
shell: bash
run: make test
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ test: check-port install dev-env-up ## Run end-to-end tests.

.PHONY: check-port
check-port:
[[ -z $$(lsof -t -i tcp:$(PORT)) ]] || (echo "The port $(PORT) is already in use"; exit 1;)
[ -z $$(lsof -t -i tcp:$(PORT)) ] || (echo "The port $(PORT) is already in use"; exit 1;)

.PHONY: docgen
docgen: check-port install dev-env-up ## Generate the openapi.json file.
AUTH_CLIENT_URL=https://my-app.com AUTH_LOG_LEVEL=error AUTH_ACCESS_CONTROL_ALLOWED_REDIRECT_URLS= pnpm dev &
while [[ "$$(curl -s -o /dev/null -w ''%{http_code}'' http://localhost:$(PORT)/healthz)" != "200" ]]; do sleep 1; done
while [ "$$(curl -s -o /dev/null -w ''%{http_code}'' http://localhost:$(PORT)/healthz)" != "200" ]; do sleep 1; done
curl http://localhost:$(PORT)/openapi.json | json_pp > docs/openapi.json
kill -9 $$(lsof -t -i tcp:$(PORT))
make dev-env-down
Expand All @@ -57,7 +57,7 @@ build:
.PHONY: dev-env-down
dev-env-up: ## Start required services (Hasura, Postgres, Mailhog).
docker-compose -f docker-compose.yaml up -d
while [[ "$$(curl -s -o /dev/null -w ''%{http_code}'' http://localhost:8080/healthz)" != "200" ]]; do sleep 1; done
while [ "$$(curl -s -o /dev/null -w ''%{http_code}'' http://localhost:8080/healthz)" != "200" ]; do sleep 1; done
@echo "Hasura is ready";


Expand Down

0 comments on commit 7a07b50

Please sign in to comment.