1 | #!/bin/bash
|
2 |
|
3 | set -e
|
4 |
|
5 | RED='\033[0;31m'
|
6 | YELLOW='\033[0;33m'
|
7 | NC='\033[0m'
|
8 |
|
9 | ENV=${NODE_ENV:-test}
|
10 | if [[ $ENV != "test" ]]; then
|
11 | echo -e "${RED}ERROR${NC}: Cannot run unit tests out of the test environment"
|
12 | exit 1
|
13 | fi
|
14 |
|
15 | TEST_COUNT=${1:-}
|
16 |
|
17 | STATUS_RESPONSE=$(git status)
|
18 | NOT_STAGED_FOR_COMMIT="^.*not staged for commit.*$"
|
19 | UNTRACKED_FILES="^.*Untracked files.*$"
|
20 | if [[ $TEST_COUNT != "watch" && ($STATUS_RESPONSE =~ $NOT_STAGED_FOR_COMMIT || $STATUS_RESPONSE =~ $UNTRACKED_FILES) ]]; then
|
21 | echo -e "${YELLOW}WARNING${NC}: You have unstaged changes. These tests might not have correct results."
|
22 | fi
|
23 |
|
24 | if [[ $TEST_COUNT == "watch" ]]; then
|
25 | node_modules/.bin/mocha-typescript-watch -p tsconfig.json "dist/**/*.spec.js"
|
26 | else
|
27 | node_modules/.bin/mocha --require ts-node/register "src/**/*.spec.ts"
|
28 | fi
|
29 |
|
30 | exit 0
|