blob: d37f9a31a7148dd6b1936201c4013b6d390538ac [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{
CJCombrink40d3e782026-03-23 06:09:04 +000063 local _server=$1
64 local _client=$2
65 echo " [Episodic Variant: ${_server}:${_client}] Testing Client(${_client})/Server(${_server})";
Mustafa Senol Cosar3f0d4442019-03-01 18:57:09 +030066 RET=0
67 if [ -n "${COVER}" ]; then
CJCombrink40d3e782026-03-23 06:09:04 +000068 ${ISTANBUL} cover ${EPISODIC_DIR}/server.js --dir ${REPORT_PREFIX}${COUNT} --handle-sigint -- --base "${_server}" &
Mustafa Senol Cosar3f0d4442019-03-01 18:57:09 +030069 COUNT=$((COUNT+1))
70 else
CJCombrink40d3e782026-03-23 06:09:04 +000071 node ${EPISODIC_DIR}/server.js --base "${_server}" &
Mustafa Senol Cosar3f0d4442019-03-01 18:57:09 +030072 fi
73 SERVERPID=$!
74 sleep 0.1
75 if [ -n "${COVER}" ]; then
CJCombrink40d3e782026-03-23 06:09:04 +000076 ${ISTANBUL} cover ${EPISODIC_DIR}/client.js --dir ${REPORT_PREFIX}${COUNT} -- --base "${_client}" || RET=1
Mustafa Senol Cosar3f0d4442019-03-01 18:57:09 +030077 COUNT=$((COUNT+1))
78 else
CJCombrink40d3e782026-03-23 06:09:04 +000079 node ${EPISODIC_DIR}/client.js --base "${_client}" || RET=1
Mustafa Senol Cosar3f0d4442019-03-01 18:57:09 +030080 fi
81 kill -2 $SERVERPID || RET=1
82 wait $SERVERPID
83 return $RET
84}
85
Randy Abernethyd8187c52015-02-16 01:25:53 -080086
Roger Meier8909cbd2014-01-26 11:44:27 +010087TESTOK=0
88
Mustafa Senol Cosar3f0d4442019-03-01 18:57:09 +030089# generating Thrift code
Roger Meier8909cbd2014-01-26 11:44:27 +010090
CJCombrinkdfeab8d2026-03-06 07:03:56 +010091${THRIFT_COMPILER} -o ${DIR} --gen js:node ${THRIFT_FILES_DIR}/ThriftTest.thrift
Mustafa Senol Cosar3f0d4442019-03-01 18:57:09 +030092${THRIFT_COMPILER} -o ${DIR} --gen js:node ${THRIFT_FILES_DIR}/JsDeepConstructorTest.thrift
93${THRIFT_COMPILER} -o ${DIR} --gen js:node ${THRIFT_FILES_DIR}/Int64Test.thrift
Cameron Martin21ed4a22024-04-22 11:08:19 +010094${THRIFT_COMPILER} -o ${DIR} --gen js:node ${THRIFT_FILES_DIR}/Include.thrift
bforbisda1169d2018-10-28 11:27:38 -040095mkdir ${DIR}/gen-nodejs-es6
CJCombrinkdfeab8d2026-03-06 07:03:56 +010096${THRIFT_COMPILER} -out ${DIR}/gen-nodejs-es6 --gen js:node,es6 ${THRIFT_FILES_DIR}/ThriftTest.thrift
Mustafa Senol Cosar3f0d4442019-03-01 18:57:09 +030097${THRIFT_COMPILER} -out ${DIR}/gen-nodejs-es6 --gen js:node,es6 ${THRIFT_FILES_DIR}/JsDeepConstructorTest.thrift
98${THRIFT_COMPILER} -out ${DIR}/gen-nodejs-es6 --gen js:node,es6 ${THRIFT_FILES_DIR}/Int64Test.thrift
Cameron Martin21ed4a22024-04-22 11:08:19 +010099${THRIFT_COMPILER} -out ${DIR}/gen-nodejs-es6 --gen js:node,es6 ${THRIFT_FILES_DIR}/Include.thrift
100mkdir ${DIR}/gen-nodejs-esm
CJCombrinkdfeab8d2026-03-06 07:03:56 +0100101${THRIFT_COMPILER} -out ${DIR}/gen-nodejs-esm --gen js:node,es6,esm ${THRIFT_FILES_DIR}/ThriftTest.thrift
Cameron Martin21ed4a22024-04-22 11:08:19 +0100102${THRIFT_COMPILER} -out ${DIR}/gen-nodejs-esm --gen js:node,es6,esm ${THRIFT_FILES_DIR}/JsDeepConstructorTest.thrift
103${THRIFT_COMPILER} -out ${DIR}/gen-nodejs-esm --gen js:node,es6,esm ${THRIFT_FILES_DIR}/Int64Test.thrift
104${THRIFT_COMPILER} -out ${DIR}/gen-nodejs-esm --gen js:node,es6,esm ${THRIFT_FILES_DIR}/Include.thrift
Roger Meier8909cbd2014-01-26 11:44:27 +0100105
Mustafa Senol Cosar3f0d4442019-03-01 18:57:09 +0300106# generate episodic compilation test code
107TYPES_PACKAGE=${EPISODIC_DIR}/node_modules/types-package
108
109# generate the first episode
110mkdir --parents ${EPISODIC_DIR}/gen-1/first-episode
CJCombrink40d3e782026-03-23 06:09:04 +0000111${THRIFT_COMPILER} -o ${EPISODIC_DIR}/gen-1/first-episode --gen js:node,ts,thrift_package_output_directory=first-episode ${THRIFT_FILES_DIR}/Types.thrift
Mustafa Senol Cosar3f0d4442019-03-01 18:57:09 +0300112
113# create a "package" from the first episode and "install" it, the episode file must be at the module root
114mkdir --parents ${TYPES_PACKAGE}/first-episode
115cp --force ${EPISODIC_DIR}/episodic_compilation.package.json ${TYPES_PACKAGE}/package.json
116cp --force ${EPISODIC_DIR}/gen-1/first-episode/gen-nodejs/Types_types.js ${TYPES_PACKAGE}/first-episode/
CJCombrink40d3e782026-03-23 06:09:04 +0000117cp --force ${EPISODIC_DIR}/gen-1/first-episode/gen-nodejs/Types_types.d.ts ${TYPES_PACKAGE}/first-episode/
118cp --force ${EPISODIC_DIR}/gen-1/first-episode/gen-nodejs/BaseService.js ${TYPES_PACKAGE}/first-episode/
119cp --force ${EPISODIC_DIR}/gen-1/first-episode/gen-nodejs/BaseService.d.ts ${TYPES_PACKAGE}/first-episode/
Mustafa Senol Cosar3f0d4442019-03-01 18:57:09 +0300120cp --force ${EPISODIC_DIR}/gen-1/first-episode/gen-nodejs/thrift.js.episode ${TYPES_PACKAGE}
CJCombrink40d3e782026-03-23 06:09:04 +0000121rm --force --recursive ${EPISODIC_DIR}/gen-1
Mustafa Senol Cosar3f0d4442019-03-01 18:57:09 +0300122
123# generate the second episode
124mkdir --parents ${EPISODIC_DIR}/gen-2/second-episode
CJCombrink40d3e782026-03-23 06:09:04 +0000125${THRIFT_COMPILER} -o ${EPISODIC_DIR}/gen-2/second-episode --gen js:node,ts,imports=${TYPES_PACKAGE} ${THRIFT_FILES_DIR}/Service.thrift
Mustafa Senol Cosar3f0d4442019-03-01 18:57:09 +0300126if [ -f ${EPISODIC_DIR}/gen-2/second-episode/Types_types.js ]; then
127 TESTOK=1
128fi
129
130# unit tests
Roger Meier8909cbd2014-01-26 11:44:27 +0100131
Randy Abernethyd8187c52015-02-16 01:25:53 -0800132node ${DIR}/binary.test.js || TESTOK=1
Tuomo Jokimiesb60b8fe2024-03-18 16:56:25 +0200133node ${DIR}/header.test.js || TESTOK=1
Mustafa Senol Cosarf86845e2018-12-05 17:50:18 +0300134node ${DIR}/int64.test.js || TESTOK=1
Henrique Mendonça15d90422015-06-25 22:31:41 +1000135node ${DIR}/deep-constructor.test.js || TESTOK=1
Cameron Martin21ed4a22024-04-22 11:08:19 +0100136node ${DIR}/include.test.mjs || TESTOK=1
CJCombrink86b15192026-03-12 15:10:25 +0100137node ${DIR}/thrift_4987_xhr_protocol.test.mjs || TESTOK=1
Roger Meier8909cbd2014-01-26 11:44:27 +0100138
Mustafa Senol Cosar3f0d4442019-03-01 18:57:09 +0300139# integration tests
Roger Meier8909cbd2014-01-26 11:44:27 +0100140
Randy Abernethyd8187c52015-02-16 01:25:53 -0800141for type in tcp multiplex websocket http
Randy Abernethy3b9ff4d2015-02-16 00:51:24 -0800142do
Randy Abernethy3b9ff4d2015-02-16 00:51:24 -0800143 for protocol in compact binary json
144 do
Randy Abernethy3b9ff4d2015-02-16 00:51:24 -0800145 for transport in buffered framed
146 do
Cameron Martin21ed4a22024-04-22 11:08:19 +0100147 for gen_variant in es5 es6 esm
bforbisda1169d2018-10-28 11:27:38 -0400148 do
Cameron Martin21ed4a22024-04-22 11:08:19 +0100149 testServer $gen_variant $type $protocol $transport || TESTOK=1
150 testServer $gen_variant $type $protocol $transport --ssl || TESTOK=1
151 testServer $gen_variant $type $protocol $transport --callback || TESTOK=1
bforbisda1169d2018-10-28 11:27:38 -0400152 done
Randy Abernethy3b9ff4d2015-02-16 00:51:24 -0800153 done
154 done
155done
Randy Abernethy2e091f62014-11-15 23:05:22 -0800156
Mustafa Senol Cosar3f0d4442019-03-01 18:57:09 +0300157# episodic compilation test
CJCombrink40d3e782026-03-23 06:09:04 +0000158echo "Testing Episode Compilation"
159testEpisodicCompilation 'pure' 'pure' || TESTOK=1
160testEpisodicCompilation 'base' 'base' || TESTOK=1
161testEpisodicCompilation 'extend' 'extend' || TESTOK=1
162testEpisodicCompilation 'extend' 'base' || TESTOK=1
163testEpisodicCompilation 'base' 'pure' || TESTOK=1
Randy Abernethyd8187c52015-02-16 01:25:53 -0800164
Randy Abernethy8e731372015-02-03 00:04:40 -0800165if [ -n "${COVER}" ]; then
Randy Abernethy8e731372015-02-03 00:04:40 -0800166 ${ISTANBUL} report --dir "${DIR}/../coverage" --include "${DIR}/../coverage/report*/coverage.json" lcov cobertura html
167 rm -r ${DIR}/../coverage/report*/*
168 rmdir ${DIR}/../coverage/report*
169fi
170
Roger Meier8909cbd2014-01-26 11:44:27 +0100171exit $TESTOK