-
Notifications
You must be signed in to change notification settings - Fork 2
/
integration-test.sh
52 lines (41 loc) · 1.85 KB
/
integration-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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/bin/sh
set -e
PROJECT="integresql_client"
echo "-> Shutting down previous containers..."
docker ps -a -q --filter "name=${PROJECT}_" | xargs -r docker rm -f
echo ""
echo "-> Checking ports..."
if lsof -Pi :5432 -sTCP:LISTEN -t >/dev/null ; then echo "\n/!\ Something is already listening on port '5432'!" && exit 1; fi
if lsof -Pi :5000 -sTCP:LISTEN -t >/dev/null ; then echo "\n/!\ Something is already listening on port '5000'!" && exit 1; fi
echo ""
echo "-> Starting PostgreSQL..."
docker run --rm -d --name "${PROJECT}_postgres" -e POSTGRES_PASSWORD=postgres -p 5432:5432 postgres:14.8-alpine \
postgres -c 'fsync=off' -c 'synchronous_commit=off' -c 'full_page_writes=off'
echo ""
echo "-> Starting IntegreSQL..."
docker run --rm -d --name "${PROJECT}_integresql" -e INTEGRESQL_PGPASSWORD=postgres --network host allaboutapps/integresql:latest
echo ""
echo "-> Generating Prisma client..."
yarn prisma generate
echo ""
echo "-> Duplicating integration tests..."
for i in $(seq 1 10);
do
cp tests-integration/user.spec.ts tests-integration/user$i.spec.ts
done
echo ""
echo "-> Running integration tests (cold)..."
rm -f integration-test.log
yarn jest tests-integration/ 2>&1 | tee integration-test.log
echo ""
echo "-> Checking migration behaviour (cold)..."
MIGRATION_COUNT=$(cat integration-test.log | grep "Migrating template database" | wc -l)
if [ "$MIGRATION_COUNT" != "1" ]; then echo "\n/!\ Migrations for template database did not run 1 time!" && exit 1; fi
echo ""
echo "-> Running integration tests (warm)..."
rm -f integration-test.log
yarn jest tests-integration/ 2>&1 | tee integration-test.log
echo ""
echo "-> Checking migration behaviour (warm)..."
MIGRATION_COUNT=$(cat integration-test.log | grep "Migrating template database" | wc -l)
if [ "$MIGRATION_COUNT" != "0" ]; then echo "\n/!\ Migrations for template database did not run 0 times!" && exit 1; fi