From 02bae889b43d208d31151dec8c9a6b42dbd05378 Mon Sep 17 00:00:00 2001 From: Daniel Volz Date: Fri, 6 Feb 2026 22:24:09 +0100 Subject: [PATCH] fix: strip ANSI escape codes in test badge workflow (#101) Vitest 4 outputs ANSI color codes in test results, which caused the grep regex to fail when extracting test counts. The badge workflow silently skipped the update, leaving stale counts in the README. Add a sed pass to strip ANSI escape sequences before parsing. --- .github/workflows/update-test-badges.yml | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/.github/workflows/update-test-badges.yml b/.github/workflows/update-test-badges.yml index 5660e56..4383b98 100644 --- a/.github/workflows/update-test-badges.yml +++ b/.github/workflows/update-test-badges.yml @@ -47,8 +47,9 @@ jobs: run: | OUTPUT=$(npm run test:run 2>&1) || true echo "$OUTPUT" - # Extract "Tests X passed" from output - PASSED=$(echo "$OUTPUT" | grep -oP 'Tests\s+\K\d+(?=\s+passed)' | tail -1) + # Strip ANSI escape codes, then extract "Tests X passed" from output + CLEAN=$(echo "$OUTPUT" | sed 's/\x1b\[[0-9;]*m//g') + PASSED=$(echo "$CLEAN" | grep -oP 'Tests\s+\K\d+(?=\s+passed)' | tail -1) echo "count=$PASSED" >> $GITHUB_OUTPUT - name: Run frontend tests and capture count @@ -60,8 +61,9 @@ jobs: run: | OUTPUT=$(npm run test:run 2>&1) || true echo "$OUTPUT" - # Extract "Tests X passed" from output - PASSED=$(echo "$OUTPUT" | grep -oP 'Tests\s+\K\d+(?=\s+passed)' | tail -1) + # Strip ANSI escape codes, then extract "Tests X passed" from output + CLEAN=$(echo "$OUTPUT" | sed 's/\x1b\[[0-9;]*m//g') + PASSED=$(echo "$CLEAN" | grep -oP 'Tests\s+\K\d+(?=\s+passed)' | tail -1) echo "count=$PASSED" >> $GITHUB_OUTPUT - name: Update README badges