forked from Ammaar-Alam/tigertype
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpre-commit
More file actions
executable file
·64 lines (50 loc) · 1.81 KB
/
pre-commit
File metadata and controls
executable file
·64 lines (50 loc) · 1.81 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
#!/bin/bash
# TigerType Pre-Commit Hook
# This hook will run tests before allowing a commit
# Source the user's shell environment
if [ -f "$HOME/.bashrc" ]; then
source "$HOME/.bashrc"
fi
if [ -f "$HOME/.bash_profile" ]; then
source "$HOME/.bash_profile"
fi
# Get the directory where the pre-commit hook is located
HOOK_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# Get the project root directory (parent of .git)
PROJECT_ROOT="$( cd "$HOOK_DIR/../.." && pwd )"
# Change to the project root directory
cd "$PROJECT_ROOT"
echo -e "\033[1;33mRunning TigerType tests before commit...\033[0m"
# Ensure dependencies are installed
echo -e "\033[1;36mEnsuring dependencies are installed...\033[0m"
npm install --silent
# Save current changes so tests run on the actual code being committed
git stash -q --keep-index
# Run server tests using jest directly
echo -e "\033[1;36mRunning server tests...\033[0m"
./node_modules/.bin/jest --detectOpenHandles --verbose --testPathPattern=server
# Store the server test exit code
SERVER_EXIT_CODE=$?
# If running in CI, also run client tests
if [ -n "$CI" ]; then
echo -e "\033[1;36mRunning client tests in CI environment...\033[0m"
cd client && npm run test:progress
CLIENT_EXIT_CODE=$?
else
# In local environment, make client tests optional
echo -e "\033[1;36mSkipping client tests in local environment.\033[0m"
CLIENT_EXIT_CODE=0
fi
# Restore stashed changes
git stash pop -q
# Check if any tests failed
if [ $SERVER_EXIT_CODE -ne 0 ]; then
echo -e "\033[1;31m❌ Server tests failed. Please fix the issues before committing.\033[0m"
exit 1
fi
if [ $CLIENT_EXIT_CODE -ne 0 ]; then
echo -e "\033[1;31m❌ Client tests failed. Please fix the issues before committing.\033[0m"
exit 1
fi
echo -e "\033[1;32m✅ All tests passed! Proceeding with commit...\033[0m"
exit 0