#!/usr/bin/env bash

# Turn on strict mode.
set -eEo pipefail

# Move to repo root
cd "${0%/*}/.."

# Add node_modules/.bin to PATH
PATH="$(pwd)/node_modules/.bin:$PATH"
export PATH

# Run the tests.
istanbul cover jasmine

# Check the code coverage.
if [[ "$CI" == "true" ]]; then
    codecov
elif [[ -d ".git" ]]; then
    # Easiest way to generate coverage files and not upload the report
    # is to use --dump.
    echo "Executing codecov and generating coverage report."
    codecov --dump > /dev/null
else
    # codecov runs git and hg.  If the folder is not under source control,
    # codecov breaks with some nasty error.  This situation happens during
    # deployment, so we just don't worry about coverage during deployment.
    echo "Not running code coverage report."
fi

echo "All tests pass."
