#!/bin/bash

set -eo pipefail

yarn -s compile:typescript

yarn -s lint --short

echo
echo "+===========================================================================+"
echo "|                            BEGIN TESTING ...                              |"
echo "+===========================================================================+"
echo

export NODE_ENV=development

if [[ $1 == 'ALL' ]] ; then
  echo "Note: 'testall' runs scripts with prefix 'skip-' as well."
  mocha --exit --trace-warnings -r source-map-support/register -c "build/test/**/@(skip|test)-*.js" 3>&2 2>&1 1>&3- | bunyan -L -o short -l fatal
else
  mocha --exit --trace-warnings -r source-map-support/register -c "build/test/**/@(test-*$1*|$1).js" 3>&2 2>&1 1>&3- | bunyan -L -o short
fi

yarn doc > /dev/null &
yarn copylib > /dev/null &

wait
echo "Note: In watch mode, it will auto restart on code change. Ctrl-C to exit."

echo
echo "+===========================================================================+"
echo "|                                TEST END                                   |"
echo "+===========================================================================+"
echo