All checks were successful
PR Preview / teardown-preview (pull_request) Successful in 15s
PR Preview / test (pull_request) Has been skipped
PR Preview / deploy-preview (pull_request) Has been skipped
Deploy Production / test (push) Successful in 8s
Test / unit-test (push) Successful in 6s
Deploy Production / deploy (push) Successful in 8s
Test / build-check (push) Successful in 4s
Test / e2e-test (push) Successful in 51s
- 后端端口随机9000-9999,前端4000-4999 - 数据库文件按端口号隔离 - vite proxy支持VITE_API_PORT环境变量 - 服务启动超时30秒,失败即退出 - Cypress: defaultCommandTimeout=5s, pageLoadTimeout=10s - 整个e2e job timeout 5分钟 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
85 lines
2.6 KiB
YAML
85 lines
2.6 KiB
YAML
name: Test
|
|
on: [push]
|
|
|
|
jobs:
|
|
unit-test:
|
|
runs-on: test
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
- name: Install & Run unit tests
|
|
run: cd frontend && npm ci && npx vitest run --reporter=verbose
|
|
|
|
e2e-test:
|
|
runs-on: test
|
|
needs: unit-test
|
|
timeout-minutes: 5
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
- name: Install frontend deps
|
|
run: cd frontend && npm ci
|
|
|
|
- name: Install backend deps
|
|
run: python3 -m venv /tmp/ci-venv && /tmp/ci-venv/bin/pip install -q -r backend/requirements.txt
|
|
|
|
- name: E2E tests
|
|
run: |
|
|
# Dynamic ports to avoid conflicts
|
|
BE_PORT=$(shuf -i 9000-9999 -n 1)
|
|
FE_PORT=$(shuf -i 4000-4999 -n 1)
|
|
DB_FILE="/tmp/ci_oil_test_${BE_PORT}.db"
|
|
echo "Using backend=$BE_PORT frontend=$FE_PORT db=$DB_FILE"
|
|
|
|
# Start backend
|
|
DB_PATH="$DB_FILE" FRONTEND_DIR=/dev/null \
|
|
/tmp/ci-venv/bin/uvicorn backend.main:app --port $BE_PORT &
|
|
BE_PID=$!
|
|
|
|
# Start frontend with proxy to dynamic backend port
|
|
(cd frontend && VITE_API_PORT=$BE_PORT npx vite --port $FE_PORT) &
|
|
FE_PID=$!
|
|
|
|
# Wait for both servers (max 30s, fail fast)
|
|
READY=0
|
|
for i in $(seq 1 30); do
|
|
if curl -sf http://localhost:$BE_PORT/api/oils > /dev/null 2>&1 && \
|
|
curl -sf http://localhost:$FE_PORT/ > /dev/null 2>&1; then
|
|
echo "Both servers ready in ${i}s"
|
|
READY=1
|
|
break
|
|
fi
|
|
sleep 1
|
|
done
|
|
|
|
if [ "$READY" = "0" ]; then
|
|
echo "ERROR: Servers failed to start within 30s"
|
|
kill $BE_PID $FE_PID 2>/dev/null
|
|
rm -f "$DB_FILE"
|
|
exit 1
|
|
fi
|
|
|
|
# Run core cypress specs with timeouts
|
|
cd frontend
|
|
npx cypress run --spec "\
|
|
cypress/e2e/recipe-detail.cy.js,\
|
|
cypress/e2e/oil-reference.cy.js,\
|
|
cypress/e2e/oil-data-integrity.cy.js,\
|
|
cypress/e2e/recipe-cost-parity.cy.js,\
|
|
cypress/e2e/category-modules.cy.js,\
|
|
cypress/e2e/notification-flow.cy.js,\
|
|
cypress/e2e/registration-flow.cy.js\
|
|
" --config "video=false,defaultCommandTimeout=5000,pageLoadTimeout=10000,baseUrl=http://localhost:$FE_PORT"
|
|
EXIT_CODE=$?
|
|
|
|
# Cleanup
|
|
kill $BE_PID $FE_PID 2>/dev/null
|
|
rm -f "$DB_FILE"
|
|
exit $EXIT_CODE
|
|
|
|
build-check:
|
|
runs-on: test
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
- name: Build frontend
|
|
run: cd frontend && npm ci && npm run build
|