#!/usr/bin/env bash # scripts/test.sh — 遍历 core + 全插件,零依赖 node --test 跑全部单测(core-protocol-v0) # owner:T1b-α lane-core | 运行:bash scripts/test.sh(在 game-runtime/ 下或任意路径,脚本自定位仓根) # # 纪律(执行版 §1):lane 阶段一切测试 = 本机零依赖 node --test;本脚本不装任何依赖、不跑 git。 # 收集对象:src/core/**/*.test.mjs|cjs + src/plugins/<*>/test/**/*.test.mjs|cjs。 # 退出码:全绿=0;任一失败=node --test 的非零码(CI/收口据此 gate)。 set -euo pipefail # 自定位仓根(脚本在 game-runtime/scripts/ 下,根 = 上一级),保证任意 cwd 可跑。 SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" ROOT="$(cd "${SCRIPT_DIR}/.." && pwd)" cd "${ROOT}" echo "[test.sh] 仓根:${ROOT}" echo "[test.sh] 收集测试文件(*.test.mjs / *.test.cjs)..." # 收集 core 与插件测试文件(find 跨平台稳妥;排除 node_modules)。 # 用数组承载,避免文件名含空格出错。 mapfile -t TEST_FILES < <(find src -type f \( -name '*.test.mjs' -o -name '*.test.cjs' \) -not -path '*/node_modules/*' | sort) if [ "${#TEST_FILES[@]}" -eq 0 ]; then echo "[test.sh] 未发现任何测试文件,视为失败(避免空过假绿)。" >&2 exit 1 fi echo "[test.sh] 共 ${#TEST_FILES[@]} 个测试文件:" for f in "${TEST_FILES[@]}"; do echo " - ${f}"; done echo "[test.sh] 开始 node --test ..." echo # 一次性把全部文件交给 node --test,得到合并的 TAP/汇总(pass/fail 总计一目了然)。 node --test "${TEST_FILES[@]}"