Test Runner (allows defining number of iterations and optional reporters)
#!/bin/bash
# syntax
# $ ./test.sh -n # -q # | true
# script colors
YELLOW='\033[1;33m'
LIGHTBLUE='\033[1;36m'
GREEN='\033[1;32m'
NC='\033[0m'
RESET='\033[0m'
# set default values (will be updated by getopts)
ITERATIONS=1
QUIET=-1
REPORTER='mocha'
while getopts ":n:q:r:" opt; do
case $opt in
q) QUIET=$OPTARG;;
n) ITERATIONS=$OPTARG;;
r) REPORTER=$OPTARG;;
\?)
# echo "Invalid option: -$OPTARG" >&2 ;;
esac
done
# coerce QUIET if we passed true | false
if [ $QUIET = 'true' ]; then QUIET=1; fi
if [ $QUIET = 'false' ]; then QUIET=0; fi
printf "\n"
for (( index=1; index<=ITERATIONS; index++ ))
do
if [ $QUIET -ne 1 ]; then
if [ $REPORTER != 'dots' ]; then
printf "\n\n [${LIGHTBLUE} running ${RESET}] ${YELLOW} Running Test $index of ${ITERATIONS} ... ${RESET}\n\n"
fi
fi
if [ $REPORTER = 'dots' ]; then
karma start --reporters super-dots
else
karma start
fi
if [ $QUIET -ne 1 ]; then
if [ $REPORTER = 'dots' ]; then
printf "\n\n"
else
printf "\n [${GREEN} complete ${RESET}] ${YELLOW} Completed $index of ${ITERATIONS} ... ${RESET}\n"
fi
fi
done
timestamp=`date +"%Y.%m.%d %H:%M:%S"`
if [ $ITERATIONS > 0 ]; then
printf "\n\n"
printf "${GREEN}====================================================================================================\n\n"
printf "${GREEN} === [${ITERATIONS}] Test(s) Processed [${timestamp}] ${RESET}\n\n"
printf "\n"
fi