#!/usr/bin/env sh

LC_ALL=C

# Print colorful message function
print_message() {
  case $2 in
    "info") printf " \033[1;34m${1}\033[0m\n" ;;
    "warning") printf " \033[1;33m⚠️ ${1}\033[0m\n" ;;
    "error") printf " \033[1;31m❌ Error:\033[0m ${1}\n" ;;
    "success") printf " \033[1;32m✅ Success:\033[0m ${1}\n" ;;
  esac
}

# abort on script error
set -e

print_message "Running tests before push..." "info"

# Run tests and capture the exit status
if yarn test; then
    print_message "All tests passed. Proceeding with push." "success"
    exit 0
else
    print_message "Tests failed! Please fix the errors and try again." "error"
    print_message "Push aborted." "warning"
    exit 1
fi