2026-12-04 08:37:28 -08:00
#!/usr/bin/env bash
# 一键验证:黄金对照、旧库兼容、浏览器流程;--with-unit 追加全部单元测试。
2026-12-04 19:15:24 -08:00
# 用法:bash e2e/verify.sh [--with-unit] [--skip-browser] [--with-next]
# --with-next:追加新版界面(/next/)的新旧开单对照与浏览器检查(使用已提交的 web/dist)。
2026-12-04 08:37:28 -08:00
# 首次运行浏览器检查前:(cd e2e && PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 npm ci)
set -u
HERE = " $( cd " $( dirname " $0 " ) " && pwd ) " ; APP = " $( dirname " $HERE " ) " ; cd " $APP "
2026-12-04 19:15:24 -08:00
WITH_UNIT = 0; SKIP_BROWSER = 0; WITH_NEXT = 0
for arg in " $@ " ; do case " $arg " in --with-unit) WITH_UNIT = 1;; --skip-browser) SKIP_BROWSER = 1;; --with-next) WITH_NEXT = 1;; *) echo "未知参数: $arg " ; exit 2;; esac ; done
2026-12-04 08:37:28 -08:00
declare -a NAMES RESULTS TIMES; FAILED = 0
run(){ local name = " $1 " ; shift; echo; echo "════ $name ════" ; local start = $SECONDS
if " $@ " ; then RESULTS +=( "PASS" ) ; else RESULTS +=( "FAIL" ) ; FAILED = 1; fi
NAMES +=( " $name " ) ; TIMES +=( " $(( SECONDS-start)) s" ) ; }
run "黄金对照(golden) " node e2e/golden.js --check
run "旧库兼容(legacy) " node e2e/legacy-db.js --check
if [ " $SKIP_BROWSER " = 0 ] ; then
if [ -d " $HERE /node_modules/playwright" ] ; then run "浏览器流程(browser) " node e2e/browser.mjs --check
else echo "缺少 e2e/node_modules/playwright,请先执行:(cd e2e && PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 npm ci)" ; NAMES +=( "浏览器流程(browser) " ) ; RESULTS +=( "FAIL" ) ; TIMES +=( "0s" ) ; FAILED = 1; fi
fi
2026-12-04 19:15:24 -08:00
if [ " $WITH_NEXT " = 1 ] ; then
# 已提交的 web/dist 必须与源码重新构建的结果一致(需先在 web/ 下 npm ci)。
if [ -d " $APP /web/node_modules" ] ; then
run "新版构建与提交一致(web/dist) " bash -c 'cd web && npx vite build --logLevel error && git diff --quiet --exit-code -- dist && test -z "$(git ls-files --others --exclude-standard -- dist)"'
fi
run "新旧开单对照(parity) " node e2e/parity-create-order.mjs
2026-12-04 22:43:40 -08:00
run "业务页面与旧版对照(parity-pages) " node e2e/parity-pages.mjs
2026-12-04 19:15:24 -08:00
run "新版界面浏览器(browser-next) " node e2e/browser-next.mjs
fi
2026-12-04 08:37:28 -08:00
[ " $WITH_UNIT " = 1 ] && run "单元测试(node --test test/) " node --test test/
echo; echo "════ 汇总 ════"
for i in " ${ !NAMES[@] } " ; do printf '%-6s %-28s %s\n' " ${ RESULTS [ $i ] } " " ${ NAMES [ $i ] } " " ${ TIMES [ $i ] } " ; done
[ " $FAILED " = 0 ] && echo "全部通过" || echo "存在失败"
exit " $FAILED "