Files
gym-manage/gym-manage-uniapp/scripts/pre-commit-miniapp-test.sh
T

69 lines
1.9 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/sh
# 小程序冒烟测试 —— 预提交钩子
#
# 安装方式(二选一):
#
# 1. 使用 Husky(推荐):
# npx husky add .husky/pre-commit "sh scripts/pre-commit-miniapp-test.sh"
#
# 2. 手动复制到 .git/hooks/
# cp scripts/pre-commit-miniapp-test.sh .git/hooks/pre-commit
# chmod +x .git/hooks/pre-commit
#
# 注意:此钩子会在本地 IDE 已开启时运行冒烟测试。
# 未检测到 IDE 运行时自动跳过(不会阻塞提交)。
set -e
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
PROJECT_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"
echo ""
echo " 🔍 小程序冒烟测试 (Pre-commit)"
echo " ─────────────────────────────"
# 仅检查小程序相关文件的变更
CHANGED_FILES=$(git diff --cached --name-only --diff-filter=ACM | grep -E "^gym-manage-uniapp/(pages|e2e)/" || true)
if [ -z "$CHANGED_FILES" ]; then
echo " ⏭ 无小程序页面/测试文件变更,跳过测试"
exit 0
fi
echo " 📝 检测到小程序相关变更:"
echo "$CHANGED_FILES" | while read -r f; do echo "$f"; done
echo ""
# 检查 IDE 是否运行
IDE_RUNNING=$(powershell.exe -Command "
try {
\$(Get-Process -Name '微信开发者工具' -ErrorAction Stop).Count;
Write-Output 'yes'
} catch {
Write-Output 'no'
}
" 2>/dev/null || echo "no")
if [ "$IDE_RUNNING" != "yes" ]; then
echo " ⚠ 微信开发者工具未运行,跳过小程序测试"
echo " 快测方式(IDE 已运行时):npm test"
exit 0
fi
echo " 🚀 运行冒烟测试..."
# 切换到 uniapp 目录运行
cd "$PROJECT_DIR"
npm run test:quick:smoke 2>&1
if [ $? -eq 0 ]; then
echo ""
echo " ✅ 冒烟测试通过"
exit 0
else
echo ""
echo " ❌ 冒烟测试失败!"
echo " 请修复后再提交,或使用 git commit --no-verify 跳过"
exit 1
fi