From 412dc01ac22f3666b0ff1e8a2a58c81bffb92842 Mon Sep 17 00:00:00 2001 From: "s0wlz (Matthias Puchstein)" Date: Wed, 29 Apr 2026 04:13:59 +0200 Subject: [PATCH] feat(tests): add make test-up/down/reset/rebuild/e2e targets --- Makefile | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 96a6164..6d9b1c4 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,5 @@ -.PHONY: dev dev-backend dev-frontend build test compose-up seed-demo +.PHONY: dev dev-backend dev-frontend build test compose-up seed-demo \ + test-up test-down test-reset test-rebuild test-e2e dev: @echo "Starting backend and frontend in parallel..." @@ -31,3 +32,55 @@ seed-demo: sqlite3 $$DB_FILE < $$f; \ done; \ sqlite3 $$DB_FILE < backend/demo/demo_seed.sql + +# ── Test pipeline ───────────────────────────────────────────────────────────── + +test-rebuild: + @. scripts/test-env.sh; \ + mkdir -p data/test; \ + rm -f "$$TT_TEST_DB"; \ + for f in backend/migrations/*.sql; do sqlite3 "$$TT_TEST_DB" < $$f; done; \ + sqlite3 "$$TT_TEST_DB" < backend/demo/demo_seed.sql; \ + echo "[test-rebuild] DB ready at $$TT_TEST_DB" + +test-up: + @. scripts/test-env.sh; \ + if [ -f data/test/.pid ] && kill -0 $$(cat data/test/.pid) 2>/dev/null; then \ + echo "[test-up] Backend already running (PID $$(cat data/test/.pid)) on port $$TT_TEST_PORT"; \ + exit 0; \ + fi; \ + [ -f "$$TT_TEST_DB" ] || $(MAKE) test-rebuild; \ + DATABASE_URL="sqlite:$$TT_TEST_DB" PORT=$$TT_TEST_PORT TT_TEST_MODE=1 \ + cargo run --manifest-path backend/Cargo.toml &>/tmp/tutortool-test.log & \ + echo $$! > data/test/.pid; \ + echo "[test-up] Backend PID $$(cat data/test/.pid) starting on port $$TT_TEST_PORT..."; \ + for i in $$(seq 1 30); do \ + curl -fs "$$TT_BASE_URL/health" >/dev/null 2>&1 && break; \ + sleep 1; \ + done; \ + curl -fs "$$TT_BASE_URL/health" >/dev/null || (echo "[test-up] Backend failed to start; see /tmp/tutortool-test.log" && exit 1); \ + echo "[test-up] Ready at $$TT_BASE_URL" + +test-down: + @. scripts/test-env.sh; \ + if [ -f data/test/.pid ]; then \ + kill $$(cat data/test/.pid) 2>/dev/null || true; \ + rm -f data/test/.pid data/test/.port; \ + echo "[test-down] Backend stopped"; \ + else \ + echo "[test-down] No PID file found; nothing to stop"; \ + fi + +test-reset: + @. scripts/test-env.sh; \ + if curl -fs "$$TT_BASE_URL/health" >/dev/null 2>&1; then \ + curl -fsS -X POST "$$TT_BASE_URL/__test__/reset"; \ + echo "[test-reset] DB reset via endpoint"; \ + else \ + echo "[test-reset] Backend not running; rebuilding DB file instead"; \ + $(MAKE) test-rebuild; \ + fi + +test-e2e: + $(MAKE) test-up + pnpm --dir frontend test:e2e