Roger Meier | 8909cbd | 2014-01-26 11:44:27 +0100 | [diff] [blame] | 1 | #! /bin/sh |
| 2 | |
Roger Meier | 8909cbd | 2014-01-26 11:44:27 +0100 | [diff] [blame] | 3 | # 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 Meier | 8909cbd | 2014-01-26 11:44:27 +0100 | [diff] [blame] | 19 | |
Randy Abernethy | 8e73137 | 2015-02-03 00:04:40 -0800 | [diff] [blame] | 20 | if [ -n "${1}" ]; then |
| 21 | COVER=${1}; |
| 22 | fi |
| 23 | |
Roger Meier | 8909cbd | 2014-01-26 11:44:27 +0100 | [diff] [blame] | 24 | DIR="$( cd "$( dirname "$0" )" && pwd )" |
| 25 | |
Mustafa Senol Cosar | 3f0d444 | 2019-03-01 18:57:09 +0300 | [diff] [blame] | 26 | EPISODIC_DIR=${DIR}/episodic-code-generation-test |
| 27 | |
| 28 | THRIFT_FILES_DIR=${DIR}/../../../test |
| 29 | |
| 30 | THRIFT_COMPILER=${DIR}/../../../compiler/cpp/thrift |
| 31 | |
Randy Abernethy | 8e73137 | 2015-02-03 00:04:40 -0800 | [diff] [blame] | 32 | ISTANBUL="$DIR/../../../node_modules/istanbul/lib/cli.js" |
Randy Abernethy | 8e73137 | 2015-02-03 00:04:40 -0800 | [diff] [blame] | 33 | |
| 34 | REPORT_PREFIX="${DIR}/../coverage/report" |
| 35 | |
| 36 | COUNT=0 |
| 37 | |
Roger Meier | 8909cbd | 2014-01-26 11:44:27 +0100 | [diff] [blame] | 38 | export NODE_PATH="${DIR}:${DIR}/../lib:${NODE_PATH}" |
| 39 | |
Randy Abernethy | 3b9ff4d | 2015-02-16 00:51:24 -0800 | [diff] [blame] | 40 | testServer() |
Roger Meier | 8909cbd | 2014-01-26 11:44:27 +0100 | [diff] [blame] | 41 | { |
bforbis | da1169d | 2018-10-28 11:27:38 -0400 | [diff] [blame] | 42 | echo " [ECMA $1] Testing $2 Client/Server with protocol $3 and transport $4 $5"; |
Roger Meier | 8909cbd | 2014-01-26 11:44:27 +0100 | [diff] [blame] | 43 | RET=0 |
Randy Abernethy | 8e73137 | 2015-02-03 00:04:40 -0800 | [diff] [blame] | 44 | if [ -n "${COVER}" ]; then |
bforbis | da1169d | 2018-10-28 11:27:38 -0400 | [diff] [blame] | 45 | ${ISTANBUL} cover ${DIR}/server.js --dir ${REPORT_PREFIX}${COUNT} --handle-sigint -- --type $2 -p $3 -t $4 $5 & |
Randy Abernethy | 8e73137 | 2015-02-03 00:04:40 -0800 | [diff] [blame] | 46 | COUNT=$((COUNT+1)) |
| 47 | else |
bforbis | da1169d | 2018-10-28 11:27:38 -0400 | [diff] [blame] | 48 | node ${DIR}/server.js --${1} --type $2 -p $3 -t $4 $5 & |
Randy Abernethy | 8e73137 | 2015-02-03 00:04:40 -0800 | [diff] [blame] | 49 | fi |
Roger Meier | 8909cbd | 2014-01-26 11:44:27 +0100 | [diff] [blame] | 50 | SERVERPID=$! |
James E. King, III | 699b5bc | 2017-09-14 08:07:08 -0700 | [diff] [blame] | 51 | sleep 0.1 |
Randy Abernethy | 8e73137 | 2015-02-03 00:04:40 -0800 | [diff] [blame] | 52 | if [ -n "${COVER}" ]; then |
bforbis | da1169d | 2018-10-28 11:27:38 -0400 | [diff] [blame] | 53 | ${ISTANBUL} cover ${DIR}/client.js --dir ${REPORT_PREFIX}${COUNT} -- --${1} --type $2 -p $3 -t $4 $5 || RET=1 |
Randy Abernethy | 8e73137 | 2015-02-03 00:04:40 -0800 | [diff] [blame] | 54 | COUNT=$((COUNT+1)) |
| 55 | else |
bforbis | da1169d | 2018-10-28 11:27:38 -0400 | [diff] [blame] | 56 | node ${DIR}/client.js --${1} --type $2 -p $3 -t $4 $5 || RET=1 |
Randy Abernethy | 8e73137 | 2015-02-03 00:04:40 -0800 | [diff] [blame] | 57 | fi |
| 58 | kill -2 $SERVERPID || RET=1 |
James E. King, III | 699b5bc | 2017-09-14 08:07:08 -0700 | [diff] [blame] | 59 | wait $SERVERPID |
Roger Meier | 8909cbd | 2014-01-26 11:44:27 +0100 | [diff] [blame] | 60 | return $RET |
| 61 | } |
| 62 | |
Mustafa Senol Cosar | 3f0d444 | 2019-03-01 18:57:09 +0300 | [diff] [blame] | 63 | testEpisodicCompilation() |
| 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 Abernethy | d8187c5 | 2015-02-16 01:25:53 -0800 | [diff] [blame] | 85 | |
Roger Meier | 8909cbd | 2014-01-26 11:44:27 +0100 | [diff] [blame] | 86 | TESTOK=0 |
| 87 | |
Mustafa Senol Cosar | 3f0d444 | 2019-03-01 18:57:09 +0300 | [diff] [blame] | 88 | # generating Thrift code |
Roger Meier | 8909cbd | 2014-01-26 11:44:27 +0100 | [diff] [blame] | 89 | |
Jens Geyer | f066d84 | 2022-06-13 23:37:25 +0200 | [diff] [blame] | 90 | ${THRIFT_COMPILER} -o ${DIR} --gen js:node ${THRIFT_FILES_DIR}/v0.16/ThriftTest.thrift |
Mustafa Senol Cosar | 3f0d444 | 2019-03-01 18:57:09 +0300 | [diff] [blame] | 91 | ${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 |
bforbis | da1169d | 2018-10-28 11:27:38 -0400 | [diff] [blame] | 93 | mkdir ${DIR}/gen-nodejs-es6 |
Jens Geyer | f066d84 | 2022-06-13 23:37:25 +0200 | [diff] [blame] | 94 | ${THRIFT_COMPILER} -out ${DIR}/gen-nodejs-es6 --gen js:node,es6 ${THRIFT_FILES_DIR}/v0.16/ThriftTest.thrift |
Mustafa Senol Cosar | 3f0d444 | 2019-03-01 18:57:09 +0300 | [diff] [blame] | 95 | ${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 Meier | 8909cbd | 2014-01-26 11:44:27 +0100 | [diff] [blame] | 97 | |
Mustafa Senol Cosar | 3f0d444 | 2019-03-01 18:57:09 +0300 | [diff] [blame] | 98 | # generate episodic compilation test code |
| 99 | TYPES_PACKAGE=${EPISODIC_DIR}/node_modules/types-package |
| 100 | |
| 101 | # generate the first episode |
| 102 | mkdir --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 |
| 106 | mkdir --parents ${TYPES_PACKAGE}/first-episode |
| 107 | cp --force ${EPISODIC_DIR}/episodic_compilation.package.json ${TYPES_PACKAGE}/package.json |
| 108 | cp --force ${EPISODIC_DIR}/gen-1/first-episode/gen-nodejs/Types_types.js ${TYPES_PACKAGE}/first-episode/ |
| 109 | cp --force ${EPISODIC_DIR}/gen-1/first-episode/gen-nodejs/thrift.js.episode ${TYPES_PACKAGE} |
| 110 | |
| 111 | # generate the second episode |
| 112 | mkdir --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 |
| 114 | if [ -f ${EPISODIC_DIR}/gen-2/second-episode/Types_types.js ]; then |
| 115 | TESTOK=1 |
| 116 | fi |
| 117 | |
| 118 | # unit tests |
Roger Meier | 8909cbd | 2014-01-26 11:44:27 +0100 | [diff] [blame] | 119 | |
Randy Abernethy | d8187c5 | 2015-02-16 01:25:53 -0800 | [diff] [blame] | 120 | node ${DIR}/binary.test.js || TESTOK=1 |
Tuomo Jokimies | b60b8fe | 2024-03-18 16:56:25 +0200 | [diff] [blame] | 121 | node ${DIR}/header.test.js || TESTOK=1 |
Mustafa Senol Cosar | f86845e | 2018-12-05 17:50:18 +0300 | [diff] [blame] | 122 | node ${DIR}/int64.test.js || TESTOK=1 |
Henrique Mendonça | 15d9042 | 2015-06-25 22:31:41 +1000 | [diff] [blame] | 123 | node ${DIR}/deep-constructor.test.js || TESTOK=1 |
Roger Meier | 8909cbd | 2014-01-26 11:44:27 +0100 | [diff] [blame] | 124 | |
Mustafa Senol Cosar | 3f0d444 | 2019-03-01 18:57:09 +0300 | [diff] [blame] | 125 | # integration tests |
Roger Meier | 8909cbd | 2014-01-26 11:44:27 +0100 | [diff] [blame] | 126 | |
Randy Abernethy | d8187c5 | 2015-02-16 01:25:53 -0800 | [diff] [blame] | 127 | for type in tcp multiplex websocket http |
Randy Abernethy | 3b9ff4d | 2015-02-16 00:51:24 -0800 | [diff] [blame] | 128 | do |
Randy Abernethy | 3b9ff4d | 2015-02-16 00:51:24 -0800 | [diff] [blame] | 129 | for protocol in compact binary json |
| 130 | do |
Randy Abernethy | 3b9ff4d | 2015-02-16 00:51:24 -0800 | [diff] [blame] | 131 | for transport in buffered framed |
| 132 | do |
bforbis | da1169d | 2018-10-28 11:27:38 -0400 | [diff] [blame] | 133 | 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 Abernethy | 3b9ff4d | 2015-02-16 00:51:24 -0800 | [diff] [blame] | 139 | done |
| 140 | done |
| 141 | done |
Randy Abernethy | 2e091f6 | 2014-11-15 23:05:22 -0800 | [diff] [blame] | 142 | |
Mustafa Senol Cosar | 3f0d444 | 2019-03-01 18:57:09 +0300 | [diff] [blame] | 143 | # episodic compilation test |
| 144 | testEpisodicCompilation |
Randy Abernethy | d8187c5 | 2015-02-16 01:25:53 -0800 | [diff] [blame] | 145 | |
Randy Abernethy | 8e73137 | 2015-02-03 00:04:40 -0800 | [diff] [blame] | 146 | if [ -n "${COVER}" ]; then |
Randy Abernethy | 8e73137 | 2015-02-03 00:04:40 -0800 | [diff] [blame] | 147 | ${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* |
| 150 | fi |
| 151 | |
Roger Meier | 8909cbd | 2014-01-26 11:44:27 +0100 | [diff] [blame] | 152 | exit $TESTOK |