Skip to content

Instantly share code, notes, and snippets.

@fmontes
Created August 23, 2017 20:13
Show Gist options
  • Save fmontes/9d013808dd54d0579b7cbcd514d9ceeb to your computer and use it in GitHub Desktop.
Save fmontes/9d013808dd54d0579b7cbcd514d9ceeb to your computer and use it in GitHub Desktop.
Githook to run the test before push
#!/bin/sh
red="\033[0;31m"
yellow="\033[1;33m"
green="\033[1;32m"
reset="\033[0m"
# now if your "package.json" isn't in the root directory
# just "cd" there
# eg.
# cd folder/with/my-package
printf "${yellow}Starting Unit Tests for JS Files:${reset}\n"
# now lets run tests
# eg.
# karma start --single-run --browsers PhantomJS --reporters dots
# or
# eslint .
# or
# mocha --colors --bail
# but we'll do more general
npm run test
# now if tests failed let's abort commit by "exit 1"
# if not, congratulations, commit is now in Git
testResults=$?
if [ $testResults -eq 1 ]
then
echo -e "${red}\n Tests FAILED push ABORTED\n ${reset}"
exit 1
else
echo -e "${green}\nTests are GOOD pushing now\n${reset}"
fi
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment