-
Notifications
You must be signed in to change notification settings - Fork 0
/
e2e.sh
225 lines (174 loc) · 4.75 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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
#
# /bin/bash e2e.sh --env .env --match tests/browser/browser.js
# /bin/bash e2e.sh --env .env --match tests/browser/browser.js --stay
# /bin/bash e2e.sh --env .env --match tests/browser/browser.js -- --target docker
#
_SHELL="$(ps "${$}" | grep "${$} " | grep -v grep | sed -rn "s/.*[-\/]+(bash|z?sh) .*/\1/p")"; # bash || sh || zsh
case ${_SHELL} in
zsh)
_DIR="$( cd "$( dirname "${(%):-%N}" )" && pwd -P )"
_0="$( basename "${(%):-%N}" )"
_SCRIPT="${(%):-%N}"
_BINARY="/bin/zsh"
_PWD="$(pwd)"
;;
sh)
_DIR="$( cd "$( dirname "${0}" )" && pwd -P )"
_0="$( basename "${0}" )"
_SCRIPT="${0}"
_BINARY="/bin/sh"
_PWD="$(pwd)"
;;
*)
_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd -P )"
_0="$( basename "${BASH_SOURCE[0]}" )"
_SCRIPT="${BASH_SOURCE[0]}"
_BINARY="/bin/bash"
_PWD="$(pwd)"
;;
esac
cd "${_DIR}"
ROOT="${_DIR}"
function ec {
echo "[${0}]: ${1}"
}
ls -la dist/validator.js 1> /dev/null 2> /dev/null
if [ "${?}" != "0" ]; then
ec "error: dist/validator.js doesn't exist - run first /bin/bash build.sh"
exit 1
fi
ENVFILE=""
PARAMS=""
STAY="0"
PLAYWRIGHT_TEST_MATCH=""
_EVAL=""
function quote {
echo "$1" | sed -E 's/\"/\\"/g'
}
function collect {
if [ "$1" = "&&" ]; then
PARAMS="$PARAMS \&\&"
_EVAL="$_EVAL &&"
else
if [ "$PARAMS" = "" ]; then
PARAMS="\"$(quote "$1")\""
_EVAL="\"$(quote "$1")\""
else
PARAMS="$PARAMS \"$(quote "$1")\""
_EVAL="$_EVAL \"$(quote "$1")\""
fi
fi
}
while (( "$#" )); do
case "$1" in
--env)
if [ "$2" = "" ]; then # PUT THIS CHECKING ALWAYS HERE IF YOU WAITING FOR VALUE
ec "error: --env value can't be empty" >&2 # optional
exit 1; # optional
fi
if ! [ -f "$2" ]; then
ec "error: --env file '$2' doesn't exist" >&2 # optional
exit 1; # optional
fi # optional
ENVFILE="$2";
shift 2;
;;
--match)
if [ "$2" = "" ]; then # PUT THIS CHECKING ALWAYS HERE IF YOU WAITING FOR VALUE
ec "error: --match value can't be empty" >&2 # optional
exit 1; # optional
fi # optional
PLAYWRIGHT_TEST_MATCH="$2";
shift 2;
;;
-s|--stay) # optional
STAY="1";
shift;
;;
--) # end argument parsing
shift;
while (( "$#" )); do # optional
collect "${1}" "${2}";
shift; # optional
done # optional if you need to pass: /bin/bash $0 -f -c -- -f "multi string arg"
break;
;;
-*|--*=) # unsupported flags
ec "error: Unsupported flag $1" >&2
exit 1;
;;
*) # preserve positional arguments
collect "${1}" "${2}";
shift;
;;
esac
done
eval set -- "$PARAMS"
trim() {
local var="$*"
# remove leading whitespace characters
var="${var#"${var%%[![:space:]]*}"}"
# remove trailing whitespace characters
var="${var%"${var##*[![:space:]]}"}"
echo -n "$var"
}
PARAMS="$(trim "$PARAMS")"
_EVAL="$(trim "$_EVAL")"
if [ "${PLAYWRIGHT_TEST_MATCH}" != "" ]; then
export PLAYWRIGHT_TEST_MATCH;
fi
if [ "${ENVFILE}" = "" ]; then
ec "error: first argument ENVFILE is not defined"
exit 1;
fi
if [ ! -f "${ENVFILE}" ]; then
ec "first argument ${ENVFILE} doesn't exist"
exit 1
fi
set -e
# source "${ENVFILE}";
eval "$(/bin/bash "${_DIR}/jasmine/lib/exportsource.sh" "${ENVFILE}")"
set +e
if [ "${NODE_API_HOST}" = "" ]; then
ec "error: NODE_API_PORT is not defined"
exit 1;
fi
if [ "${NODE_API_HOST}" = "" ]; then
ec "error: NODE_API_HOST is not defined"
exit 1;
fi
SERVER="http://${NODE_API_HOST}:${NODE_API_PORT}";
echo "SERVER: ${SERVER}"
function cleanup {
echo 'clean...'
set +e
curl -sS "${SERVER}/exit" 2>/dev/null
unlink "${ASSETLIST}" 2>/dev/null || true
}
cleanup
trap cleanup EXIT;
sleep 0.2
set -e
set -x
node "${_DIR}/jasmine/server_koa.js" --web "${ROOT}" --env "${ENVFILE}" &
set +e
set +x
ec "Waiting for server healthcheck - ${SERVER}/healthcheck:";
# https://stackoverflow.com/a/33520390/5560682
until [ "$(curl -sS "${SERVER}/healthcheck" 2>/dev/null)" = "jasmine healthy" ]; do
printf "."
sleep 0.5;
done;
echo ""
ec "...server is working"
/bin/bash bash/swap-files-v2.sh package.json package.dev.json -- /bin/bash playwright.sh --env "${ENVFILE}" "$@"
STATUS=${?}
if [ "${STAY}" = "1" ]; then
cat <<EEE
Open:
${SERVER}
Press Ctrl+C to exit
EEE
tail -f /dev/null
fi
exit ${STATUS}