blob: fd1142585ba28ce5eeef64c2cf803388d20d7ee8 [file] [log] [blame]
Roger Meier8909cbd2014-01-26 11:44:27 +01001#! /bin/sh
2
Roger Meier8909cbd2014-01-26 11:44:27 +01003# Licensed to the Apache Software Foundation (ASF) under one
4# or more contributor license agreements. See the NOTICE file
5# distributed with this work for additional information
6# regarding copyright ownership. The ASF licenses this file
7# to you under the Apache License, Version 2.0 (the
8# "License"); you may not use this file except in compliance
9# with the License. You may obtain a copy of the License at
10#
11# http://www.apache.org/licenses/LICENSE-2.0
12#
13# Unless required by applicable law or agreed to in writing,
14# software distributed under the License is distributed on an
15# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16# KIND, either express or implied. See the License for the
17# specific language governing permissions and limitations
18# under the License.
Roger Meier8909cbd2014-01-26 11:44:27 +010019
Randy Abernethy8e731372015-02-03 00:04:40 -080020if [ -n "${1}" ]; then
21 COVER=${1};
22fi
23
Roger Meier8909cbd2014-01-26 11:44:27 +010024DIR="$( cd "$( dirname "$0" )" && pwd )"
25
Randy Abernethy8e731372015-02-03 00:04:40 -080026ISTANBUL="$DIR/../../../node_modules/istanbul/lib/cli.js"
Randy Abernethyd8187c52015-02-16 01:25:53 -080027RUNBROWSER="$DIR/../../../node_modules/run-browser/bin/cli.js"
Randy Abernethy8e731372015-02-03 00:04:40 -080028
29REPORT_PREFIX="${DIR}/../coverage/report"
30
31COUNT=0
32
Roger Meier8909cbd2014-01-26 11:44:27 +010033export NODE_PATH="${DIR}:${DIR}/../lib:${NODE_PATH}"
34
Randy Abernethy3b9ff4d2015-02-16 00:51:24 -080035testServer()
Roger Meier8909cbd2014-01-26 11:44:27 +010036{
Randy Abernethy3b9ff4d2015-02-16 00:51:24 -080037 echo " Testing $1 Client/Server with protocol $2 and transport $3 $4";
Roger Meier8909cbd2014-01-26 11:44:27 +010038 RET=0
Randy Abernethy8e731372015-02-03 00:04:40 -080039 if [ -n "${COVER}" ]; then
Randy Abernethy3b9ff4d2015-02-16 00:51:24 -080040 ${ISTANBUL} cover ${DIR}/server.js --dir ${REPORT_PREFIX}${COUNT} --handle-sigint -- --type $1 -p $2 -t $3 $4 &
Randy Abernethy8e731372015-02-03 00:04:40 -080041 COUNT=$((COUNT+1))
42 else
Randy Abernethy3b9ff4d2015-02-16 00:51:24 -080043 node ${DIR}/server.js --type $1 -p $2 -t $3 $4 &
Randy Abernethy8e731372015-02-03 00:04:40 -080044 fi
Roger Meier8909cbd2014-01-26 11:44:27 +010045 SERVERPID=$!
46 sleep 1
Randy Abernethy8e731372015-02-03 00:04:40 -080047 if [ -n "${COVER}" ]; then
Randy Abernethy3b9ff4d2015-02-16 00:51:24 -080048 ${ISTANBUL} cover ${DIR}/client.js --dir ${REPORT_PREFIX}${COUNT} -- --type $1 -p $2 -t $3 $4 || RET=1
Randy Abernethy8e731372015-02-03 00:04:40 -080049 COUNT=$((COUNT+1))
50 else
Randy Abernethy3b9ff4d2015-02-16 00:51:24 -080051 node ${DIR}/client.js --type $1 -p $2 -t $3 $4 || RET=1
Randy Abernethy8e731372015-02-03 00:04:40 -080052 fi
53 kill -2 $SERVERPID || RET=1
Roger Meier8909cbd2014-01-26 11:44:27 +010054 return $RET
55}
56
Randy Abernethyd8187c52015-02-16 01:25:53 -080057testBrowser()
58{
59 echo " Testing browser client with http server with json protocol and buffered transport";
60 RET=0
61 node ${DIR}/server.js --type http -p json -t buffered &
62 SERVERPID=$!
63 sleep 1
64 ${RUNBROWSER} ${DIR}/browser_client.js --phantom || RET=1
65 kill -2 $SERVERPID || RET=1
66 return $RET
67}
68
Roger Meier8909cbd2014-01-26 11:44:27 +010069TESTOK=0
70
71#generating thrift code
72
73${DIR}/../../../compiler/cpp/thrift -o ${DIR} --gen js:node ${DIR}/../../../test/ThriftTest.thrift
74
75#unit tests
76
Randy Abernethyd8187c52015-02-16 01:25:53 -080077node ${DIR}/binary.test.js || TESTOK=1
Roger Meier8909cbd2014-01-26 11:44:27 +010078
79#integration tests
80
Randy Abernethyd8187c52015-02-16 01:25:53 -080081for type in tcp multiplex websocket http
Randy Abernethy3b9ff4d2015-02-16 00:51:24 -080082do
Roger Meier8909cbd2014-01-26 11:44:27 +010083
Randy Abernethy3b9ff4d2015-02-16 00:51:24 -080084 for protocol in compact binary json
85 do
Roger Meier8909cbd2014-01-26 11:44:27 +010086
Randy Abernethy3b9ff4d2015-02-16 00:51:24 -080087 for transport in buffered framed
88 do
89 testServer $type $protocol $transport || TESTOK=1
90 testServer $type $protocol $transport --ssl || TESTOK=1
91 testServer $type $protocol $transport --promise || TESTOK=1
92 done
93 done
94done
Randy Abernethy2e091f62014-11-15 23:05:22 -080095
Randy Abernethyd8187c52015-02-16 01:25:53 -080096# XHR only until phantomjs 2 is released.
97testBrowser
98
Randy Abernethy8e731372015-02-03 00:04:40 -080099if [ -n "${COVER}" ]; then
Randy Abernethy8e731372015-02-03 00:04:40 -0800100 ${ISTANBUL} report --dir "${DIR}/../coverage" --include "${DIR}/../coverage/report*/coverage.json" lcov cobertura html
101 rm -r ${DIR}/../coverage/report*/*
102 rmdir ${DIR}/../coverage/report*
103fi
104
Roger Meier8909cbd2014-01-26 11:44:27 +0100105exit $TESTOK