#!/bin/bash # Test script for the debug pre-commit hook # This script helps verify that the hook is working correctly set -e echo "๐งช Testing TimeSafari Debug Pre-commit Hook" echo "=============================================" # Colors for output RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' BLUE='\033[0;34m' NC='\033[0m' # No Color # Test directory TEST_DIR="$(mktemp -d)" echo -e "${BLUE}Created test directory: $TEST_DIR${NC}" # Function to cleanup cleanup() { echo -e "${YELLOW}Cleaning up test directory...${NC}" rm -rf "$TEST_DIR" } # Set trap to cleanup on exit trap cleanup EXIT # Function to run test run_test() { local test_name="$1" local test_file="$2" local expected_exit="$3" echo -e "\n${BLUE}Running test: $test_name${NC}" # Create test file echo "$test_file" > "$TEST_DIR/test.vue" # Stage the file cd "$TEST_DIR" git init > /dev/null 2>&1 git add test.vue > /dev/null 2>&1 # Run the hook if bash ../../.git/hooks/pre-commit > hook_output.txt 2>&1; then exit_code=0 else exit_code=$? fi # Check result if [[ $exit_code -eq $expected_exit ]]; then echo -e " ${GREEN}โ PASS${NC} - Exit code: $exit_code (expected: $expected_exit)" else echo -e " ${RED}โ FAIL${NC} - Exit code: $exit_code (expected: $expected_exit)" echo -e " ${YELLOW}Hook output:${NC}" cat hook_output.txt fi # Cleanup git rm -rf .git rm -f hook_output.txt } # Test cases echo -e "\n${BLUE}Test Case 1: Clean file (should pass)${NC}" run_test "Clean file" "// No debug code here" 0 echo -e "\n${BLUE}Test Case 2: Console statement (should fail)${NC}" run_test "Console statement" "console.log('debug info')" 1 echo -e "\n${BLUE}Test Case 3: Debug template (should fail)${NC}" run_test "Debug template" "Debug: {{ isMapReady ? 'Map Ready' : 'Map Loading' }}" 1 echo -e "\n${BLUE}Test Case 4: Debug constant (should fail)${NC}" run_test "Debug constant" "const DEBUG_MODE = true" 1 echo -e "\n${BLUE}Test Case 5: Mixed content (should fail)${NC}" run_test "Mixed content" "// Some normal code\nconsole.debug('test')\n// More normal code" 1 echo -e "\n${BLUE}Test Case 6: HTML debug comment (should fail)${NC}" run_test "HTML debug comment" "" 1 echo -e "\n${BLUE}Test Case 7: Debug attribute (should fail)${NC}" run_test "Debug attribute" "