#!/bin/bash # 尚数网测评 · 测试用例执行台 # # 探测并按需拉起后端 30000 / 前端 5173,启动执行台,打开控制台。 # 端口上已有实例一律复用,绝不重启或杀掉别人的进程。 set -e cd "$(dirname "$0")" PORT="${SSW_E2E_PORT:-7788}" echo "" echo " 尚数网测评 · 测试用例执行台" echo " ────────────────────────────────────────" if [ ! -d node_modules ]; then echo " 首次运行,安装依赖…" npm install --no-audit --no-fund --silent fi # 执行台自己占着的端口先让出来(只清理执行台,不碰前后端) if lsof -nP -iTCP:"$PORT" -sTCP:LISTEN >/dev/null 2>&1; then echo " 端口 $PORT 上已有执行台,先停掉旧的" lsof -nP -tiTCP:"$PORT" -sTCP:LISTEN | xargs kill 2>/dev/null || true sleep 1 fi echo " 拉起依赖服务(已在运行的会直接复用)…" node -e ' import("./lib/env.mjs").then(async (m) => { const log = (s) => console.log(" " + s) try { await m.startFrontend(log) await m.startBackend(log) } catch (e) { console.log(" ⚠ " + e.message) console.log(" 服务没起来也能开控制台,但相关用例会失败") } process.exit(0) })' echo " ────────────────────────────────────────" node runner.mjs & RUNNER_PID=$! sleep 1 open -a "Google Chrome" "http://localhost:$PORT/" 2>/dev/null || open "http://localhost:$PORT/" trap 'kill $RUNNER_PID 2>/dev/null' EXIT wait $RUNNER_PID