Skip to content

Instantly share code, notes, and snippets.

@ParvJain
Last active October 29, 2020 16:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ParvJain/778be798b27eaacf66a9059f1092f6bb to your computer and use it in GitHub Desktop.
Save ParvJain/778be798b27eaacf66a9059f1092f6bb to your computer and use it in GitHub Desktop.
git pre-push hook to check code coverage w/ nyc
#!/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