This repository has been archived by the owner on Mar 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathe2e.sh
executable file
·138 lines (113 loc) · 3.38 KB
/
e2e.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#!/bin/bash
#
# Postfacto, a free, open-source and self-hosted retro tool aimed at helping
# remote teams.
#
# Copyright (C) 2016 - Present Pivotal Software, Inc.
#
# This program is free software: you can redistribute it and/or modify
#
# it under the terms of the GNU Affero General Public License as
#
# published by the Free Software Foundation, either version 3 of the
#
# License, or (at your option) any later version.
#
#
#
# This program is distributed in the hope that it will be useful,
#
# but WITHOUT ANY WARRANTY; without even the implied warranty of
#
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
#
# GNU Affero General Public License for more details.
#
#
#
# You should have received a copy of the GNU Affero General Public License
#
# along with this program. If not, see <https://www.gnu.org/licenses/>.
set -e
BASE_DIR="$(dirname "$0")"
export RAILS_ENV="test"
export USE_MOCK_GOOGLE=true
export BASE_WEB_URL="http://localhost:4000"
export RETRO_ADMIN_BASE_URL="http://localhost:4000/admin"
export GOOGLE_AUTH_ENDPOINT="http://localhost:3100/auth"
API_LOG="$BASE_DIR/test-api-server.log";
WEB_LOG="$BASE_DIR/test-web-server.log";
# Update database
pushd "$BASE_DIR/api" >/dev/null
echo 'Dropping test database...'
bundle exec rake db:drop
echo 'Migrating test database...'
bundle exec rake db:create db:migrate db:test:prepare
echo 'Seeding test data...'
bundle exec rake db:seed
popd >/dev/null
# Set up trap to ensure spawned processes are killed in all situations
SPAWNED_PIDS="";
kill_pid_tree() {
# Behaviour of react_scripts node servers makes them hard to kill;
# must identify child and grandchild processes
PID="$1"
SUBPID1="$(pgrep -P "$PID" || true)"
if [[ -n "$SUBPID1" ]]; then
SUBPID2="$(pgrep -P "$SUBPID1" || true)"
if [[ -n "$SUBPID2" ]]; then
kill "$SUBPID2" >/dev/null 2>&1 || true
fi
kill "$SUBPID1" >/dev/null 2>&1 || true
fi
kill "$PID" >/dev/null 2>&1 || true
}
kill_spawned() {
if [[ -n "$SPAWNED_PIDS" ]]; then
echo "Shutting down child processes $SPAWNED_PIDS"
for PID in $SPAWNED_PIDS; do
kill_pid_tree "$PID"
done
SPAWNED_PIDS=""
fi
}
register_spawned() {
SPAWNED_PIDS="$SPAWNED_PIDS $1"
}
if [[ "$EPHEMERAL_CONTAINER" != "true" ]]; then
# If we kill the script or a test fails, ensure it is cleaned up
# (only necessary if we are in a long-lived container, i.e. not in CI)
trap "kill_spawned; sleep 1; echo 'e2e tests failed :('; false;" EXIT
fi
# Launch mock auth server
npm --prefix="$BASE_DIR/mock-google-server" start &
register_spawned $!
# Create static content
echo 'Building frontend in E2E test mode...'
rm -rf "$BASE_DIR/api/client/*"
npm --prefix="$BASE_DIR/web" run build
cp -a "$BASE_DIR/web/build/." "$BASE_DIR/api/client"
# Launch API
pushd "$BASE_DIR/api" >/dev/null
echo 'Launching API...'
echo > "$API_LOG"
bundle exec rails server -b 0.0.0.0 -p 4000 -e "$RAILS_ENV" >> "$API_LOG" 2>&1 &
register_spawned $!
echo 'Waiting for API...'
( tail -f -n10 "$API_LOG" & ) | grep -q 'Listening' || true
popd >/dev/null
# Run tests
pushd "$BASE_DIR/e2e" >/dev/null
echo 'Running E2E tests...'
bundle exec rspec "$@"
popd >/dev/null
# Shutdown services
kill_spawned;
if [[ "$EPHEMERAL_CONTAINER" != "true" ]]; then
trap - EXIT
fi
# Successful, so remove log files
rm "$API_LOG" >/dev/null || true
rm "$WEB_LOG" >/dev/null || true
sleep 1;
echo "E2E tests passed"