-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-utils.sh
More file actions
158 lines (132 loc) Β· 3.72 KB
/
Copy pathtest-utils.sh
File metadata and controls
158 lines (132 loc) Β· 3.72 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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#!/bin/bash
set -euo pipefail
# Test Utilities for Local Development Environment
# This script provides utility functions for testing localhost:3000
# REQUIREMENTS: Git Bash, WSL, or Unix-like environment on Windows
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Configuration
LOCALHOST="http://localhost:3000"
TIMEOUT=5
# Print colored message
print_message() {
local color=$1
local message=$2
echo -e "${color}${message}${NC}"
}
# Check if server is running
check_server() {
print_message "$BLUE" "π Checking if dev server is running..."
if curl -s -f -m $TIMEOUT "$LOCALHOST" > /dev/null 2>&1; then
print_message "$GREEN" "β Dev server is running at $LOCALHOST"
return 0
else
print_message "$RED" "β Dev server is not accessible at $LOCALHOST"
print_message "$YELLOW" "π‘ Start it with: npm run dev"
return 1
fi
}
# Check specific route
check_route() {
local route=$1
local url="${LOCALHOST}${route}"
if curl -s -f -m $TIMEOUT "$url" > /dev/null 2>&1; then
print_message "$GREEN" "β Route accessible: $route"
return 0
else
print_message "$RED" "β Route not accessible: $route"
return 1
fi
}
# Check all main routes
check_all_routes() {
print_message "$BLUE" "\nπ Checking all main routes...\n"
local routes=(
"/"
"/tech-radar"
"/tech-radar/docs"
"/mcpflare"
"/legal/privacy"
"/legal/terms"
"/legal/security"
)
local failed=0
for route in "${routes[@]}"; do
if ! check_route "$route"; then
((failed++))
fi
done
echo ""
if [ $failed -eq 0 ]; then
print_message "$GREEN" "β All routes accessible!"
return 0
else
print_message "$RED" "β $failed route(s) failed"
return 1
fi
}
# Get page title
get_page_title() {
local route=$1
local url="${LOCALHOST}${route}"
local title=$(curl -s -m $TIMEOUT "$url" | grep -o '<title>[^<]*</title>' | sed 's/<title>\(.*\)<\/title>/\1/')
if [ -n "$title" ]; then
echo "$title"
else
echo "No title found"
fi
}
# Validate build
validate_build() {
print_message "$BLUE" "π¨ Validating production build...\n"
if npm run build > /dev/null 2>&1; then
print_message "$GREEN" "β Build succeeded"
return 0
else
print_message "$RED" "β Build failed"
print_message "$YELLOW" "π‘ Run 'npm run build' to see errors"
return 1
fi
}
# Quick health check
quick_check() {
print_message "$BLUE" "\nπ₯ Quick Health Check\n"
check_server
local server_status=$?
if [ $server_status -eq 0 ]; then
check_route "/"
check_route "/tech-radar"
check_route "/mcpflare"
fi
echo ""
if [ $server_status -eq 0 ]; then
print_message "$GREEN" "β Environment is healthy"
return 0
else
print_message "$RED" "β Environment check failed"
return 1
fi
}
# Full validation
full_validation() {
print_message "$BLUE" "\nπ Running Full Environment Validation\n"
check_server || return 1
echo ""
check_all_routes || return 1
}
# Export functions for use in other scripts
export -f check_server
export -f check_route
export -f check_all_routes
export -f get_page_title
export -f validate_build
export -f quick_check
export -f full_validation
# If script is run directly, do quick check
if [ "${BASH_SOURCE[0]}" -ef "$0" ]; then
quick_check
fi