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