blob: 0882d135310913e520a33b6074b8c7ae80589462 [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
Henrique Mendonça1568aef2015-05-27 22:15:46 +100078node ${DIR}/deep-constructor.test.js || TESTOK=1
Roger Meier8909cbd2014-01-26 11:44:27 +010079
80#integration tests
81
Randy Abernethyd8187c52015-02-16 01:25:53 -080082for type in tcp multiplex websocket http
Randy Abernethy3b9ff4d2015-02-16 00:51:24 -080083do
Roger Meier8909cbd2014-01-26 11:44:27 +010084
Randy Abernethy3b9ff4d2015-02-16 00:51:24 -080085 for protocol in compact binary json
86 do
Roger Meier8909cbd2014-01-26 11:44:27 +010087
Randy Abernethy3b9ff4d2015-02-16 00:51:24 -080088 for transport in buffered framed
89 do
90 testServer $type $protocol $transport || TESTOK=1
91 testServer $type $protocol $transport --ssl || TESTOK=1
92 testServer $type $protocol $transport --promise || TESTOK=1
93 done
94 done
95done
Randy Abernethy2e091f62014-11-15 23:05:22 -080096
Randy Abernethyd8187c52015-02-16 01:25:53 -080097# XHR only until phantomjs 2 is released.
98testBrowser
99
Randy Abernethy8e731372015-02-03 00:04:40 -0800100if [ -n "${COVER}" ]; then
Randy Abernethy8e731372015-02-03 00:04:40 -0800101 ${ISTANBUL} report --dir "${DIR}/../coverage" --include "${DIR}/../coverage/report*/coverage.json" lcov cobertura html
102 rm -r ${DIR}/../coverage/report*/*
103 rmdir ${DIR}/../coverage/report*
104fi
105
Roger Meier8909cbd2014-01-26 11:44:27 +0100106exit $TESTOK