Skip to content

Commit

Permalink
fix: update pre commit hook to skip test for outside src changes
Browse files Browse the repository at this point in the history
  • Loading branch information
dev-ahmadbilal committed Aug 30, 2024
1 parent 53c39af commit 4e11105
Showing 1 changed file with 21 additions and 12 deletions.
33 changes: 21 additions & 12 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,29 @@
# Run linting
npm run lint

echo "Linting passed. Proceeding with the unit tests."
# Get the list of changed files in the commit
CHANGED_FILES=$(git diff --cached --name-only)

# Run NestJS unit tests
echo "Running NestJS unit tests..."
npm run test
# Check if any of the changed files are under the `src` folder
if echo "$CHANGED_FILES" | grep -q '^src/'; then
echo "Changes detected in the src folder. Running unit tests..."

# Capture the exit code of the tests
TEST_RESULT=$?
# Run islam.js unit tests
echo "Running islam.js unit tests..."
npm run test

# Check if tests passed
if [ $TEST_RESULT -ne 0 ]; then
echo "Tests failed. Please fix the issues before committing."
exit $TEST_RESULT
# Capture the exit code of the tests
TEST_RESULT=$?

# Check if tests passed
if [ $TEST_RESULT -ne 0 ]; then
echo "Tests failed. Please fix the issues before committing."
exit $TEST_RESULT
fi

echo "Tests passed. Proceeding with the commit."
else
echo "No changes detected in the src folder. Skipping unit tests."
fi

echo "Tests passed. Proceeding with the commit."
exit 0
exit 0

0 comments on commit 4e11105

Please sign in to comment.