This repository has been archived by the owner on Feb 18, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathrun.sh
executable file
·252 lines (234 loc) · 7.39 KB
/
run.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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
#!/bin/bash
MAGELLAN=./node_modules/.bin/magellan
MOCHA_ARGS=""
WORKERS=8
GRUNT=./node_modules/.bin/grunt
REPORTER=""
PARALLEL=0
JOBS=0
OPTS=""
SCREENSIZES="mobile,desktop"
LOCALES="en"
BRANCH=""
RETURN=0
CLEAN=0
GREP=""
LOCAL_BROWSER="chrome"
# Warn if NODE_ENV variable is not set
if [ "$NODE_ENV" = "" ]; then
echo "WARNING: NODE_ENV environment variable is not set."
exit 1
fi
#disable selenium promise manager
export SELENIUM_PROMISE_MANAGER=0
# Function to join arrays into a string
function joinStr { local IFS="$1"; shift; echo "$*"; }
I18N_CONFIG="\"browser\":\"chrome\",\"proxy\":\"system\",\"saveAllScreenshots\":true"
IE11_CONFIG="\"sauce\":\"true\",\"sauceConfig\":\"win-ie11\""
SAFARI_CONFIG="\"sauce\":\"true\",\"sauceConfig\":\"osx-safari\""
declare -a MAGELLAN_CONFIGS
usage () {
cat <<EOF
-a [workers] - Number of parallel workers in Magellan (defaults to 3)
-R - Use custom Slack/Spec/XUnit reporter, otherwise just use Spec reporter
-p - Execute the tests in parallel via CircleCI envvars (implies -g -s mobile,desktop)
-S [commitHash] - Run tests against given commit via https://calypso.live
-B [branch] - Run Jetpack tests on given Jetpack branch via https://jurassic.ninja
-s - Screensizes in a comma-separated list (defaults to mobile,desktop)
-g - Execute general tests in the specs/ directory
-j - Execute Jetpack tests in the specs-jetpack-calypso/ directory (desktop and mobile)
-W - Execute WooCommerce tests in the specs-woocommerce/ directory (desktop and mobile)
-F - Execute tests tagged with @secure-auth
-C - Execute tests tagged with @canary
-J - Execute Jetpack connect tests tagged with @canary
-H [host] - Specify an alternate host for Jetpack tests
-w - Only execute signup tests on Windows/IE11, not compatible with -g flag
-z - Only execute canary tests on Windows/IE11, not compatible with -g flag
-y - Only execute canary tests on Safari 10 on Mac, not compatible with -g flag
-l [config] - Execute the tests via Sauce Labs with the given configuration
-c - Exit with status code 0 regardless of test results
-m [browsers] - Execute the multi-browser visual-diff tests with the given list of browsers via grunt. Specify browsers in comma-separated list or 'all'
-i - Execute i18n NUX screenshot tests, not compatible with -g flag
-I - Execute tests in specs-i18n/ directory
-x - Execute the tests from the context of xvfb-run
-u [baseUrl] - Override the calypsoBaseURL config
-h - This help listing
EOF
exit 1
}
if [ $# -eq 0 ]; then
usage
fi
while getopts ":a:RpS:B:s:gjWCJH:wzyl:cm:fiIUvxu:h:F" opt; do
case $opt in
a)
WORKERS=$OPTARG
continue
;;
R)
MOCHA_ARGS+="-R spec-xunit-reporter "
continue
;;
p)
PARALLEL=1
continue
;;
c)
CLEAN=1
continue
;;
S)
export LIVEBRANCHES="true"
NODE_CONFIG_ARGS+=("\"liveBranch\":\"true\",\"calypsoBaseURL\":\"https://hash-$OPTARG.calypso.live\",\"branchName\":\"$BRANCHNAME\"")
continue
;;
B)
export LIVEBRANCHES="true"
NODE_CONFIG_ARGS+=("\"jetpackBranch\":\"true\",\"jetpackBranchName\":\"$OPTARG\"")
continue
;;
s)
SCREENSIZES=$OPTARG
continue
;;
g)
MAGELLAN_CONFIG="magellan.json"
;;
i)
NODE_CONFIG_ARGS+=$I18N_CONFIG
LOCALES="en,pt-BR,es,ja,fr,he"
export SCREENSHOTDIR="screenshots-i18n"
MAGELLAN_CONFIG="magellan-i18n-nux.json"
;;
I)
SCREENSIZES="desktop"
WORKERS=1 # We need to be careful to take it slow with Google
NODE_CONFIG_ARGS+=$I18N_CONFIG
LOCALES="en,es,pt-br,de,fr,he,ja,it,nl,ru,tr,id,zh-cn,zh-tw,ko,ar,sv"
MAGELLAN_CONFIG="magellan-i18n.json"
;;
w)
NODE_CONFIG_ARGS+=$IE11_CONFIG
LOCAL_BROWSER="ie11"
SCREENSIZES="desktop"
MAGELLAN_CONFIG="magellan-ie11.json"
;;
z)
NODE_CONFIG_ARGS+=$IE11_CONFIG
LOCAL_BROWSER="ie11"
SCREENSIZES="desktop"
MAGELLAN_CONFIG="magellan-ie11-canary.json"
;;
y)
NODE_CONFIG_ARGS+=$SAFARI_CONFIG
LOCAL_BROWSER="safari"
SCREENSIZES="desktop"
MAGELLAN_CONFIG="magellan-safari-canary.json"
;;
l)
NODE_CONFIG_ARGS+=("\"sauce\":\"true\",\"sauceConfig\":\"$OPTARG\"")
continue
;;
m)
BROWSERS=$(echo $OPTARG | sed 's/,/ /g')
if [ "$CI" != "true" ] || [ $CIRCLE_NODE_INDEX == 0 ]; then
CMD="$GRUNT $BROWSERS"
eval $CMD
fi
exit $?
;;
j)
WORKERS=3
SCREENSIZES="desktop,mobile"
MAGELLAN_CONFIG="magellan-jetpack.json"
;;
J)
SCREENSIZES="desktop"
MAGELLAN_CONFIG="magellan-jetpack-canary.json"
;;
W)
SCREENSIZES="desktop,mobile"
MAGELLAN_CONFIG="magellan-woocommerce.json"
;;
C)
SCREENSIZES="mobile"
MAGELLAN_CONFIG="magellan-canary.json"
;;
F)
SCREENSIZES="desktop"
MAGELLAN_CONFIG="magellan-2fa.json"
;;
H)
export JETPACKHOST=$OPTARG
;;
x)
NODE_CONFIG_ARGS+=("\"headless\":\"true\",\"useTestVideo\":\"false\"")
# MAGELLAN="xvfb-run $MAGELLAN"
;;
u)
NODE_CONFIG_ARGS+=("\"calypsoBaseURL\":\"$OPTARG\"")
continue
;;
h)
usage
;;
\?)
echo "Invalid option: -$OPTARG" >&2
echo ""
usage
;;
:)
echo "Option -$OPTARG requires an argument" >&2
echo ""
usage
;;
esac
MAGELLAN_CONFIGS+=("$MAGELLAN_CONFIG")
unset MAGELLAN_CONFIG
done
# Skip any tests in the given variable - DOES NOT WORK WITH MAGELLAN - See issue #506
if [ "$SKIP_TEST_REGEX" != "" ]; then
GREP="-i -g '$SKIP_TEST_REGEX'"
fi
# Combine any NODE_CONFIG entries into a single object
NODE_CONFIG_ARG="$(joinStr , ${NODE_CONFIG_ARGS[*]})"
MOCHA_ARGS+="--NODE_CONFIG={$NODE_CONFIG_ARG}"
if [ $PARALLEL == 1 ]; then
# Assign an index to each test segment to run in parallel
MOBILE=$(expr 0 % $CIRCLE_NODE_TOTAL)
DESKTOP=$(expr 1 % $CIRCLE_NODE_TOTAL)
echo "Parallel execution details:"
echo "mobile=$MOBILE, desktop=$DESKTOP, node=$CIRCLE_NODE_INDEX, total=$CIRCLE_NODE_TOTAL"
if [ $CIRCLE_NODE_INDEX == $MOBILE ]; then
echo "Executing tests at mobile screen width"
CMD="env BROWSERSIZE=mobile $MAGELLAN --config=$MAGELLAN_CONFIGS --mocha_args='$MOCHA_ARGS' --max_workers=$WORKERS --local_browser=$LOCAL_BROWSER"
eval $CMD
RETURN+=$?
fi
if [ $CIRCLE_NODE_INDEX == $DESKTOP ]; then
echo "Executing tests at desktop screen width"
CMD="env BROWSERSIZE=desktop $MAGELLAN --config=$MAGELLAN_CONFIGS --mocha_args='$MOCHA_ARGS' --max_workers=$WORKERS --local_browser=$LOCAL_BROWSER"
eval $CMD
RETURN+=$?
fi
else # Not using multiple CircleCI containers, just queue up the tests in sequence
if [ "$CI" != "true" ] || [ $CIRCLE_NODE_INDEX == 0 ]; then
IFS=, read -r -a SCREENSIZE_ARRAY <<< "$SCREENSIZES"
IFS=, read -r -a LOCALE_ARRAY <<< "$LOCALES"
for size in ${SCREENSIZE_ARRAY[@]}; do
for locale in ${LOCALE_ARRAY[@]}; do
for config in "${MAGELLAN_CONFIGS[@]}"; do
if [ "$config" != "" ]; then
CMD="env BROWSERSIZE=$size BROWSERLOCALE=$locale $MAGELLAN --mocha_args='$MOCHA_ARGS' --config='$config' --max_workers=$WORKERS --local_browser=$LOCAL_BROWSER"
eval $CMD
RETURN+=$?
fi
done
done
done
fi
fi
if [ $CLEAN == 1 ]; then
exit 0
fi
exit $RETURN