forked from Automattic/wp-e2e-tests
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.sh
executable file
·188 lines (170 loc) · 4.92 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
#!/bin/bash
MOCHA=./node_modules/mocha/bin/mocha
GRUNT=./node_modules/.bin/grunt
REPORTER=""
PARALLEL=0
JOBS=0
AFTER="lib/after.js"
OPTS=""
SCREENSIZES="mobile,desktop"
BRANCH=""
RETURN=0
CLEAN=0
GREP=""
# Function to join arrays into a string
function joinStr { local IFS="$1"; shift; echo "$*"; }
I18N_CONFIG="\"browser\":\"firefox\",\"proxy\":\"system\",\"neverSaveScreenshots\":\"true\""
IE11_CONFIG="\"sauce\":\"true\",\"sauceConfig\":\"win-ie11\""
declare -a TARGETS
usage () {
cat <<EOF
-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)
-b [branch] - Run tests on given branch via https://calypso.live
-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
-C - Execute 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
-l [config] - Execute the critical visdiff 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'
-f - Tell visdiffs to fail the tests rather than just send an alert
-i - Execute i18n tests in the specs-i18n/ directory, not compatible with -g flag
-v - Execute the visdiff tests in specs-visdiff/
-h - This help listing
EOF
exit 0
}
if [ $# -eq 0 ]; then
usage
fi
while getopts ":Rpb:s:gjCH:wl:cm:fivh" opt; do
case $opt in
R)
REPORTER="-R spec-xunit-slack-reporter"
continue
;;
p)
PARALLEL=1
continue
;;
c)
CLEAN=1
continue
;;
b)
NODE_CONFIG_ARGS+=("\"liveBranch\":\"true\",\"branchName\":\"$OPTARG\",\"calypsoBaseURL\":\"https://calypso.live\"")
continue
;;
s)
SCREENSIZES=$OPTARG
continue
;;
g)
TARGET="specs/"
;;
i)
NODE_CONFIG_ARGS+=$I18N_CONFIG
TARGET="specs-i18n/"
;;
w)
NODE_CONFIG_ARGS+=$IE11_CONFIG
SCREENSIZES=desktop
TARGET="specs/*wp-signup-spec.js" # wildcard needed to account for random filename ordering
;;
l)
NODE_CONFIG_ARGS+=("\"sauce\":\"true\",\"sauceConfig\":\"$OPTARG\"")
continue
;;
v)
TARGET="specs-visdiff/"
;;
m)
BROWSERS=$(echo $OPTARG | sed 's/,/ /g')
if [ "$CI" != "true" ] || [ $CIRCLE_NODE_INDEX == 0 ]; then
CMD="$GRUNT $BROWSERS"
eval $CMD
fi
exit $?
;;
j)
MOCHA+=" --compilers js:babel-register"
SCREENSIZES="desktop,mobile"
TARGET="specs-jetpack-calypso/"
;;
C)
GREP="-g '@canary'"
MOCHA+=" --compilers js:babel-register"
SCREENSIZES="mobile"
TARGET="specs/"
;;
H)
export JETPACKHOST=$OPTARG
;;
f)
NODE_CONFIG_ARGS+=("\"failVisdiffs\":\"true\"")
;;
h)
usage
;;
\?)
echo "Invalid option: -$OPTARG" >&2
echo ""
usage
;;
:)
echo "Option -$OPTARG requires an argument" >&2
echo ""
usage
;;
esac
TARGETS+=("$TARGET")
unset TARGET
done
# Skip any tests in the given variable
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[*]})"
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"
NC="--NODE_CONFIG='{$NODE_CONFIG_ARG}'"
CMD="env BROWSERSIZE=mobile $MOCHA $NC $GREP $REPORTER specs/ $AFTER"
eval $CMD
RETURN+=$?
fi
if [ $CIRCLE_NODE_INDEX == $DESKTOP ]; then
echo "Executing tests at desktop screen width"
NC="--NODE_CONFIG='{$NODE_CONFIG_ARG}'"
CMD="env BROWSERSIZE=desktop $MOCHA $NC $GREP $REPORTER specs/ $AFTER"
eval $CMD
RETURN+=$?
fi
else # Not a parallel run, just queue up the tests in sequence
NC="--NODE_CONFIG='{$NODE_CONFIG_ARG}'"
if [ "$CI" != "true" ] || [ $CIRCLE_NODE_INDEX == 0 ]; then
IFS=, read -r -a SCREENSIZE_ARRAY <<< "$SCREENSIZES"
for size in ${SCREENSIZE_ARRAY[@]}; do
for target in "${TARGETS[@]}"; do
if [ "$target" != "" ]; then
CMD="env BROWSERSIZE=$size $MOCHA $NC $GREP $REPORTER $target $AFTER"
eval $CMD
RETURN+=$?
fi
done
done
fi
fi
if [ $CLEAN == 1 ]; then
exit 0
fi
exit $RETURN