blob: 144832ee43dd27747485d04c1f72e4b2fb9d8a67 [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
Mustafa Senol Cosar3f0d4442019-03-01 18:57:09 +030026EPISODIC_DIR=${DIR}/episodic-code-generation-test
27
28THRIFT_FILES_DIR=${DIR}/../../../test
29
30THRIFT_COMPILER=${DIR}/../../../compiler/cpp/thrift
31
Randy Abernethy8e731372015-02-03 00:04:40 -080032ISTANBUL="$DIR/../../../node_modules/istanbul/lib/cli.js"
Randy Abernethy8e731372015-02-03 00:04:40 -080033
34REPORT_PREFIX="${DIR}/../coverage/report"
35
36COUNT=0
37
Roger Meier8909cbd2014-01-26 11:44:27 +010038export NODE_PATH="${DIR}:${DIR}/../lib:${NODE_PATH}"
39
Randy Abernethy3b9ff4d2015-02-16 00:51:24 -080040testServer()
Roger Meier8909cbd2014-01-26 11:44:27 +010041{
bforbisda1169d2018-10-28 11:27:38 -040042 echo " [ECMA $1] Testing $2 Client/Server with protocol $3 and transport $4 $5";
Roger Meier8909cbd2014-01-26 11:44:27 +010043 RET=0
Randy Abernethy8e731372015-02-03 00:04:40 -080044 if [ -n "${COVER}" ]; then
bforbisda1169d2018-10-28 11:27:38 -040045 ${ISTANBUL} cover ${DIR}/server.js --dir ${REPORT_PREFIX}${COUNT} --handle-sigint -- --type $2 -p $3 -t $4 $5 &
Randy Abernethy8e731372015-02-03 00:04:40 -080046 COUNT=$((COUNT+1))
47 else
bforbisda1169d2018-10-28 11:27:38 -040048 node ${DIR}/server.js --${1} --type $2 -p $3 -t $4 $5 &
Randy Abernethy8e731372015-02-03 00:04:40 -080049 fi
Roger Meier8909cbd2014-01-26 11:44:27 +010050 SERVERPID=$!
James E. King, III699b5bc2017-09-14 08:07:08 -070051 sleep 0.1
Randy Abernethy8e731372015-02-03 00:04:40 -080052 if [ -n "${COVER}" ]; then
bforbisda1169d2018-10-28 11:27:38 -040053 ${ISTANBUL} cover ${DIR}/client.js --dir ${REPORT_PREFIX}${COUNT} -- --${1} --type $2 -p $3 -t $4 $5 || RET=1
Randy Abernethy8e731372015-02-03 00:04:40 -080054 COUNT=$((COUNT+1))
55 else
bforbisda1169d2018-10-28 11:27:38 -040056 node ${DIR}/client.js --${1} --type $2 -p $3 -t $4 $5 || RET=1
Randy Abernethy8e731372015-02-03 00:04:40 -080057 fi
58 kill -2 $SERVERPID || RET=1
James E. King, III699b5bc2017-09-14 08:07:08 -070059 wait $SERVERPID
Roger Meier8909cbd2014-01-26 11:44:27 +010060 return $RET
61}
62
Mustafa Senol Cosar3f0d4442019-03-01 18:57:09 +030063testEpisodicCompilation()
64{
65 RET=0
66 if [ -n "${COVER}" ]; then
67 ${ISTANBUL} cover ${EPISODIC_DIR}/server.js --dir ${REPORT_PREFIX}${COUNT} --handle-sigint &
68 COUNT=$((COUNT+1))
69 else
70 node ${EPISODIC_DIR}/server.js &
71 fi
72 SERVERPID=$!
73 sleep 0.1
74 if [ -n "${COVER}" ]; then
75 ${ISTANBUL} cover ${EPISODIC_DIR}/client.js --dir ${REPORT_PREFIX}${COUNT} || RET=1
76 COUNT=$((COUNT+1))
77 else
78 node ${EPISODIC_DIR}/client.js || RET=1
79 fi
80 kill -2 $SERVERPID || RET=1
81 wait $SERVERPID
82 return $RET
83}
84
Randy Abernethyd8187c52015-02-16 01:25:53 -080085
Roger Meier8909cbd2014-01-26 11:44:27 +010086TESTOK=0
87
Mustafa Senol Cosar3f0d4442019-03-01 18:57:09 +030088# generating Thrift code
Roger Meier8909cbd2014-01-26 11:44:27 +010089
Jens Geyerf066d842022-06-13 23:37:25 +020090${THRIFT_COMPILER} -o ${DIR} --gen js:node ${THRIFT_FILES_DIR}/v0.16/ThriftTest.thrift
Mustafa Senol Cosar3f0d4442019-03-01 18:57:09 +030091${THRIFT_COMPILER} -o ${DIR} --gen js:node ${THRIFT_FILES_DIR}/JsDeepConstructorTest.thrift
92${THRIFT_COMPILER} -o ${DIR} --gen js:node ${THRIFT_FILES_DIR}/Int64Test.thrift
bforbisda1169d2018-10-28 11:27:38 -040093mkdir ${DIR}/gen-nodejs-es6
Jens Geyerf066d842022-06-13 23:37:25 +020094${THRIFT_COMPILER} -out ${DIR}/gen-nodejs-es6 --gen js:node,es6 ${THRIFT_FILES_DIR}/v0.16/ThriftTest.thrift
Mustafa Senol Cosar3f0d4442019-03-01 18:57:09 +030095${THRIFT_COMPILER} -out ${DIR}/gen-nodejs-es6 --gen js:node,es6 ${THRIFT_FILES_DIR}/JsDeepConstructorTest.thrift
96${THRIFT_COMPILER} -out ${DIR}/gen-nodejs-es6 --gen js:node,es6 ${THRIFT_FILES_DIR}/Int64Test.thrift
Roger Meier8909cbd2014-01-26 11:44:27 +010097
Mustafa Senol Cosar3f0d4442019-03-01 18:57:09 +030098# generate episodic compilation test code
99TYPES_PACKAGE=${EPISODIC_DIR}/node_modules/types-package
100
101# generate the first episode
102mkdir --parents ${EPISODIC_DIR}/gen-1/first-episode
103${THRIFT_COMPILER} -o ${EPISODIC_DIR}/gen-1/first-episode --gen js:node,thrift_package_output_directory=first-episode ${THRIFT_FILES_DIR}/Types.thrift
104
105# create a "package" from the first episode and "install" it, the episode file must be at the module root
106mkdir --parents ${TYPES_PACKAGE}/first-episode
107cp --force ${EPISODIC_DIR}/episodic_compilation.package.json ${TYPES_PACKAGE}/package.json
108cp --force ${EPISODIC_DIR}/gen-1/first-episode/gen-nodejs/Types_types.js ${TYPES_PACKAGE}/first-episode/
109cp --force ${EPISODIC_DIR}/gen-1/first-episode/gen-nodejs/thrift.js.episode ${TYPES_PACKAGE}
110
111# generate the second episode
112mkdir --parents ${EPISODIC_DIR}/gen-2/second-episode
113${THRIFT_COMPILER} -o ${EPISODIC_DIR}/gen-2/second-episode --gen js:node,imports=${TYPES_PACKAGE} ${THRIFT_FILES_DIR}/Service.thrift
114if [ -f ${EPISODIC_DIR}/gen-2/second-episode/Types_types.js ]; then
115 TESTOK=1
116fi
117
118# unit tests
Roger Meier8909cbd2014-01-26 11:44:27 +0100119
Randy Abernethyd8187c52015-02-16 01:25:53 -0800120node ${DIR}/binary.test.js || TESTOK=1
Tuomo Jokimiesb60b8fe2024-03-18 16:56:25 +0200121node ${DIR}/header.test.js || TESTOK=1
Mustafa Senol Cosarf86845e2018-12-05 17:50:18 +0300122node ${DIR}/int64.test.js || TESTOK=1
Henrique Mendonça15d90422015-06-25 22:31:41 +1000123node ${DIR}/deep-constructor.test.js || TESTOK=1
Roger Meier8909cbd2014-01-26 11:44:27 +0100124
Mustafa Senol Cosar3f0d4442019-03-01 18:57:09 +0300125# integration tests
Roger Meier8909cbd2014-01-26 11:44:27 +0100126
Randy Abernethyd8187c52015-02-16 01:25:53 -0800127for type in tcp multiplex websocket http
Randy Abernethy3b9ff4d2015-02-16 00:51:24 -0800128do
Randy Abernethy3b9ff4d2015-02-16 00:51:24 -0800129 for protocol in compact binary json
130 do
Randy Abernethy3b9ff4d2015-02-16 00:51:24 -0800131 for transport in buffered framed
132 do
bforbisda1169d2018-10-28 11:27:38 -0400133 for ecma_version in es5 es6
134 do
135 testServer $ecma_version $type $protocol $transport || TESTOK=1
136 testServer $ecma_version $type $protocol $transport --ssl || TESTOK=1
137 testServer $ecma_version $type $protocol $transport --callback || TESTOK=1
138 done
Randy Abernethy3b9ff4d2015-02-16 00:51:24 -0800139 done
140 done
141done
Randy Abernethy2e091f62014-11-15 23:05:22 -0800142
Mustafa Senol Cosar3f0d4442019-03-01 18:57:09 +0300143# episodic compilation test
144testEpisodicCompilation
Randy Abernethyd8187c52015-02-16 01:25:53 -0800145
Randy Abernethy8e731372015-02-03 00:04:40 -0800146if [ -n "${COVER}" ]; then
Randy Abernethy8e731372015-02-03 00:04:40 -0800147 ${ISTANBUL} report --dir "${DIR}/../coverage" --include "${DIR}/../coverage/report*/coverage.json" lcov cobertura html
148 rm -r ${DIR}/../coverage/report*/*
149 rmdir ${DIR}/../coverage/report*
150fi
151
Roger Meier8909cbd2014-01-26 11:44:27 +0100152exit $TESTOK