Skip to content

Instantly share code, notes, and snippets.

@timjstewart
Created January 24, 2020 03:41
Show Gist options
  • Save timjstewart/1857e6865edd7ef242615ace9784a58a to your computer and use it in GitHub Desktop.
Save timjstewart/1857e6865edd7ef242615ace9784a58a to your computer and use it in GitHub Desktop.
#! /bin/bash
BROWSER=Chrome
CANCELLED=0
COVERAGE_DATA=.coverage
COVERAGE_REPORT_DIR=htmlcov
POLL_INTERVAL=5
trap ctrl_c INT
function refresh_browser() {
/usr/bin/osascript <<-APPLESCRIPT
tell application "Chrome" to tell the active tab of its first window
reload
end tell
APPLESCRIPT
}
function ctrl_c() {
CANCELLED=1
}
while [ "$CANCELLED" -eq "0" ]; do
if [ -r "${COVERAGE_DATA}" ]; then
if [ "${COVERAGE_DATA}" -nt "${COVERAGE_REPORT_DIR}" ] || [ ! -d "${COVERAGE_REPORT_DIR}" ]; then
echo "$(date) generating HTML report..."
if coverage html; then
echo "$(date) refreshing ${BROWSER}..."
refresh_browser
touch "${COVERAGE_REPORT_DIR}"
else
>2 echo "error generating coverage report"
fi
fi
fi
sleep ${POLL_INTVERVAL:-5}
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment