#!/bin/bash
# test-all.sh
# Author: Matthew Raymer
# Description: Comprehensive test suite for TimeSafari application
# This script runs all tests including prerequisites, web tests, and mobile tests
# with proper error handling and logging.
#
# Exit Codes:
# 1 - Prerequisites check failed
# 2 - Build failed
# 3 - Web tests failed
# 4 - Mobile tests failed

# Exit on any error
set -e

# Source common utilities
source "$(dirname "$0")/common.sh"

# Parse command line arguments
parse_args "$@"

# Print test header
print_header "TimeSafari Test Suite"
log_info "Starting comprehensive test suite at $(date)"

# Step 1: Check prerequisites
safe_execute "Checking prerequisites" "npm run test:prerequisites" || exit 1

# Step 2: Build the application
safe_execute "Building application" "npm run build" || exit 2

# Step 3: Run web tests
safe_execute "Running web tests" "npm run test:web" || exit 3

# Step 4: Run mobile tests
safe_execute "Running mobile tests" "npm run test:mobile" || exit 4

# Print test summary
log_success "All tests completed successfully!"
print_footer "Test Suite"

# Exit with success
exit 0 