blob: 38b284ac95131b384ab315600c642aebb855d4de [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
Henrique Mendonça15d90422015-06-25 22:31:41 +100074${DIR}/../../../compiler/cpp/thrift -o ${DIR} --gen js:node ${DIR}/../../../test/JsDeepConstructorTest.thrift
Roger Meier8909cbd2014-01-26 11:44:27 +010075
76#unit tests
77
Randy Abernethyd8187c52015-02-16 01:25:53 -080078node ${DIR}/binary.test.js || TESTOK=1
Henrique Mendonça15d90422015-06-25 22:31:41 +100079node ${DIR}/deep-constructor.test.js || TESTOK=1
Roger Meier8909cbd2014-01-26 11:44:27 +010080
81#integration tests
82
Randy Abernethyd8187c52015-02-16 01:25:53 -080083for type in tcp multiplex websocket http
Randy Abernethy3b9ff4d2015-02-16 00:51:24 -080084do
Roger Meier8909cbd2014-01-26 11:44:27 +010085
Randy Abernethy3b9ff4d2015-02-16 00:51:24 -080086 for protocol in compact binary json
87 do
Roger Meier8909cbd2014-01-26 11:44:27 +010088
Randy Abernethy3b9ff4d2015-02-16 00:51:24 -080089 for transport in buffered framed
90 do
91 testServer $type $protocol $transport || TESTOK=1
92 testServer $type $protocol $transport --ssl || TESTOK=1
93 testServer $type $protocol $transport --promise || TESTOK=1
94 done
95 done
96done
Randy Abernethy2e091f62014-11-15 23:05:22 -080097
Randy Abernethyd8187c52015-02-16 01:25:53 -080098# XHR only until phantomjs 2 is released.
99testBrowser
100
Randy Abernethy8e731372015-02-03 00:04:40 -0800101if [ -n "${COVER}" ]; then
Randy Abernethy8e731372015-02-03 00:04:40 -0800102 ${ISTANBUL} report --dir "${DIR}/../coverage" --include "${DIR}/../coverage/report*/coverage.json" lcov cobertura html
103 rm -r ${DIR}/../coverage/report*/*
104 rmdir ${DIR}/../coverage/report*
105fi
106
Roger Meier8909cbd2014-01-26 11:44:27 +0100107exit $TESTOK