From 428d9a12e064a7c71a5b4beda254bf38a4775c03 Mon Sep 17 00:00:00 2001 From: kikootwo Date: Thu, 15 Jan 2026 17:02:58 -0500 Subject: [PATCH] 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. --- .github/workflows/run-tests.yml | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index ac89a2a..b00a6e9 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -76,13 +76,16 @@ jobs: run: | # Parse the test output from vitest's default reporter 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 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 "===================================" # 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 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") @@ -93,8 +96,8 @@ jobs: TEST_FILES=0 fi - # Extract test count - match line with "Tests" but not "Test Files" - TESTS_LINE=$(grep -E "^\s*Tests\s" test-output.txt | grep -v "Test Files" | head -1 || echo "") + # Extract test count - look for line containing "Tests" followed by number, exclude "Test Files" + TESTS_LINE=$(grep -E "Tests\s+[0-9]+" test-output.txt | grep -v "Test Files" | tail -1 || echo "") if [ -n "$TESTS_LINE" ]; then 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") @@ -105,8 +108,8 @@ jobs: TOTAL=0 fi - # Extract duration (e.g., "Duration 10.44s") - DURATION_LINE=$(grep "Duration" test-output.txt | head -1 || echo "") + # Extract duration (e.g., "Duration 26.97s") + DURATION_LINE=$(grep -E "Duration\s+[0-9]+" test-output.txt | tail -1 || echo "") if [ -n "$DURATION_LINE" ]; then DURATION=$(echo "$DURATION_LINE" | grep -oE "[0-9]+\.[0-9]+s" | head -1 | sed 's/s//' || echo "0") else