113 lines
3.3 KiB
Bash
Executable File
113 lines
3.3 KiB
Bash
Executable File
#!/bin/bash
|
|
# =====================================================================
|
|
# run-all-tests.sh - Run all tests against an existing server
|
|
# =====================================================================
|
|
# This script runs all tests against an existing server
|
|
# =====================================================================
|
|
|
|
set -e # Exit on any error
|
|
|
|
# Define constants
|
|
BASE_URL="http://localhost:8080"
|
|
TESTS_DIR="$(dirname "$0")"
|
|
|
|
# Run pre-test setup
|
|
echo "Running pre-test setup..."
|
|
if [ -f "$TESTS_DIR/pre-test-setup.sh" ]; then
|
|
"$TESTS_DIR/pre-test-setup.sh"
|
|
else
|
|
echo "Warning: pre-test-setup.sh not found, skipping setup"
|
|
fi
|
|
|
|
# Check if the server is running
|
|
echo "Checking if server is running at $BASE_URL..."
|
|
if ! curl -s -o /dev/null -w "%{http_code}" "$BASE_URL/" | grep -q "200"; then
|
|
echo "Server is not running at $BASE_URL. Please start it using:"
|
|
echo "cd docker/resume && ./caddy.sh"
|
|
exit 1
|
|
fi
|
|
|
|
echo "Server is running at $BASE_URL"
|
|
|
|
# Run shell script tests
|
|
run_shell_tests() {
|
|
echo "Running shell script tests..."
|
|
|
|
# Run unit tests
|
|
echo "Running unit tests..."
|
|
if [ -d "$TESTS_DIR/unit" ] && [ "$(ls -A "$TESTS_DIR/unit")" ]; then
|
|
for test in "$TESTS_DIR/unit"/*.sh; do
|
|
if [ -f "$test" ] && [ -x "$test" ]; then
|
|
echo "Running unit test: $(basename "$test")"
|
|
"$test" || echo "FAILED: $(basename "$test")"
|
|
fi
|
|
done
|
|
else
|
|
echo "No unit tests found."
|
|
fi
|
|
|
|
# Run integration tests
|
|
echo "Running integration tests..."
|
|
if [ -d "$TESTS_DIR/integration" ] && [ "$(ls -A "$TESTS_DIR/integration")" ]; then
|
|
for test in "$TESTS_DIR/integration"/*.sh; do
|
|
if [ -f "$test" ] && [ -x "$test" ]; then
|
|
echo "Running integration test: $(basename "$test")"
|
|
"$test" "$BASE_URL" || echo "FAILED: $(basename "$test")"
|
|
fi
|
|
done
|
|
|
|
# Check for subdirectories
|
|
for dir in "$TESTS_DIR/integration"/*/; do
|
|
if [ -d "$dir" ]; then
|
|
for test in "$dir"*.sh; do
|
|
if [ -f "$test" ] && [ -x "$test" ]; then
|
|
echo "Running integration test: $(basename "$test")"
|
|
"$test" "$BASE_URL" || echo "FAILED: $(basename "$test")"
|
|
fi
|
|
done
|
|
fi
|
|
done
|
|
else
|
|
echo "No integration tests found."
|
|
fi
|
|
|
|
# Run e2e tests
|
|
echo "Running e2e tests..."
|
|
if [ -d "$TESTS_DIR/e2e" ] && [ "$(ls -A "$TESTS_DIR/e2e")" ]; then
|
|
for test in "$TESTS_DIR/e2e"/*.sh; do
|
|
if [ -f "$test" ] && [ -x "$test" ]; then
|
|
echo "Running e2e test: $(basename "$test")"
|
|
"$test" "$BASE_URL" || echo "FAILED: $(basename "$test")"
|
|
fi
|
|
done
|
|
else
|
|
echo "No e2e tests found."
|
|
fi
|
|
}
|
|
|
|
# Run JavaScript tests
|
|
run_js_tests() {
|
|
echo "Running JavaScript tests..."
|
|
|
|
# Check if Playwright is installed
|
|
if command -v npx &> /dev/null && npx playwright --version &> /dev/null; then
|
|
# Run Playwright tests
|
|
echo "Running Playwright tests..."
|
|
npx playwright test || echo "FAILED: Playwright tests"
|
|
else
|
|
echo "Playwright not found, skipping Playwright tests."
|
|
fi
|
|
|
|
# Run Lighthouse tests if available
|
|
if [ -f "$TESTS_DIR/lighthouse.js" ]; then
|
|
echo "Running Lighthouse tests..."
|
|
node "$TESTS_DIR/lighthouse.js" "$BASE_URL" || echo "FAILED: Lighthouse tests"
|
|
fi
|
|
}
|
|
|
|
# Main execution
|
|
echo "=== Starting Test Suite ==="
|
|
run_shell_tests
|
|
run_js_tests
|
|
echo "=== Test Suite Completed ==="
|