Skip to content

Commit 0089818

Browse files
committed
Improve test reporting in codebuff.json: emit concise success summaries
for file-change hooks when all tests pass, while preserving verbose output for failures to aid debugging. 🤖 Generated with Codebuff Co-Authored-By: Codebuff <noreply@codebuff.com>
1 parent f92a445 commit 0089818

File tree

2 files changed

+38
-3
lines changed

2 files changed

+38
-3
lines changed

codebuff.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"fileChangeHooks": [
1616
{
1717
"name": "backend-unit-tests",
18-
"command": "set -o pipefail && find src -name '*.test.ts' ! -name '*.integration.test.ts' | sort | xargs -I {} ../.bin/bun test {} 2>&1 | grep -Ev '✓|\\(pass\\)'",
18+
"command": "../scripts/run-tests-summary",
1919
"cwd": "backend",
2020
"filePattern": "backend/**/*.ts"
2121
},
@@ -27,7 +27,7 @@
2727
},
2828
{
2929
"name": "npm-app-unit-tests",
30-
"command": "set -o pipefail && find src -name '*.test.ts' ! -name '*.integration.test.ts' | sort | xargs -I {} ../.bin/bun test {} 2>&1 | grep -Ev '✓|\\(pass\\)'",
30+
"command": "../scripts/run-tests-summary",
3131
"cwd": "npm-app",
3232
"filePattern": "npm-app/**/*.ts"
3333
},
@@ -45,7 +45,7 @@
4545
},
4646
{
4747
"name": "common-unit-tests",
48-
"command": "set -o pipefail && find src -name '*.test.ts' ! -name '*.integration.test.ts' | sort | xargs -I {} ../.bin/bun test {} 2>&1 | grep -Ev '✓|\\(pass\\)'",
48+
"command": "../scripts/run-tests-summary",
4949
"cwd": "common",
5050
"filePattern": "common/**/*.ts"
5151
},

scripts/run-tests-summary

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/usr/bin/env bash
2+
# Run unit tests in the current package (cwd) and:
3+
# - If all tests pass: print a single summary line
4+
# - If any test fails: print the full output
5+
#
6+
# Usage: invoked from package directory (e.g., backend/, npm-app/, common/)
7+
# The codebuff.json hooks set cwd accordingly and call this script via ../.bin/run-tests-summary
8+
9+
set -o pipefail
10+
11+
TMPFILE="$(mktemp)"
12+
SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]:-$0}")" && pwd)"
13+
BUN="$SCRIPT_DIR/bun"
14+
[ -x "$BUN" ] || BUN="bun"
15+
16+
# Count test files first to avoid xargs running with no input
17+
COUNT=$(find src -name '*.test.ts' ! -name '*.integration.test.ts' | sort | wc -l | tr -d ' ')
18+
if [ "$COUNT" -eq 0 ]; then
19+
echo "✅ All tests passed: 0 tests across 0 files."
20+
exit 0
21+
fi
22+
23+
# Run tests file-by-file to keep behavior consistent with prior hooks
24+
# Capture all output to a tmpfile and check exit status
25+
if ! (find src -name '*.test.ts' ! -name '*.integration.test.ts' | sort | xargs -I {} "$BUN" test {} ) >"$TMPFILE" 2>&1; then
26+
cat "$TMPFILE"
27+
rm -f "$TMPFILE"
28+
exit 1
29+
fi
30+
31+
# Success: summarize totals from Bun's per-file summaries
32+
TESTS=$(grep -Eo 'Ran [0-9]+ tests across [0-9]+ files' "$TMPFILE" | awk '{t+=$2} END{print t+0}')
33+
FILES=$(grep -Eo 'Ran [0-9]+ tests across [0-9]+ files' "$TMPFILE" | awk '{f+=$5} END{print f+0}')
34+
echo "✅ All tests passed: ${TESTS:-0} tests across ${FILES:-0} files."
35+
rm -f "$TMPFILE"

0 commit comments

Comments
 (0)