Improve test output parsing in CI workflow

Strips ANSI color codes from test output for reliable parsing and updates grep logic to use the last relevant lines for test files, tests, and duration. This enhances robustness when extracting test statistics from vitest output in the GitHub Actions workflow.
This commit is contained in:
kikootwo
2026-01-15 17:02:58 -05:00
parent d07b10e407
commit 428d9a12e0
+9 -6
View File
@@ -76,13 +76,16 @@ jobs:
run: | run: |
# Parse the test output from vitest's default reporter # Parse the test output from vitest's default reporter
if [ -f test-output.txt ]; then if [ -f test-output.txt ]; then
# Strip ANSI color codes for reliable parsing
sed -i 's/\x1b\[[0-9;]*m//g' test-output.txt
# Debug: show relevant lines # Debug: show relevant lines
echo "=== Relevant test output lines ===" echo "=== Relevant test output lines ==="
grep -E "(Test Files|Tests|Duration)" test-output.txt || true grep -E "(Test Files|Tests|Duration)" test-output.txt | tail -5 || true
echo "===================================" echo "==================================="
# Extract test file count (e.g., "Test Files 81 passed (81)") # Extract test file count (e.g., "Test Files 81 passed (81)")
TEST_FILES_LINE=$(grep "Test Files" test-output.txt | head -1 || echo "") TEST_FILES_LINE=$(grep "Test Files" test-output.txt | tail -1 || echo "")
if [ -n "$TEST_FILES_LINE" ]; then if [ -n "$TEST_FILES_LINE" ]; then
TEST_FILES_PASSED=$(echo "$TEST_FILES_LINE" | grep -oE "[0-9]+ passed" | grep -oE "[0-9]+" | head -1 || echo "0") TEST_FILES_PASSED=$(echo "$TEST_FILES_LINE" | grep -oE "[0-9]+ passed" | grep -oE "[0-9]+" | head -1 || echo "0")
TEST_FILES_FAILED=$(echo "$TEST_FILES_LINE" | grep -oE "[0-9]+ failed" | grep -oE "[0-9]+" | head -1 || echo "0") TEST_FILES_FAILED=$(echo "$TEST_FILES_LINE" | grep -oE "[0-9]+ failed" | grep -oE "[0-9]+" | head -1 || echo "0")
@@ -93,8 +96,8 @@ jobs:
TEST_FILES=0 TEST_FILES=0
fi fi
# Extract test count - match line with "Tests" but not "Test Files" # Extract test count - look for line containing "Tests" followed by number, exclude "Test Files"
TESTS_LINE=$(grep -E "^\s*Tests\s" test-output.txt | grep -v "Test Files" | head -1 || echo "") TESTS_LINE=$(grep -E "Tests\s+[0-9]+" test-output.txt | grep -v "Test Files" | tail -1 || echo "")
if [ -n "$TESTS_LINE" ]; then if [ -n "$TESTS_LINE" ]; then
PASSED=$(echo "$TESTS_LINE" | grep -oE "[0-9]+ passed" | grep -oE "[0-9]+" | head -1 || echo "0") PASSED=$(echo "$TESTS_LINE" | grep -oE "[0-9]+ passed" | grep -oE "[0-9]+" | head -1 || echo "0")
FAILED=$(echo "$TESTS_LINE" | grep -oE "[0-9]+ failed" | grep -oE "[0-9]+" | head -1 || echo "0") FAILED=$(echo "$TESTS_LINE" | grep -oE "[0-9]+ failed" | grep -oE "[0-9]+" | head -1 || echo "0")
@@ -105,8 +108,8 @@ jobs:
TOTAL=0 TOTAL=0
fi fi
# Extract duration (e.g., "Duration 10.44s") # Extract duration (e.g., "Duration 26.97s")
DURATION_LINE=$(grep "Duration" test-output.txt | head -1 || echo "") DURATION_LINE=$(grep -E "Duration\s+[0-9]+" test-output.txt | tail -1 || echo "")
if [ -n "$DURATION_LINE" ]; then if [ -n "$DURATION_LINE" ]; then
DURATION=$(echo "$DURATION_LINE" | grep -oE "[0-9]+\.[0-9]+s" | head -1 | sed 's/s//' || echo "0") DURATION=$(echo "$DURATION_LINE" | grep -oE "[0-9]+\.[0-9]+s" | head -1 | sed 's/s//' || echo "0")
else else