-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun-tests.sh
More file actions
executable file
·141 lines (113 loc) · 4.96 KB
/
run-tests.sh
File metadata and controls
executable file
·141 lines (113 loc) · 4.96 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#!/bin/bash
# ─────────────────────────────────────────────────────────────────
# UnoSim Test & Build Pipeline (Policy-Compliant Version)
# ─────────────────────────────────────────────────────────────────
# Konfiguration
LOG_FILE="run-tests_output.log"
TOTAL_STEPS=5
STEP=0
SERVER_PID=""
# Policy: Standard Log-Level für die Pipeline ist WARN (2) oder ERROR (1)
# Das minimiert I/O-Last, während der Ring-Buffer bei Fehlern Kontext liefert.
export LOG_LEVEL=1
export NODE_ENV=test
# Farben & Icons
G="\033[32m"; Y="\033[33m"; R="\033[31m"; C="\033[36m"; B="\033[1m"; D="\033[2m"; RS="\033[0m"
OK="${G}✔${RS}"; FAIL="${R}✘${RS}"; RUN="${Y}◌${RS}"; WARN="${Y}⚠${RS}"
div() { printf "${D}────────────────────────────────────────────────${RS}\n"; }
# Aufräum-Funktion bei Abbruch oder Ende
cleanup() {
if [ -n "$SERVER_PID" ]; then
kill "$SERVER_PID" 2>/dev/null
fi
}
trap cleanup EXIT
run_task() {
local label=$1 cmd=$2
STEP=$((STEP+1))
local start=$(date +%s)
echo -e "\n${B}▸ [$STEP/$TOTAL_STEPS] $label${RS}"
# Verzeichnisse sicherstellen
mkdir -p temp build
# Policy-Konforme Ausführung:
# Wir nutzen die neue LOG_LEVEL Steuerung statt unzuverlässiger grep-Filter.
# set -o pipefail stellt sicher, dass Fehler im Command den Task stoppen.
(set -o pipefail; eval "$cmd" >> "$LOG_FILE" 2>&1) &
local pid=$!
while kill -0 "$pid" 2>/dev/null; do
printf "\r %b %-35s Sek.: %d" "$RUN" "$label" $(( $(date +%s) - start ))
sleep 1
done
wait "$pid"
local exit_code=$?
local duration=$(( $(date +%s) - start ))
if [ $exit_code -eq 0 ]; then
printf "\r %b %-35s Sek.: %d\n" "$OK" "$label" "$duration"
return 0
else
printf "\r %b %-35s ${R}FEHLER${RS} (Code: $exit_code)\n" "$FAIL" "$label"
echo -e " ${R}${FAIL} Abbruch: Siehe $LOG_FILE${RS}"
# Tipp: Bei Fehlern enthält das LOG_FILE dank Ring-Buffer nun automatisch
# den DEBUG-Kontext, auch wenn LOG_LEVEL auf 1 steht.
exit 1
fi
}
parse_test_results() {
local pattern=$1
# Prüfe die letzten 30 Zeilen auf Zusammenfassungen
local line=$(tail -n 30 "$LOG_FILE" | grep -E "$pattern" | tail -n 1)
[ -z "$line" ] && return
local p=$(echo "$line" | grep -oE "[0-9]+ passed" | head -n 1 | cut -d' ' -f1 || echo "0")
local f=$(echo "$line" | grep -oE "[0-9]+ failed" | head -n 1 | cut -d' ' -f1 || echo "0")
local s=$(echo "$line" | grep -oE "[0-9]+ skipped" | head -n 1 | cut -d' ' -f1 || echo "0")
local res=" "
[[ $p -gt 0 ]] && res+="${OK} Passed: ${G}$p${RS} "
[[ $f -gt 0 ]] && res+="${FAIL} Failed: ${R}$f${RS} "
[[ $s -gt 0 ]] && res+="${WARN} Skipped: ${Y}$s${RS}"
[[ -n $(echo $res | tr -d ' ') ]] && echo -e "$res"
}
# ─────────────────────────────────────────────────────────────────
# MAIN
# ─────────────────────────────────────────────────────────────────
clear
div
printf " ${B}UnoSim Test & Build Pipeline${RS} ${D}(Log: %s)${RS}\n" "$LOG_FILE"
div
rm -f "$LOG_FILE"
[ -d temp ] && rm -rf temp/*
# 1. Statische Analyse
run_task "Statische Analyse" "npm run check"
# 2. Unit-Tests & Coverage
run_task "Unit-Tests & Coverage" "NODE_OPTIONS='--no-warnings' npm run test:unit -- --reporter=default --maxConcurrency=2"
parse_test_results "Tests.*passed"
# --- VORBEREITUNG SERVER (Kein nummerierter Task) ---
echo -e "\n${B}▸ [Vorbereitung] Server-Start${RS}"
lsof -ti:3000 | xargs kill -9 2>/dev/null || true
sleep 1
export PORT=3000
# Server startet im Hintergrund mit kontrolliertem Logging
npm run dev >> "$LOG_FILE" 2>&1 &
SERVER_PID=$!
for i in {1..15}; do
if curl -s http://localhost:3000 > /dev/null; then
echo -e " ${G}${OK} Server bereit (PID $SERVER_PID)${RS}"
break
fi
[ $i -eq 15 ] && echo -e " ${R}${FAIL} Server-Start Timeout!${RS}" && exit 1
sleep 1
done
# 3. E2E-Tests (Playwright)
run_task "E2E-Tests (Playwright)" "npx playwright test"
parse_test_results "([0-9]+ passed|[0-9]+ failed|[0-9]+ skipped)"
# 4. Integration-Tests (Cache)
run_task "Cache-Optimization Tests" "npx vitest run tests/server/cache-optimization.test.ts --reporter=default"
parse_test_results "Tests.*passed"
# Server stoppen
cleanup
SERVER_PID=""
# 5. Produktions-Build
run_task "Produktions-Build" "npm run build"
echo
div
printf " ${G}${B}${OK} Pipeline erfolgreich abgeschlossen${RS}\n"
div