test.sh
1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/env bash
# scripts/test.sh —— 合并到默认分支(main / master)前的测试闸门。
# 顺序:setup-db → build → lint → unit+integration → e2e → reset-db
# 由 .githooks/pre-push 和 test-gate skill(通过子会话)调用。
set -euo pipefail
PROJECT_ROOT="$(cd "$(dirname "$0")/.." && pwd)"
cd "$PROJECT_ROOT"
echo "[test.sh] 1/6 setup test db"
./scripts/setup-test-db.sh
echo "[test.sh] 2/6 build"
(cd backend && mvn -B -DskipTests clean package)
if [ -d frontend ]; then
(cd frontend && npm ci && npm run build)
else
echo "[test.sh] skip frontend build (frontend/ not initialized yet)"
fi
echo "[test.sh] 3/6 lint"
if [ -d frontend ]; then
(cd frontend && npm run lint)
else
echo "[test.sh] skip frontend lint (frontend/ not initialized yet)"
fi
echo "[test.sh] 4/6 unit + integration"
(cd backend && mvn -B test)
if [ -d frontend ]; then
(cd frontend && npm test -- --run)
else
echo "[test.sh] skip frontend unit tests (frontend/ not initialized yet)"
fi
echo "[test.sh] 5/6 E2E"
echo "[test.sh] e2e 略"
echo "[test.sh] 6/6 reset test db"
./scripts/setup-test-db.sh
echo "[test.sh] GREEN"