-
Notifications
You must be signed in to change notification settings - Fork 2
/
test.sh
executable file
·36 lines (31 loc) · 1.13 KB
/
test.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/env bash
# Run jest and start a local DB for integration tests if we are running locally
if [[ -z "${HOWDJU_RUNNING_IN_GITHUB_WORKFLOW+present}" ]]; then
echo "Not in a Github action; starting a temporary local Postgres container"
export $(cat ../config/test.env | xargs)
image_id=$(docker run --rm -d -p $DB_PORT:5432 -e POSTGRES_PASSWORD=$DB_PASSWORD postgres:12.5 postgres)
if [[ $? -ne 0 ]]; then
echo "Failed to start docker image"
exit 1
fi
echo "Started docker image ${image_id}"
fi
function cleanup {
if [[ -n "${image_id}" ]]; then
echo "Stopping docker image ${image_id}"
docker stop $image_id
fi
}
trap cleanup EXIT
if [[ $1 == "inspect" ]]; then
# Assume that $2 is either a file filter (which must come immediately after the jest command to
# count as a positional argument) or a flag which can go anywhere.)
echo "Running: node --inspect-brk ../node_modules/.bin/jest $2 --runInBand --watch ${@:3}"
node --inspect-brk ../node_modules/.bin/jest "${2}" --runInBand --watch "${@:3}"
jest_status=$?
else
echo "Running: jest ${@:1}"
jest "${@:1}"
jest_status=$?
fi
exit $jest_status