blob: a3baa6e438bec91f0c082e0b47d7d31fd2a3d8b2 [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
Randy Abernethy3b9ff4d2015-02-16 00:51:24 -080038testServer()
Roger Meier8909cbd2014-01-26 11:44:27 +010039{
Cameron Martin21ed4a22024-04-22 11:08:19 +010040 echo " [Variant: $1] Testing $2 Client/Server with protocol $3 and transport $4 $5";
Roger Meier8909cbd2014-01-26 11:44:27 +010041 RET=0
Randy Abernethy8e731372015-02-03 00:04:40 -080042 if [ -n "${COVER}" ]; then
Cameron Martin21ed4a22024-04-22 11:08:19 +010043 ${ISTANBUL} cover ${DIR}/server.mjs --dir ${REPORT_PREFIX}${COUNT} --handle-sigint -- --type $2 -p $3 -t $4 $5 &
Randy Abernethy8e731372015-02-03 00:04:40 -080044 COUNT=$((COUNT+1))
45 else
Cameron Martin21ed4a22024-04-22 11:08:19 +010046 node ${DIR}/server.mjs --${1} --type $2 -p $3 -t $4 $5 &
Randy Abernethy8e731372015-02-03 00:04:40 -080047 fi
Roger Meier8909cbd2014-01-26 11:44:27 +010048 SERVERPID=$!
James E. King, III699b5bc2017-09-14 08:07:08 -070049 sleep 0.1
Randy Abernethy8e731372015-02-03 00:04:40 -080050 if [ -n "${COVER}" ]; then
Cameron Martin21ed4a22024-04-22 11:08:19 +010051 ${ISTANBUL} cover ${DIR}/client.mjs --dir ${REPORT_PREFIX}${COUNT} -- --${1} --type $2 -p $3 -t $4 $5 || RET=1
Randy Abernethy8e731372015-02-03 00:04:40 -080052 COUNT=$((COUNT+1))
53 else
Cameron Martin21ed4a22024-04-22 11:08:19 +010054 node ${DIR}/client.mjs --${1} --type $2 -p $3 -t $4 $5 || RET=1
Randy Abernethy8e731372015-02-03 00:04:40 -080055 fi
56 kill -2 $SERVERPID || RET=1
James E. King, III699b5bc2017-09-14 08:07:08 -070057 wait $SERVERPID
Roger Meier8909cbd2014-01-26 11:44:27 +010058 return $RET
59}
60
Mustafa Senol Cosar3f0d4442019-03-01 18:57:09 +030061testEpisodicCompilation()
62{
63 RET=0
64 if [ -n "${COVER}" ]; then
65 ${ISTANBUL} cover ${EPISODIC_DIR}/server.js --dir ${REPORT_PREFIX}${COUNT} --handle-sigint &
66 COUNT=$((COUNT+1))
67 else
68 node ${EPISODIC_DIR}/server.js &
69 fi
70 SERVERPID=$!
71 sleep 0.1
72 if [ -n "${COVER}" ]; then
73 ${ISTANBUL} cover ${EPISODIC_DIR}/client.js --dir ${REPORT_PREFIX}${COUNT} || RET=1
74 COUNT=$((COUNT+1))
75 else
76 node ${EPISODIC_DIR}/client.js || RET=1
77 fi
78 kill -2 $SERVERPID || RET=1
79 wait $SERVERPID
80 return $RET
81}
82
Randy Abernethyd8187c52015-02-16 01:25:53 -080083
Roger Meier8909cbd2014-01-26 11:44:27 +010084TESTOK=0
85
Mustafa Senol Cosar3f0d4442019-03-01 18:57:09 +030086# generating Thrift code
Roger Meier8909cbd2014-01-26 11:44:27 +010087
Jens Geyerf066d842022-06-13 23:37:25 +020088${THRIFT_COMPILER} -o ${DIR} --gen js:node ${THRIFT_FILES_DIR}/v0.16/ThriftTest.thrift
Mustafa Senol Cosar3f0d4442019-03-01 18:57:09 +030089${THRIFT_COMPILER} -o ${DIR} --gen js:node ${THRIFT_FILES_DIR}/JsDeepConstructorTest.thrift
90${THRIFT_COMPILER} -o ${DIR} --gen js:node ${THRIFT_FILES_DIR}/Int64Test.thrift
Cameron Martin21ed4a22024-04-22 11:08:19 +010091${THRIFT_COMPILER} -o ${DIR} --gen js:node ${THRIFT_FILES_DIR}/Include.thrift
bforbisda1169d2018-10-28 11:27:38 -040092mkdir ${DIR}/gen-nodejs-es6
Jens Geyerf066d842022-06-13 23:37:25 +020093${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 +030094${THRIFT_COMPILER} -out ${DIR}/gen-nodejs-es6 --gen js:node,es6 ${THRIFT_FILES_DIR}/JsDeepConstructorTest.thrift
95${THRIFT_COMPILER} -out ${DIR}/gen-nodejs-es6 --gen js:node,es6 ${THRIFT_FILES_DIR}/Int64Test.thrift
Cameron Martin21ed4a22024-04-22 11:08:19 +010096${THRIFT_COMPILER} -out ${DIR}/gen-nodejs-es6 --gen js:node,es6 ${THRIFT_FILES_DIR}/Include.thrift
97mkdir ${DIR}/gen-nodejs-esm
98${THRIFT_COMPILER} -out ${DIR}/gen-nodejs-esm --gen js:node,es6,esm ${THRIFT_FILES_DIR}/v0.16/ThriftTest.thrift
99${THRIFT_COMPILER} -out ${DIR}/gen-nodejs-esm --gen js:node,es6,esm ${THRIFT_FILES_DIR}/JsDeepConstructorTest.thrift
100${THRIFT_COMPILER} -out ${DIR}/gen-nodejs-esm --gen js:node,es6,esm ${THRIFT_FILES_DIR}/Int64Test.thrift
101${THRIFT_COMPILER} -out ${DIR}/gen-nodejs-esm --gen js:node,es6,esm ${THRIFT_FILES_DIR}/Include.thrift
Roger Meier8909cbd2014-01-26 11:44:27 +0100102
Mustafa Senol Cosar3f0d4442019-03-01 18:57:09 +0300103# generate episodic compilation test code
104TYPES_PACKAGE=${EPISODIC_DIR}/node_modules/types-package
105
106# generate the first episode
107mkdir --parents ${EPISODIC_DIR}/gen-1/first-episode
108${THRIFT_COMPILER} -o ${EPISODIC_DIR}/gen-1/first-episode --gen js:node,thrift_package_output_directory=first-episode ${THRIFT_FILES_DIR}/Types.thrift
109
110# create a "package" from the first episode and "install" it, the episode file must be at the module root
111mkdir --parents ${TYPES_PACKAGE}/first-episode
112cp --force ${EPISODIC_DIR}/episodic_compilation.package.json ${TYPES_PACKAGE}/package.json
113cp --force ${EPISODIC_DIR}/gen-1/first-episode/gen-nodejs/Types_types.js ${TYPES_PACKAGE}/first-episode/
114cp --force ${EPISODIC_DIR}/gen-1/first-episode/gen-nodejs/thrift.js.episode ${TYPES_PACKAGE}
115
116# generate the second episode
117mkdir --parents ${EPISODIC_DIR}/gen-2/second-episode
118${THRIFT_COMPILER} -o ${EPISODIC_DIR}/gen-2/second-episode --gen js:node,imports=${TYPES_PACKAGE} ${THRIFT_FILES_DIR}/Service.thrift
119if [ -f ${EPISODIC_DIR}/gen-2/second-episode/Types_types.js ]; then
120 TESTOK=1
121fi
122
123# unit tests
Roger Meier8909cbd2014-01-26 11:44:27 +0100124
Randy Abernethyd8187c52015-02-16 01:25:53 -0800125node ${DIR}/binary.test.js || TESTOK=1
Tuomo Jokimiesb60b8fe2024-03-18 16:56:25 +0200126node ${DIR}/header.test.js || TESTOK=1
Mustafa Senol Cosarf86845e2018-12-05 17:50:18 +0300127node ${DIR}/int64.test.js || TESTOK=1
Henrique Mendonça15d90422015-06-25 22:31:41 +1000128node ${DIR}/deep-constructor.test.js || TESTOK=1
Cameron Martin21ed4a22024-04-22 11:08:19 +0100129node ${DIR}/include.test.mjs || TESTOK=1
Roger Meier8909cbd2014-01-26 11:44:27 +0100130
Mustafa Senol Cosar3f0d4442019-03-01 18:57:09 +0300131# integration tests
Roger Meier8909cbd2014-01-26 11:44:27 +0100132
Randy Abernethyd8187c52015-02-16 01:25:53 -0800133for type in tcp multiplex websocket http
Randy Abernethy3b9ff4d2015-02-16 00:51:24 -0800134do
Randy Abernethy3b9ff4d2015-02-16 00:51:24 -0800135 for protocol in compact binary json
136 do
Randy Abernethy3b9ff4d2015-02-16 00:51:24 -0800137 for transport in buffered framed
138 do
Cameron Martin21ed4a22024-04-22 11:08:19 +0100139 for gen_variant in es5 es6 esm
bforbisda1169d2018-10-28 11:27:38 -0400140 do
Cameron Martin21ed4a22024-04-22 11:08:19 +0100141 testServer $gen_variant $type $protocol $transport || TESTOK=1
142 testServer $gen_variant $type $protocol $transport --ssl || TESTOK=1
143 testServer $gen_variant $type $protocol $transport --callback || TESTOK=1
bforbisda1169d2018-10-28 11:27:38 -0400144 done
Randy Abernethy3b9ff4d2015-02-16 00:51:24 -0800145 done
146 done
147done
Randy Abernethy2e091f62014-11-15 23:05:22 -0800148
Mustafa Senol Cosar3f0d4442019-03-01 18:57:09 +0300149# episodic compilation test
150testEpisodicCompilation
Randy Abernethyd8187c52015-02-16 01:25:53 -0800151
Randy Abernethy8e731372015-02-03 00:04:40 -0800152if [ -n "${COVER}" ]; then
Randy Abernethy8e731372015-02-03 00:04:40 -0800153 ${ISTANBUL} report --dir "${DIR}/../coverage" --include "${DIR}/../coverage/report*/coverage.json" lcov cobertura html
154 rm -r ${DIR}/../coverage/report*/*
155 rmdir ${DIR}/../coverage/report*
156fi
157
Roger Meier8909cbd2014-01-26 11:44:27 +0100158exit $TESTOK