diff --git a/scripts/setup-test-db.sh b/scripts/setup-test-db.sh index 41a3970..0a026ca 100755 --- a/scripts/setup-test-db.sh +++ b/scripts/setup-test-db.sh @@ -13,6 +13,12 @@ set -euo pipefail +# macOS Homebrew 的 mysql-client 是 keg-only,默认不在 PATH;非交互式 bash 也不读 ~/.zshrc。 +# 这里幂等 prepend 常见安装路径,命中则用,未命中(如 Linux CI 已自带 mysql)则跳过。 +for p in /opt/homebrew/opt/mysql-client/bin /usr/local/opt/mysql-client/bin; do + [ -d "$p" ] && case ":$PATH:" in *":$p:"*) ;; *) PATH="$p:$PATH" ;; esac +done + ENV_FILE="$(dirname "$0")/../.env.local" [ -f "$ENV_FILE" ] || { echo "[setup-test-db] ⚠️ .env.local 不存在($ENV_FILE)" >&2; exit 1; } diff --git a/scripts/test.sh b/scripts/test.sh index 2fdb4be..dbe8d3d 100755 --- a/scripts/test.sh +++ b/scripts/test.sh @@ -12,13 +12,27 @@ 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) && (cd frontend && npm ci && npm run 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" -(cd frontend && npm run 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) && (cd frontend && npm test -- --run) +(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 略"