From 08179d1369f099eb4e2b051f0f4189580a6e0867 Mon Sep 17 00:00:00 2001 From: xiaoxia Date: Mon, 3 Aug 2026 13:57:10 +0800 Subject: [PATCH] fix(ci): strip ANSI codes before grep in vitest_incremental.sh vitest outputs ANSI color codes that interfere with grep matching. 'No test files found' skip logic was not triggered, causing CI failure. Added sed to strip ANSI codes before grep check. Closes #1221 --- scripts/ci/vitest_incremental.sh | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/scripts/ci/vitest_incremental.sh b/scripts/ci/vitest_incremental.sh index 7c5e73c59..cef424ae5 100755 --- a/scripts/ci/vitest_incremental.sh +++ b/scripts/ci/vitest_incremental.sh @@ -55,9 +55,19 @@ echo "" # 在Docker Node容器中执行增量测试 set +e -bash scripts/ci/step_frontend_run.sh "npx vitest run related $CHANGED_FILES" +VITEST_OUTPUT=$(bash scripts/ci/step_frontend_run.sh "npx vitest run related $CHANGED_FILES" 2>&1) VITEST_EXIT=$? set -e +echo "$VITEST_OUTPUT" + +# 如果没有找到测试文件,视为通过(改动的文件没有对应测试) +# 先用 sed 去掉 ANSI 转义码,避免干扰 grep 匹配 +CLEAN_OUTPUT=$(echo "$VITEST_OUTPUT" | sed 's/\x1b\[[0-9;]*m//g') +if echo "$CLEAN_OUTPUT" | grep -q "No test files found"; then + echo "" + echo "⚠️ 未找到相关测试文件,跳过(非失败)" + exit 0 +fi if [ "$VITEST_EXIT" -eq 0 ]; then echo ""