Last active
October 29, 2020 16:32
-
-
Save ParvJain/778be798b27eaacf66a9059f1092f6bb to your computer and use it in GitHub Desktop.
git pre-push hook to check code coverage w/ nyc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Setting benchmark to 80% coverage | |
passing_marks=8000 | |
echo "Running tests..." && | |
nyc -r cobertura -r text-summary mocha ./test/**/*.js --exit | |
echo "Finished, and generated coverage report..." | |
test_coverage=$(echo 'cat //coverage/@line-rate' | xmllint --shell ./coverage/cobertura-coverage.xml | awk -F'[="]' '!/>/{print $(NF-1)}' | cut -d. -f2) | |
if [ "$test_coverage" -lt "$passing_marks" ] | |
then | |
echo "❌ Your test coverage is below 80 percent, cannot procceed with commit!" | |
exit 1 | |
else | |
echo "✅ ELIGIBLE TO MAKE COMMIT, YOU PASSED!" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment