UNPKG

4.54 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
19#
20# This script runs a given test suite "layer". We try at most three
21# times for success. It is intended to be called from
22# ./runMochaLayers.sh.
23#
24
25set -e
26set -o pipefail
27
28SCRIPTDIR=$(cd $(dirname "$0") && pwd)
29
30if [ -n "$LAYER" ]; then
31 # user asked to run tests in just one specified layer, e.g. "07"
32
33 if [ -n "$NEEDS_OPENWHISK" ]; then
34 #
35 # allocate openwhisk keys
36 #
37
38 #
39 # Notes:
40 # - see tools/travis/installers/openwhisk.sh for the creation of these files
41 #
42 export WSK_CONFIG_FILE=~/.wskprops_${KEY}_${PORT_OFFSET}
43 export WSK_CONFIG_FILEb=~/.wskpropsb_${KEY}_${PORT_OFFSET}
44 export TEST_SPACE="${TEST_SPACE_PREFIX-ns}${KEY}_${PORT_OFFSET}"
45 export TEST_SPACE2="${TEST_SPACE_PREFIX-ns}${KEY}_${PORT_OFFSET}b"
46
47 echo "Using wskconfig $WSK_CONFIG_FILE"
48 echo "Using TEST_SPACE ${TEST_SPACE}"
49
50 # check if we have already did auth allocation from previous tests against other mocha target
51 . ${WSK_CONFIG_FILEb}
52 export AUTH2=$AUTH
53
54 . ${WSK_CONFIG_FILE}
55 export API_HOST=$APIHOST
56 export AUTH=$AUTH
57 export __OW_APIGW_TOKEN=$APIGW_ACCESS_TOKEN
58 fi
59
60 if [ -z $EXCLUDE_OW_TEST ]; then
61 if [[ $LAYER == *"core"* ]]; then
62 TEST_SUITES=$(find -H "$TEST_SUITE_ROOT"/{plugin-*,core,client} -path "*/dist/test/$LAYER" -o -path '*/core/test' -maxdepth 4)
63 else
64 TEST_SUITES=$(find -H "$TEST_SUITE_ROOT"/{plugin-*,core,client} -path "*/dist/test/$LAYER" -maxdepth 4)
65 fi
66 else
67 if [[ $LAYER == *"core"* ]]; then
68 TEST_SUITES=$(find -H "$TEST_SUITE_ROOT"/{plugin-*,core,client} -path "*/dist/test/$LAYER" -o -path '*/core/test' ! -path "*/dist/test/openwhisk*" ! -path "*/dist/test/composer*" ! -path "*/dist/test/grid" -maxdepth 4)
69 else
70 TEST_SUITES=$(find -H "$TEST_SUITE_ROOT"/{plugin-*,core,client} -path "*/dist/test/$LAYER" ! -path "*/dist/test/openwhisk*" ! -path "*/dist/test/composer*" ! -path "*/dist/test/grid" -maxdepth 4)
71 fi
72 fi
73else
74 if [ -z $EXCLUDE_OW_TEST ]; then
75 TEST_SUITES=$(find -H "$TEST_SUITE_ROOT"/{plugin-*,core,client} -path "*/dist/test" -o -path '*/core/test' -maxdepth 4)
76 else
77 TEST_SUITES=$(find -H "$TEST_SUITE_ROOT"/{plugin-*,core,client} -path "*/dist/test" ! -path "*/dist/test/openwhisk*" ! -path "*/dist/test/composer*" ! -path "*/dist/test/grid" -maxdepth 4)
78 fi
79fi
80
81echo "Running these test suites: $TEST_SUITES"
82
83# when running on a local (i.e. not-travis) device, we aren't using
84# multiple X displays
85if [ -n "$TRAVIS_JOB_ID" ]; then
86 # travis: we may have multiple DISPLAYs
87 echo "DISPLAY=$DISPLAY"
88else
89 # not travis: just one display
90 export DISPLAY=:0
91fi
92export DISPLAY
93
94# a signifier in case plugins or core want to do something different
95# while running tests
96export RUNNING_SHELL_TEST=true
97
98#
99# Notes:
100#
101# 1) passing --bail to mocha means we fail fast, if any test within
102# the test suite fails
103#
104# 2) flycheck is an emacs module that integrates with tslint; it
105# creates temporary files in-directory :( we use a mocha exclude
106# pattern to ensure we aren't executing tests in these temp files
107#
108# 3) we haven't yet figured out why spectron does not exit gracefully
109# on its own, hence we pass --exit to mocha, which tells mocha to do a
110# process.exit after the last test has been performed
111#
112function go {
113 NO_USAGE_TRACKING=true mocha \
114 -c \
115 --exit \
116 --reporter ${MOCHA_REPORTER-spec} \
117 --bail \
118 --recursive \
119 --timeout ${TIMEOUT-60000} \
120 --grep "${TEST_FILTER:-.*}" \
121 --exclude "**/*flycheck*" \
122 $TEST_SUITES
123}
124
125if [ -n "$TRAVIS_JOB_ID" ]; then
126 # travis: we try a few times
127 go || go || go || go
128else
129 # not travis: fail fast
130 go
131fi