#!/usr/bin/env bash set -e cd "$(dirname "$0")/.." RED='\033[0;31m' GREEN='\033[0;32m' NC='\033[0m' # No Color function mock_is_running() { curl --silent "http://127.0.0.1:4010/_sdkgen/health" >/dev/null 2>&1 } kill_server_on_port() { pids=$(lsof -t -i tcp:"$1" || echo "") if [ "$pids" != "" ]; then kill "$pids" echo "Stopped $pids." fi } function is_overriding_api_base_url() { [ -n "$TEST_API_BASE_URL" ] } if ! is_overriding_api_base_url && ! mock_is_running ; then # When we exit this script, make sure to kill the background mock server process trap 'kill_server_on_port 4010' EXIT ./scripts/mock --daemon fi if is_overriding_api_base_url ; then echo -e "${GREEN}✔ Running tests against ${TEST_API_BASE_URL}${NC}" echo elif ! mock_is_running ; then echo -e "${RED}ERROR:${NC} The test suite will not run without the sdkgen mock server; start it with ./scripts/mock" exit 1 else echo -e "${GREEN}✔ sdkgen mock server is running${NC}" echo fi echo "==> Running tests" ./node_modules/.bin/jest "$@"