Repository: thrift
Updated Branches:
  refs/heads/master 2f2d6ac7e -> 8e73137c2


THRIFT-2963: add code coverage to nodejs lib
Client: Node
Patch: Tom Croucher and Andrew de Andrade


Project: http://git-wip-us.apache.org/repos/asf/thrift/repo
Commit: http://git-wip-us.apache.org/repos/asf/thrift/commit/8e73137c
Tree: http://git-wip-us.apache.org/repos/asf/thrift/tree/8e73137c
Diff: http://git-wip-us.apache.org/repos/asf/thrift/diff/8e73137c

Branch: refs/heads/master
Commit: 8e73137c278b1ac7f4a455217393a7e6348c0766
Parents: 2f2d6ac
Author: Randy Abernethy <[email protected]>
Authored: Tue Feb 3 00:04:40 2015 -0800
Committer: Randy Abernethy <[email protected]>
Committed: Tue Feb 3 00:04:40 2015 -0800

----------------------------------------------------------------------
 lib/nodejs/.gitignore      |  1 +
 lib/nodejs/test/testAll.sh | 88 ++++++++++++++++++++++++++++++++++-------
 package.json               |  5 ++-
 3 files changed, 79 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/thrift/blob/8e73137c/lib/nodejs/.gitignore
----------------------------------------------------------------------
diff --git a/lib/nodejs/.gitignore b/lib/nodejs/.gitignore
new file mode 100644
index 0000000..4ebc8ae
--- /dev/null
+++ b/lib/nodejs/.gitignore
@@ -0,0 +1 @@
+coverage

http://git-wip-us.apache.org/repos/asf/thrift/blob/8e73137c/lib/nodejs/test/testAll.sh
----------------------------------------------------------------------
diff --git a/lib/nodejs/test/testAll.sh b/lib/nodejs/test/testAll.sh
index b96c9ee..cf66099 100755
--- a/lib/nodejs/test/testAll.sh
+++ b/lib/nodejs/test/testAll.sh
@@ -19,19 +19,40 @@
 # under the License.
 #
 
+if [ -n "${1}" ]; then
+  COVER=${1};
+fi
+
 DIR="$( cd "$( dirname "$0" )" && pwd )"
 
+ISTANBUL="$DIR/../../../node_modules/istanbul/lib/cli.js"
+NODEUNIT="${DIR}/../../../node_modules/nodeunit/bin/nodeunit"
+
+REPORT_PREFIX="${DIR}/../coverage/report"
+
+COUNT=0
+
 export NODE_PATH="${DIR}:${DIR}/../lib:${NODE_PATH}"
 
 testClientServer()
 {
   echo "   Testing Client/Server with protocol $1 and transport $2 $3";
   RET=0
-  node ${DIR}/server.js -p $1 -t $2 $3 &
+  if [ -n "${COVER}" ]; then
+    ${ISTANBUL} cover ${DIR}/server.js --dir ${REPORT_PREFIX}${COUNT} 
--handle-sigint -- -p $1 -t $2 $3 &
+    COUNT=$((COUNT+1))
+  else
+    node ${DIR}/server.js -p $1 -t $2 $3 &
+  fi
   SERVERPID=$!
   sleep 1
-  node ${DIR}/client.js -p $1 -t $2 $3 || RET=1
-  kill -9 $SERVERPID || RET=1
+  if [ -n "${COVER}" ]; then
+    ${ISTANBUL} cover ${DIR}/client.js --dir ${REPORT_PREFIX}${COUNT} -- -p $1 
-t $2 $3 || RET=1
+    COUNT=$((COUNT+1))
+  else
+    node ${DIR}/client.js -p $1 -t $2 $3 || RET=1
+  fi
+  kill -2 $SERVERPID || RET=1
   return $RET
 }
 
@@ -39,11 +60,21 @@ testMultiplexedClientServer()
 {
   echo "   Testing Multiplexed Client/Server with protocol $1 and transport $2 
$3";
   RET=0
-  node ${DIR}/multiplex_server.js -p $1 -t $2 $3 &
+  if [ -n "${COVER}" ]; then
+    ${ISTANBUL} cover ${DIR}/multiplex_server.js --dir 
${REPORT_PREFIX}${COUNT} --handle-sigint -- -p $1 -t $2 $3 &
+    COUNT=$((COUNT+1))
+  else
+    node ${DIR}/multiplex_server.js -p $1 -t $2 $3 &
+  fi
   SERVERPID=$!
   sleep 1
-  node ${DIR}/multiplex_client.js -p $1 -t $2 $3 || RET=1
-  kill -9 $SERVERPID || RET=1
+  if [ -n "${COVER}" ]; then
+    ${ISTANBUL} cover ${DIR}/multiplex_client.js --dir 
${REPORT_PREFIX}${COUNT} -- -p $1 -t $2 $3 || RET=1
+    COUNT=$((COUNT+1))
+  else
+    node ${DIR}/multiplex_client.js -p $1 -t $2 $3 || RET=1
+  fi
+  kill -2 $SERVERPID || RET=1
   return $RET
 }
 
@@ -51,11 +82,23 @@ testHttpClientServer()
 {
   echo "   Testing HTTP Client/Server with protocol $1 and transport $2 $3";
   RET=0
-  node ${DIR}/http_server.js -p $1 -t $2 $3 &
+  if [ -n "${COVER}" ]; then
+    ${ISTANBUL} cover ${DIR}/http_server.js --dir ${REPORT_PREFIX}${COUNT} 
--handle-sigint -- -p $1 -t $2 $3 &
+    COUNT=$((COUNT+1))
+  else
+    node ${DIR}/http_server.js -p $1 -t $2 $3 &
+  fi
   SERVERPID=$!
   sleep 1
-  node ${DIR}/http_client.js -p $1 -t $2 $3 || RET=1
-  kill -9 $SERVERPID || RET=1
+  if [ -n "${COVER}" ]; then
+    ${ISTANBUL} cover ${DIR}/http_client.js --dir ${REPORT_PREFIX}${COUNT} -- 
-p $1 -t $2 $3 || RET=1
+    COUNT=$((COUNT+1))
+  else
+    node ${DIR}/http_client.js -p $1 -t $2 $3 || RET=1
+  fi
+
+  kill -2 $SERVERPID || RET=1
+  sleep 1
   return $RET
 }
 
@@ -63,15 +106,25 @@ testWSClientServer()
 {
   echo "   Testing WebSocket Client/Server with protocol $1 and transport $2 
$3";
   RET=0
-  node ${DIR}/http_server.js -p $1 -t $2 $3 &
+  if [ -n "${COVER}" ]; then
+    ${ISTANBUL} cover ${DIR}/http_server.js --dir ${REPORT_PREFIX}${COUNT} 
--handle-sigint -- -p $1 -t $2 $3 &
+    COUNT=$((COUNT+1))
+  else
+    node ${DIR}/http_server.js -p $1 -t $2 $3 &
+  fi
   SERVERPID=$!
   sleep 1
-  node ${DIR}/ws_client.js -p $1 -t $2 $3 || RET=1
-  kill -9 $SERVERPID || RET=1
+  if [ -n "${COVER}" ]; then
+    ${ISTANBUL} cover ${DIR}/ws_client.js --dir ${REPORT_PREFIX}${COUNT} -- -p 
$1 -t $2 $3 || RET=1
+    COUNT=$((COUNT+1))
+  else
+    node ${DIR}/ws_client.js -p $1 -t $2 $3 || RET=1
+  fi
+
+  kill -2 $SERVERPID || RET=1
   return $RET
 }
 
-
 TESTOK=0
 
 #generating thrift code
@@ -80,7 +133,7 @@ ${DIR}/../../../compiler/cpp/thrift -o ${DIR} --gen js:node 
${DIR}/../../../test
 
 #unit tests
 
-${DIR}/../node_modules/nodeunit/bin/nodeunit ${DIR}/binary.test.js || TESTOK=1
+${NODEUNIT} ${DIR}/binary.test.js || TESTOK=1
 
 #integration tests
 
@@ -126,4 +179,11 @@ testWSClientServer binary framed || TESTOK=1
 testWSClientServer json buffered --promise || TESTOK=1
 testWSClientServer binary framed --ssl || TESTOK=1
 
+if [ -n "${COVER}" ]; then
+  echo "${DIR}/../coverage/report*/coverage.json"
+  ${ISTANBUL} report --dir "${DIR}/../coverage" --include 
"${DIR}/../coverage/report*/coverage.json" lcov cobertura html
+  rm -r ${DIR}/../coverage/report*/*
+  rmdir ${DIR}/../coverage/report*
+fi
+
 exit $TESTOK

http://git-wip-us.apache.org/repos/asf/thrift/blob/8e73137c/package.json
----------------------------------------------------------------------
diff --git a/package.json b/package.json
index 54b0b81..73524c4 100755
--- a/package.json
+++ b/package.json
@@ -37,9 +37,12 @@
   },
   "devDependencies": {
     "connect": "2.7.x",
-    "commander": "2.1.x"
+    "commander": "2.1.x",
+    "istanbul": "^0.3.5",
+    "tape": "^3.4.0"
   },
   "scripts": {
+    "cover": "lib/nodejs/test/testAll.sh COVER",
     "test": "lib/nodejs/test/testAll.sh"
   }
 }

Reply via email to