11#! /bin/bash
22
3- # TourGuideAI GitHub Actions Test Runner
4- # This script runs tests in a GitHub Actions environment
3+ # Enhanced GitHub Tests Runner Script
4+ # Updated with improved Jest configurations and parallel testing
55
6- set -e # Exit on any error
6+ set -e
77
8- echo " === TourGuideAI GitHub Actions Tests === "
9- echo " Starting tests at $( date ) "
8+ echo " 🚀 TourGuideAI Test Suite - Enhanced Edition "
9+ echo " ============================================== "
1010
11- # Set environment variables
12- export CI=true
13- export NODE_ENV=test
11+ # Colors for output
12+ GREEN=' \033[0;32m'
13+ RED=' \033[0;31m'
14+ YELLOW=' \033[1;33m'
15+ NC=' \033[0m' # No Color
1416
15- # Create results directories
16- RESULTS_DIR=" docs/project_lifecycle/all_tests/results"
17- mkdir -p " $RESULTS_DIR "
18- mkdir -p " $RESULTS_DIR /stability"
19- mkdir -p " $RESULTS_DIR /analytics"
20-
21- # Initialize counters
22- TOTAL_TESTS=0
23- PASSED_TESTS=0
24- FAILED_TESTS=0
25- SKIPPED_TESTS=0
26-
27- # Function to run a test category
28- run_test_category () {
29- local category=" $1 "
30- local test_path=" $2 "
31- local test_pattern=" ${3:-* .test.js} "
32-
33- echo " "
34- echo " 🧪 Running $category ..."
35-
36- if [ -d " $test_path " ]; then
37- # Count test files
38- local test_count=$( find " $test_path " -name " $test_pattern " -type f | wc -l)
39- TOTAL_TESTS=$(( TOTAL_TESTS + test_count))
40-
41- if [ $test_count -eq 0 ]; then
42- echo " ⚠️ No test files found in $test_path "
43- return 0
44- fi
45-
46- echo " Found $test_count test files"
47-
48- # Run tests with npm test
49- if npm test -- " $test_path " --passWithNoTests --silent --watchAll=false; then
50- echo " ✅ $category completed successfully"
51- PASSED_TESTS=$(( PASSED_TESTS + test_count))
52- else
53- echo " ⚠️ $category completed with issues"
54- FAILED_TESTS=$(( FAILED_TESTS + test_count))
55- fi
56- else
57- echo " ⚠️ Directory not found: $test_path "
58- SKIPPED_TESTS=$(( SKIPPED_TESTS + 1 ))
59- fi
17+ # Function to print colored output
18+ print_status () {
19+ echo -e " ${GREEN} ✓${NC} $1 "
6020}
6121
62- # Function to run security tests
63- run_security_tests () {
64- echo " "
65- echo " 🔒 Running Security Tests..."
66-
67- if [ -f " tests/security/security-audit.test.js" ]; then
68- if NODE_ENV=test npm test -- tests/security/security-audit.test.js --passWithNoTests --silent --watchAll=false; then
69- echo " ✅ Security tests completed"
70- PASSED_TESTS=$(( PASSED_TESTS + 1 ))
71- else
72- echo " ⚠️ Security tests completed with issues"
73- FAILED_TESTS=$(( FAILED_TESTS + 1 ))
74- fi
75- TOTAL_TESTS=$(( TOTAL_TESTS + 1 ))
76- else
77- echo " ⚠️ Security test file not found"
78- SKIPPED_TESTS=$(( SKIPPED_TESTS + 1 ))
79- fi
22+ print_error () {
23+ echo -e " ${RED} ✗${NC} $1 "
8024}
8125
82- # Function to run essential component tests
83- run_essential_components () {
84- echo " "
85- echo " 🎯 Running Essential Component Tests..."
86-
87- local essential_components=(
88- " src/tests/components/ApiStatus.test.js"
89- " src/tests/components/ProfilePage.test.js"
90- " src/tests/components/ErrorBoundary.test.js"
91- )
92-
93- for component in " ${essential_components[@]} " ; do
94- if [ -f " $component " ]; then
95- echo " Testing $( basename " $component " ) ..."
96- if npm test -- " $component " --passWithNoTests --silent --watchAll=false; then
97- echo " ✅ $( basename " $component " ) passed"
98- PASSED_TESTS=$(( PASSED_TESTS + 1 ))
99- else
100- echo " ⚠️ $( basename " $component " ) completed with issues"
101- FAILED_TESTS=$(( FAILED_TESTS + 1 ))
102- fi
103- TOTAL_TESTS=$(( TOTAL_TESTS + 1 ))
104- else
105- echo " ⚠️ $( basename " $component " ) not found"
106- SKIPPED_TESTS=$(( SKIPPED_TESTS + 1 ))
107- fi
108- done
26+ print_warning () {
27+ echo -e " ${YELLOW} ⚠${NC} $1 "
10928}
11029
111- # Run different test categories
112- run_security_tests
113- run_essential_components
114- run_test_category " API Tests" " src/tests/api"
115- run_test_category " Component Tests" " src/tests/components" " *.test.js"
116- run_test_category " Analytics Tests" " src/tests/components/analytics"
117- run_test_category " Integration Tests" " tests/integration"
118- run_test_category " Smoke Tests" " tests/smoke"
30+ # Initialize counters
31+ FRONTEND_TESTS_PASSED=0
32+ BACKEND_TESTS_PASSED=0
33+ TOTAL_ERRORS=0
34+
35+ echo " Starting comprehensive test execution..."
36+
37+ # Frontend Tests
38+ echo " Running Frontend Tests..."
39+ echo " ========================="
40+
41+ if npm run test:frontend; then
42+ print_status " Frontend tests completed successfully"
43+ FRONTEND_TESTS_PASSED=1
44+ else
45+ print_error " Frontend tests failed"
46+ TOTAL_ERRORS=$(( TOTAL_ERRORS + 1 ))
47+ fi
11948
120- # Generate summary
12149echo " "
122- echo " === Test Summary ==="
123- echo " Total tests: $TOTAL_TESTS "
124- echo " Passed: $PASSED_TESTS "
125- echo " Failed: $FAILED_TESTS "
126- echo " Skipped: $SKIPPED_TESTS "
127-
128- # Create summary file
129- SUMMARY_FILE=" $RESULTS_DIR /github-test-summary.txt"
130- cat > " $SUMMARY_FILE " << EOF
131- === TourGuideAI GitHub Actions Test Summary ===
132- Run Date: $( date)
133- Total tests: $TOTAL_TESTS
134- Passed: $PASSED_TESTS
135- Failed: $FAILED_TESTS
136- Skipped: $SKIPPED_TESTS
137-
138- Status: $(( PASSED_TESTS > 0 && FAILED_TESTS == 0 ? "SUCCESS" : "COMPLETED_WITH_ISSUES"))
139- EOF
50+
51+ # Backend Tests
52+ echo " Running Backend Tests..."
53+ echo " ========================"
54+
55+ if npm run test:backend; then
56+ print_status " Backend tests completed successfully"
57+ BACKEND_TESTS_PASSED=1
58+ else
59+ print_error " Backend tests failed"
60+ TOTAL_ERRORS=$(( TOTAL_ERRORS + 1 ))
61+ fi
14062
14163echo " "
142- echo " Test summary saved to: $SUMMARY_FILE "
143- echo " Tests completed at $( date) "
14464
145- # Exit with success code since we're using continue-on-error in workflows
146- exit 0
65+ # Test Summary
66+ echo " Test Execution Summary"
67+ echo " ====================="
68+ echo " Frontend Tests: $( [ $FRONTEND_TESTS_PASSED -eq 1 ] && echo ' ✅ PASSED' || echo ' ❌ FAILED' ) "
69+ echo " Backend Tests: $( [ $BACKEND_TESTS_PASSED -eq 1 ] && echo ' ✅ PASSED' || echo ' ❌ FAILED' ) "
70+ echo " Total Errors: $TOTAL_ERRORS "
71+
72+ if [ $TOTAL_ERRORS -eq 0 ]; then
73+ print_status " All test suites completed successfully!"
74+ exit 0
75+ else
76+ print_error " Some test suites failed. Please review the output above."
77+ exit 1
78+ fi
0 commit comments