UNPKG

3.97 kBapplication/x-shView Raw
1#!/usr/bin/env bash
2
3#
4# Copyright 2017-19 IBM Corporation
5#
6# Licensed under the Apache License, Version 2.0 (the "License");
7# you may not use this file except in compliance with the License.
8# You may obtain a copy of the License at
9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS,
14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15# See the License for the specific language governing permissions and
16# limitations under the License.
17#
18
19set -e
20set -o pipefail
21
22SCRIPTDIR=$(cd $(dirname "$0") && pwd)
23
24if [ -n "$NYC" ]; then
25 if [ -z "$TRAVIS_JOB_ID" ]; then
26 # for travis, we will do the instrumentation in advance, in tools/travis/install.sh
27 # for not-travis, do the instrumentation now:
28 "$SCRIPTDIR"/../../../tools/codecov/instrument.sh
29
30 # also for non-travis: clean out any prior code coverage data
31 rm -rf .nyc_output
32 fi
33fi
34
35if [ -z "$MONOREPO_MODE" ]; then
36 echo "running as external custom client"
37 ROOT="$SCRIPTDIR"/../..
38 export TEST_SUITE_ROOT="$ROOT"/node_modules/@kui-shell
39 export TEST_ROOT="$TEST_SUITE_ROOT"/test
40 cd "$SCRIPTDIR"
41else
42 ROOT="$SCRIPTDIR"/../../..
43 echo "running in monorepo $ROOT"
44 export TEST_SUITE_ROOT="$ROOT"/node_modules/@kui-shell
45 export TEST_ROOT="$ROOT"/packages/test
46fi
47
48if [ -z "$API_HOST" ]; then
49 if [ -f ~/.wskprops ]; then
50 . ~/.wskprops
51 export API_HOST=$APIHOST
52 elif [ -z "$LAYERS" ]; then
53 export EXCLUDE_OW_TEST=true
54 fi
55fi
56
57if [ ! -f ~/.wskprops ]; then
58 echo "APIHOST=$API_HOST" > ~/.wskprops
59 echo "INSECURE_SSL=true" >> ~/.wskprops
60fi
61
62export PATH=./node_modules/.bin:$PATH
63
64# which tests to run; the default is every test
65if [ $# -ne 0 ]; then
66 # one or more layers, specified on command line
67 WHICH=$@
68elif [ -n "$LAYERS" ]; then
69 # one or more layers, specified by env var
70 WHICH=$LAYERS
71else
72 # all layers
73 WHICH=""
74fi
75
76echo "Running these layers: $# $WHICH"
77
78children=()
79childrenNames=()
80
81function kill_them_all() {
82 children=("$@")
83 for job in "${children[@]}"; do
84 echo "killing ${job}"
85 kill -9 ${job}
86 done
87 exit
88}
89trap kill_them_all INT
90
91idx=${PORT_OFFSET_BASE-${PORT_OFFSET-1}}
92if [ -z "$WHICH" ]; then
93 (LAYER=$LAYER DISPLAY=":$idx" PORT_OFFSET=$idx "$TEST_ROOT"/bin/runTest.sh 2>&1)
94else
95 for i in $WHICH; do
96 LAYER=`basename $i`
97 echo "spawning mocha layer $LAYER PORT_OFFSET=$idx"
98 (LAYER=$LAYER DISPLAY=":$idx" PORT_OFFSET=$idx "$TEST_ROOT"/bin/runTest.sh 2>&1) &
99 children+=("$!")
100 childrenNames+=("$LAYER")
101 idx=$((idx+1))
102 done
103fi
104
105function wait_and_get_exit_codes() {
106 children=("$@")
107 EXIT_CODE=0
108 # the ! gives us indices
109 for jobIdx in "${!children[@]}"; do
110 job="${children[$jobIdx]}"
111 jobName="${childrenNames[$jobIdx]}"
112 echo "$(tput setaf 3)waiting on ${jobName} with PID ${job}$(tput sgr0)" # yellow text
113 CODE=0;
114 wait ${job} || CODE=$?
115 if [[ "${CODE}" != "0" ]]; then
116 echo "$(tput setaf 1)failing: job ${jobName} exited with a non-zero code ${CODE}$(tput sgr0)" # red text
117 EXIT_CODE=1;
118 else
119 echo "$(tput setaf 2)ok: mocha job ${jobName} exited with success$(tput sgr0)" # red text
120 fi
121 done
122}
123wait_and_get_exit_codes "${children[@]}"
124
125# finally, if the tests were successful, report on code coverage
126if [ $EXIT_CODE == 0 ]; then
127 if [ -n "$NYC" ]; then
128 # in travis, we will do the report generation in tools/travis/script.sh
129 if [ -z "$TRAVIS_JOB_ID" ]; then
130 set +e # we don't want report generation failures to induce a test failure
131 "$SCRIPTDIR"/../../../tools/codecov/report.sh
132 fi
133 fi
134fi
135
136echo "runMochaLayers finished with ${EXIT_CODE-0}"
137exit "${EXIT_CODE-0}"