Skip to content

Commit c62816c

Browse files
authored
Add E2E tests workflow configuration (#187)
* Add E2E tests workflow configuration
1 parent 8dba868 commit c62816c

File tree

2 files changed

+72
-15
lines changed

2 files changed

+72
-15
lines changed

.github/workflows/e2e-tests.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: E2E Tests
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
workflow_dispatch:
9+
10+
jobs:
11+
e2e-tests:
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- name: Checkout code
16+
uses: actions/checkout@v4
17+
18+
- name: Set up Node.js
19+
uses: actions/setup-node@v4
20+
with:
21+
node-version: '18'
22+
cache: 'npm'
23+
24+
- name: Install dependencies
25+
run: npm ci
26+
27+
- name: Create required files
28+
run: |
29+
touch dbinit.sql
30+
cp env.example env.local.test
31+
32+
- name: Set up Docker Buildx
33+
uses: docker/setup-buildx-action@v3
34+
35+
- name: Build application
36+
run: npm run build
37+
38+
- name: Run e2e tests
39+
run: make e2e-tests
40+
timeout-minutes: 15
41+
42+
- name: Cleanup Docker containers
43+
if: always()
44+
run: |
45+
docker compose down -v || true
46+
docker system prune -f || true

Makefile

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -79,17 +79,20 @@ endif
7979
.PHONY: e2e-tests
8080
e2e-tests: ## Start end2end tests
8181
@make up &
82-
83-
@# wait until server is ready and the connection to the db is ready
84-
@- while ! curl -s -f -LI http://localhost:8080/health >> /dev/null; do echo "waiting until server is ready for tests..." && sleep 3; done
85-
86-
@set -a && source env.local.test && set +a && npx jest ./tests/api_e2e --verbose true || true
87-
88-
@docker compose down
89-
90-
@echo "Done - Some important information for debugging:"
91-
@echo " - If the tests fail, consider to refresh the db by running 'make down-db' first"
92-
@echo " - To have data for spotify, apple, and anchor, use podcast_id 3 for the tests"
82+
@UP_PID=$$!; \
83+
echo "Starting services (PID: $$UP_PID)..."; \
84+
trap 'docker compose down; kill $$UP_PID 2>/dev/null || true' EXIT; \
85+
while ! curl -s -f -LI http://localhost:8080/health >> /dev/null; do \
86+
echo "waiting until server is ready for tests..." && sleep 3; \
87+
done; \
88+
echo "Server is ready, running tests..."; \
89+
set -a && source env.local.test && set +a && npx jest ./tests/api_e2e --verbose true; \
90+
TEST_EXIT_CODE=$$?; \
91+
docker compose down; \
92+
echo "Done - Some important information for debugging:"; \
93+
echo " - If the tests fail, consider to refresh the db by running 'make down' first"; \
94+
echo " - To have data for spotify, apple, and anchor, use podcast_id 3 for the tests"; \
95+
exit $$TEST_EXIT_CODE
9396

9497
.PHONY: status
9598
status: ## Send status request
@@ -111,7 +114,15 @@ send-api-req-prod: ## Send request to production
111114
db-shell: ## Opens the mysql shell inside the db container
112115
docker compose exec db bash -c 'mysql -uopenpodcast -popenpodcast openpodcast'
113116

114-
.PHONY: test-one-e2e-%
115-
test-one-e2e-%: ## Run end2end tests for a specific test case
116-
@echo "Running end2end test for: $*"
117-
npx jest ./tests/api_e2e --verbose true --testNamePattern="$*"
117+
.PHONY: db-init-auth
118+
db-init-auth: ## Initialize the auth db after api is up
119+
# creates the auth schema
120+
docker cp ./db_schema/auth.sql $$(docker compose ps -q db):/tmp/auth.sql
121+
docker compose exec db bash -c 'mysql -uopenpodcast -popenpodcast openpodcast_auth < /tmp/auth.sql'
122+
123+
# creates some dummy auth data
124+
docker cp ./db_auth_data.sql $$(docker compose ps -q db):/tmp/auth_data.sql
125+
docker compose exec db bash -c 'mysql -uopenpodcast -popenpodcast openpodcast_auth < /tmp/auth_data.sql'
126+
docker cp ./db_auth_data.sql api-db-1:/tmp/auth_data.sql
127+
docker compose exec db bash -c 'mysql -uopenpodcast -popenpodcast openpodcast_auth < /tmp/auth_data.sql'
128+

0 commit comments

Comments
 (0)