THRIFT-2327 nodejs: nodejs test suite should be bundled with the library
Patch: Pierre Lamot

further modifications by Roger Meier
- git mv instead of delete and add
- detect node or nodejs with configure.ac
- use exit instead of return within lib/nodejs/test/testAll.sh
diff --git a/.gitignore b/.gitignore
index 3f95581..9755012 100644
--- a/.gitignore
+++ b/.gitignore
@@ -188,6 +188,9 @@
 /lib/js/test/build
 /lib/js/test/Makefile
 /lib/js/test/Makefile.in
+/lib/nodejs/Makefile
+/lib/nodejs/Makefile.in
+/lib/nodejs/node_modules/
 /lib/perl/MANIFEST
 /lib/perl/MYMETA.yml
 /lib/perl/Makefile
diff --git a/configure.ac b/configure.ac
index 7d9a82e..b2577dd 100755
--- a/configure.ac
+++ b/configure.ac
@@ -178,6 +178,18 @@
 fi
 AM_CONDITIONAL(WITH_ERLANG, [test "$have_erlang" = "yes"])
 
+AX_THRIFT_LIB(nodejs, [Nodejs], yes)
+have_nodejs=no
+if test "$with_nodejs" = "yes"; then
+  AC_PATH_PROGS([NODEJS], [nodejs node])
+  AC_PATH_PROG([NPM], [npm])
+  if test "x$NODEJS" != "x" -a "x$NPM" != "x"; then
+    have_nodejs="yes"
+  fi
+fi
+AM_CONDITIONAL(WITH_NODEJS, [test "$have_nodejs" = "yes"])
+AM_CONDITIONAL(HAVE_NPM, [test "x$NPM" != "x"])
+
 AX_THRIFT_LIB(python, [Python], yes)
 if test "$with_python" = "yes";  then
   AM_PATH_PYTHON(2.4,, :)
@@ -547,7 +559,7 @@
 # gruard against pre defined config.h
 AH_TOP([
 #ifndef CONFIG_H
-#define CONFIG_H 
+#define CONFIG_H
 ])
 AH_BOTTOM([
 #endif
@@ -578,6 +590,7 @@
   lib/hs/Makefile
   lib/java/Makefile
   lib/js/test/Makefile
+  lib/nodejs/Makefile
   lib/perl/Makefile
   lib/perl/test/Makefile
   lib/php/Makefile
@@ -587,7 +600,6 @@
   test/Makefile
   test/cpp/Makefile
   test/hs/Makefile
-  test/nodejs/Makefile
   test/php/Makefile
   test/perl/Makefile
   test/py/Makefile
@@ -623,6 +635,7 @@
 echo "Building Erlang Library ...... : $have_erlang"
 echo "Building Go Library .......... : $have_go"
 echo "Building D Library ........... : $have_d"
+echo "Building NodeJS Library ...... : $have_nodejs"
 
 if test "$have_cpp" = "yes" ; then
   echo
@@ -687,6 +700,12 @@
   echo "   Building D libevent tests . : $with_d_event_tests"
   echo "   Building D SSL tests ...... : $with_d_ssl_tests"
 fi
+if test "$have_nodejs" = "yes" ; then
+  echo
+  echo "NodeJS Library:"
+  echo "   Using NodeJS .............. : $NODEJS"
+  echo "   Using NodeJS version....... : $($NODEJS --version)"
+fi
 echo
 echo "If something is missing that you think should be present,"
 echo "please skim the output of configure to find the missing"
diff --git a/lib/Makefile.am b/lib/Makefile.am
index 1cc5c6c..26d9020 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -70,6 +70,11 @@
 SUBDIRS += d
 endif
 
+if WITH_NODEJS
+SUBDIRS += nodejs
+endif
+
+
 # All of the libs that don't use Automake need to go in here
 # so they will end up in our release tarballs.
 EXTRA_DIST = \
@@ -79,6 +84,5 @@
 			delphi \
 			javame \
 			js \
-			nodejs \
 			ocaml \
 			st
diff --git a/lib/nodejs/Makefile.am b/lib/nodejs/Makefile.am
new file mode 100755
index 0000000..5e298d4
--- /dev/null
+++ b/lib/nodejs/Makefile.am
@@ -0,0 +1,31 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+
+THRIFT = $(top_srcdir)/compiler/cpp/thrift
+
+#stubs: $(top_srcdir)/test/ThriftTest.thrift
+#	$(THRIFT) --gen js:node -o test/ $(top_srcdir)/test/ThriftTest.thrift
+
+deps: package.json
+	$(NPM) install
+
+check: deps
+	$(NPM) test
+
+clean-local:
+	$(RM) -r test/gen-nodejs
diff --git a/lib/nodejs/package.json b/lib/nodejs/package.json
index 668c58d..b2b92d6 100755
--- a/lib/nodejs/package.json
+++ b/lib/nodejs/package.json
@@ -29,6 +29,10 @@
     "nodeunit": "~0.8.0"
   },
   "devDependencies": {
-    "connect": "2.7.x"
+    "connect": "2.7.x",
+    "commander": "2.1.x"
+  },
+  "scripts": {
+    "test" : "test/testAll.sh"
   }
 }
diff --git a/lib/nodejs/test/client.js b/lib/nodejs/test/client.js
new file mode 100644
index 0000000..e7d6e61
--- /dev/null
+++ b/lib/nodejs/test/client.js
@@ -0,0 +1,77 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+//Client test for the following I/O stack:
+//    TBinaryProtocol
+//    TFramedTransport
+//    TSocket
+
+var assert = require('assert');
+var thrift = require('thrift');
+var ThriftTransports = require('thrift/transport');
+var ThriftProtocols = require('thrift/protocol');
+var ThriftTest = require('./gen-nodejs/ThriftTest');
+var ThriftTestDriver = require('./thrift_test_driver').ThriftTestDriver;
+
+var program = require('commander');
+
+program
+  .option('-p, --protocol <protocol>', 'Set thift protocol (binary|json) [protocol]')
+  .option('-t, --transport <transport>', 'Set thift transport (buffered|framed) [transport]')
+  .parse(process.argv);
+
+var protocol = undefined;
+var transport =  undefined;
+
+if (program.protocol === "binary") {
+  protocol = ThriftProtocols.TBinaryProtocol;
+} else if (program.protocol === "json") {
+  protocol = ThriftProtocols.TJSONProtocol;
+} else {
+  //default
+  protocol = ThriftProtocols.TBinaryProtocol;
+}
+
+if (program.transport === "framed") {
+  transport = ThriftTransports.TFramedTransport;
+} else if (program.transport === "buffered") {
+  transport = ThriftTransports.TBufferedTransport;
+} else {
+  //default
+  transport = ThriftTransports.TBufferedTransport;
+}
+
+var connection = thrift.createConnection('localhost', 9090, {
+  transport: transport,
+  protocol: protocol
+});
+
+var client = thrift.createClient(ThriftTest, connection);
+
+connection.on('error', function(err) {
+  assert(false, err);
+});
+
+ThriftTestDriver(client, function (status) {
+  console.log(status);
+  connection.end();
+});
+
+// to make it also run on expresso
+exports.expressoTest = function() {};
diff --git a/test/nodejs/multiplex_client.js b/lib/nodejs/test/multiplex_client.js
similarity index 90%
rename from test/nodejs/multiplex_client.js
rename to lib/nodejs/test/multiplex_client.js
index ba0d47b..6cf6975 100644
--- a/test/nodejs/multiplex_client.js
+++ b/lib/nodejs/test/multiplex_client.js
@@ -17,15 +17,45 @@
  * under the License.
  */
 var thrift = require('thrift');
-var ttransport = require('transport');
+var ThriftTransports = require('thrift/transport');
+var ThriftProtocols = require('thrift/protocol');
 var assert = require('assert');
 
 var ThriftTest = require('./gen-nodejs/ThriftTest'),
     SecondService = require('./gen-nodejs/SecondService'),
     ttypes = require('./gen-nodejs/ThriftTest_types');
 
+var program = require('commander');
+
+program
+  .option('-p, --protocol <protocol>', 'Set thift protocol (binary|json) [protocol]')
+  .option('-t, --transport <transport>', 'Set thift transport (buffered|framed) [transport]')
+  .parse(process.argv);
+
+var protocol = undefined;
+var transport =  undefined;
+
+if (program.protocol === "binary") {
+  protocol = ThriftProtocols.TBinaryProtocol;
+} else if (program.protocol === "json") {
+  protocol = ThriftProtocols.TJSONProtocol;
+} else {
+  //default
+  protocol = ThriftProtocols.TBinaryProtocol;
+}
+
+if (program.transport === "framed") {
+  transport = ThriftTransports.TFramedTransport;
+} else if (program.transport === "buffered") {
+  transport = ThriftTransports.TBufferedTransport;
+} else {
+  //default
+  transport = ThriftTransports.TBufferedTransport;
+}
+
 var connection = thrift.createConnection('localhost', 9090, {
-    'transport': ttransport.TFramedTransport
+  transport: transport,
+  protocol: protocol
 });
 
 var mp = new thrift.Multiplexer();
diff --git a/lib/nodejs/test/multiplex_server.js b/lib/nodejs/test/multiplex_server.js
new file mode 100644
index 0000000..a2a1709
--- /dev/null
+++ b/lib/nodejs/test/multiplex_server.js
@@ -0,0 +1,80 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * 'License'); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * 'AS IS' BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+var thrift = require('thrift');
+var Thrift = thrift.Thrift;
+var ThriftTransports = require('thrift/transport');
+var ThriftProtocols = require('thrift/protocol');
+
+var ThriftTest = require('./gen-nodejs/ThriftTest'),
+  SecondService = require('./gen-nodejs/SecondService'),
+  ttypes = require('./gen-nodejs/ThriftTest_types');
+
+var program = require('commander');
+
+program
+  .option('-p, --protocol <protocol>', 'Set thift protocol (binary|json) [protocol]')
+  .option('-t, --transport <transport>', 'Set thift transport (buffered|framed) [transport]')
+  .parse(process.argv);
+
+var protocol = undefined;
+var transport =  undefined;
+
+if (program.protocol === "binary") {
+  protocol = ThriftProtocols.TBinaryProtocol;
+} else if (program.protocol === "json") {
+  protocol = ThriftProtocols.TJSONProtocol;
+} else {
+  //default
+  protocol = ThriftProtocols.TBinaryProtocol;
+}
+
+if (program.transport === "framed") {
+  transport = ThriftTransports.TFramedTransport;
+} else if (program.transport === "buffered") {
+  transport = ThriftTransports.TBufferedTransport;
+} else {
+  //default
+  transport = ThriftTransports.TBufferedTransport;
+}
+
+var ThriftTestHandler = require("./test_handler").ThriftTestHandler;
+
+var SecondServiceHandler = {
+  secondtestString: function(thing, result) {
+    console.log('testString(\'' + thing + '\')');
+    result(null, thing);
+  }
+};
+
+var processor = new thrift.MultiplexedProcessor();
+
+processor.registerProcessor(
+  "ThriftTest",
+  new ThriftTest.Processor(ThriftTestHandler));
+
+processor.registerProcessor(
+  "SecondService",
+  new SecondService.Processor(SecondServiceHandler));
+
+var server = thrift.createMultiplexServer(processor, {
+  protocol: protocol,
+  transport: transport
+});
+
+server.listen(9090);
diff --git a/lib/nodejs/test/server.js b/lib/nodejs/test/server.js
new file mode 100644
index 0000000..da9a4d6
--- /dev/null
+++ b/lib/nodejs/test/server.js
@@ -0,0 +1,63 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * 'License'); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * 'AS IS' BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+//Server test for the following I/O stack:
+//    TBinaryProtocol
+//    TFramedTransport
+//    TSocket
+
+var thrift = require('thrift');
+var ThriftTransports = require('thrift/transport');
+var ThriftProtocols = require('thrift/protocol');
+var ThriftTest = require('./gen-nodejs/ThriftTest');
+var ThriftTestHandler = require('./test_handler').ThriftTestHandler;
+
+
+var program = require('commander');
+
+program
+  .option('-p, --protocol <protocol>', 'Set thift protocol (binary|json) [protocol]')
+  .option('-t, --transport <transport>', 'Set thift transport (buffered|framed) [transport]')
+  .parse(process.argv);
+
+var protocol = undefined;
+var transport =  undefined;
+
+if (program.protocol === "binary") {
+  protocol = ThriftProtocols.TBinaryProtocol;
+} else if (program.protocol === "json") {
+  protocol = ThriftProtocols.TJSONProtocol;
+} else {
+  //default
+  protocol = ThriftProtocols.TBinaryProtocol;
+}
+
+if (program.transport === "framed") {
+  transport = ThriftTransports.TFramedTransport;
+} else if (program.transport === "buffered") {
+  transport = ThriftTransports.TBufferedTransport;
+} else {
+  //default
+  transport = ThriftTransports.TBufferedTransport;
+}
+
+thrift.createServer(ThriftTest, ThriftTestHandler, {
+  protocol: protocol,
+  transport: transport
+}).listen(9090);
diff --git a/test/nodejs/server_http.js b/lib/nodejs/test/server_http.js
similarity index 100%
rename from test/nodejs/server_http.js
rename to lib/nodejs/test/server_http.js
diff --git a/test/nodejs/test.html b/lib/nodejs/test/test.html
similarity index 100%
rename from test/nodejs/test.html
rename to lib/nodejs/test/test.html
diff --git a/test/nodejs/test.js b/lib/nodejs/test/test.js
similarity index 100%
rename from test/nodejs/test.js
rename to lib/nodejs/test/test.js
diff --git a/lib/nodejs/test/testAll.sh b/lib/nodejs/test/testAll.sh
new file mode 100755
index 0000000..3e64393
--- /dev/null
+++ b/lib/nodejs/test/testAll.sh
@@ -0,0 +1,73 @@
+#! /bin/sh
+
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+DIR="$( cd "$( dirname "$0" )" && pwd )"
+
+export NODE_PATH="${DIR}:${DIR}/../lib:${NODE_PATH}"
+
+testClientServer()
+{
+  echo "   Testing Client/Server with protocol $1 and transport $2";
+  RET=0
+  node ${DIR}/server.js -p $1 -t $2 &
+  SERVERPID=$!
+  sleep 1
+  node ${DIR}/client.js -p $1 -t $2 || RET=1
+  kill -9 $SERVERPID || RET=1
+  return $RET
+}
+
+testMultiplexedClientServer()
+{
+  echo "   Testing Multiplexed Client/Server with protocol $1 and transport $2";
+  RET=0
+  node ${DIR}/multiplex_server.js -p $1 -t $2 &
+  SERVERPID=$!
+  sleep 1
+  node ${DIR}/multiplex_client.js -p $1 -t $2 || RET=1
+  kill -9 $SERVERPID || RET=1 #f
+  return $RET
+}
+
+
+TESTOK=0
+
+#generating thrift code
+
+${DIR}/../../../compiler/cpp/thrift -o ${DIR} --gen js:node ${DIR}/../../../test/ThriftTest.thrift
+
+#unit tests
+
+node ${DIR}/binary.test.js || TESTOK=1
+
+#integration tests
+
+testClientServer binary buffered || TESTOK=1
+testClientServer json buffered || TESTOK=1
+testClientServer binary framed || TESTOK=1
+testClientServer json framed || TESTOK=1
+
+testMultiplexedClientServer binary buffered || TESTOK=1
+testMultiplexedClientServer json buffered || TESTOK=1
+testMultiplexedClientServer binary framed || TESTOK=1
+testMultiplexedClientServer json framed || TESTOK=1
+
+exit $TESTOK
diff --git a/test/nodejs/test_handler.js b/lib/nodejs/test/test_handler.js
similarity index 100%
rename from test/nodejs/test_handler.js
rename to lib/nodejs/test/test_handler.js
diff --git a/test/nodejs/thrift_test_driver.js b/lib/nodejs/test/thrift_test_driver.js
similarity index 100%
rename from test/nodejs/thrift_test_driver.js
rename to lib/nodejs/test/thrift_test_driver.js
diff --git a/test/Makefile.am b/test/Makefile.am
index 175f477..2d44229 100755
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -17,7 +17,7 @@
 # under the License.
 #
 
-SUBDIRS = nodejs
+SUBDIRS =
 
 if WITH_CPP
 SUBDIRS += cpp
@@ -55,7 +55,6 @@
 	test.sh \
 	cpp \
 	hs \
-	nodejs \
 	ocaml \
 	perl \
 	php \
diff --git a/test/nodejs/Makefile.am b/test/nodejs/Makefile.am
deleted file mode 100755
index 39a7237..0000000
--- a/test/nodejs/Makefile.am
+++ /dev/null
@@ -1,56 +0,0 @@
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements. See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License. You may obtain a copy of the License at
-#
-#   http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied. See the License for the
-# specific language governing permissions and limitations
-# under the License.
-
-
-THRIFT = $(top_srcdir)/compiler/cpp/thrift
-
-stubs: ../ThriftTest.thrift
-	$(THRIFT) --gen js:node ../ThriftTest.thrift
-
-check: stubs
-	@if which nodeunit &> /dev/null ; then \
-		echo "   Testing thrift/binary"; \
-		NODE_PATH=../../lib/nodejs/lib:../../lib/nodejs/lib/thrift:$(NODE_PATH) nodeunit ../../lib/nodejs/test/binary.test.js; \
-	fi
-	@if which node &> /dev/null ; then \
-		echo "   Testing Client/Server"; \
-		timeout -s14 5 $(MAKE) server & \
-		sleep 1; $(MAKE) client; sleep 2; \
-		\
-		echo "   Testing Multiplex Client/Server"; \
-		sleep 4; timeout -s14 5 $(MAKE) mserver & \
-		sleep 1; $(MAKE) mclient; sleep 2; \
-		\
-		echo "   Testing Client/Server examples"; \
-		sleep 4; timeout -s14 5 $(MAKE) -C ../../lib/nodejs/examples server & \
-		sleep 1; $(MAKE) -C ../../lib/nodejs/examples client; sleep 2; \
-	fi
-
-clean-local:
-	$(RM) -r gen-nodejs
-
-server:
-	NODE_PATH=../../lib/nodejs/lib:../../lib/nodejs/lib/thrift:$(NODE_PATH) node server.js
-
-client:
-	NODE_PATH=../../lib/nodejs/lib:../../lib/nodejs/lib/thrift:$(NODE_PATH) node client.js
-
-mserver:
-	NODE_PATH=../../lib/nodejs/lib:../../lib/nodejs/lib/thrift:$(NODE_PATH) node multiplex_server.js
-
-mclient:
-	NODE_PATH=../../lib/nodejs/lib:../../lib/nodejs/lib/thrift:$(NODE_PATH) node multiplex_client.js
diff --git a/test/nodejs/client.js b/test/nodejs/client.js
deleted file mode 100644
index d70ec0c..0000000
--- a/test/nodejs/client.js
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-//Client test for the following I/O stack:
-//    TBinaryProtocol
-//    TFramedTransport
-//    TSocket
-
-var assert = require('assert');
-var thrift = require('thrift');
-var TFramedTransport = require('thrift/transport').TFramedTransport;
-var ThriftTest = require('./gen-nodejs/ThriftTest');
-var ThriftTestDriver = require('./thrift_test_driver').ThriftTestDriver;
-
-var connection = thrift.createConnection('localhost', 9090, { transport: TFramedTransport} );
-var client = thrift.createClient(ThriftTest, connection);
-
-connection.on('error', function(err) {
-  assert(false, err);
-});
-
-ThriftTestDriver(client, function (status) {
-  console.log(status);
-  connection.end();
-});
-
-// to make it also run on expresso
-exports.expressoTest = function() {};
-
diff --git a/test/nodejs/client_bin.js b/test/nodejs/client_bin.js
deleted file mode 100644
index d077202..0000000
--- a/test/nodejs/client_bin.js
+++ /dev/null
@@ -1,47 +0,0 @@
-/*

- * Licensed to the Apache Software Foundation (ASF) under one

- * or more contributor license agreements. See the NOTICE file

- * distributed with this work for additional information

- * regarding copyright ownership. The ASF licenses this file

- * to you under the Apache License, Version 2.0 (the

- * "License"); you may not use this file except in compliance

- * with the License. You may obtain a copy of the License at

- *

- *   http://www.apache.org/licenses/LICENSE-2.0

- *

- * Unless required by applicable law or agreed to in writing,

- * software distributed under the License is distributed on an

- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY

- * KIND, either express or implied. See the License for the

- * specific language governing permissions and limitations

- * under the License.

- */

-

-//Node client test for the following I/O stack:

-//    TJSONProtocol

-//    TBufferedTransport

-//    TSocket

-

-var assert = require('assert');

-var thrift = require('thrift');

-var TBufferedTransport = require('thrift/transport').TBufferedTransport;

-var TBinaryProtocol = require('thrift/protocol').TBinaryProtocol;

-var ThriftTest = require('./gen-nodejs/ThriftTest');

-var ThriftTestDriver = require('./thrift_test_driver').ThriftTestDriver;

-

-var connection = thrift.createConnection('localhost', 9090, 

-	                { protocol: TBinaryProtocol, transport: TBufferedTransport} );

-var client = thrift.createClient(ThriftTest, connection);

-

-connection.on('error', function(err) {

-  assert(false, err);

-});

-

-ThriftTestDriver(client, function (status) {

-  console.log(status);

-  connection.end();

-});

-

-// to make it also run on expresso

-exports.expressoTest = function() {};

-

diff --git a/test/nodejs/client_json.js b/test/nodejs/client_json.js
deleted file mode 100644
index de0190f..0000000
--- a/test/nodejs/client_json.js
+++ /dev/null
@@ -1,47 +0,0 @@
-/*

- * Licensed to the Apache Software Foundation (ASF) under one

- * or more contributor license agreements. See the NOTICE file

- * distributed with this work for additional information

- * regarding copyright ownership. The ASF licenses this file

- * to you under the Apache License, Version 2.0 (the

- * "License"); you may not use this file except in compliance

- * with the License. You may obtain a copy of the License at

- *

- *   http://www.apache.org/licenses/LICENSE-2.0

- *

- * Unless required by applicable law or agreed to in writing,

- * software distributed under the License is distributed on an

- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY

- * KIND, either express or implied. See the License for the

- * specific language governing permissions and limitations

- * under the License.

- */

-

-//Node client test for the following I/O stack:

-//    TJSONProtocol

-//    TBufferedTransport

-//    TSocket

-

-var assert = require('assert');

-var thrift = require('thrift');

-var TBufferedTransport = require('thrift/transport').TBufferedTransport;

-var TJSONProtocol = require('thrift/protocol').TJSONProtocol;

-var ThriftTest = require('./gen-nodejs/ThriftTest');

-var ThriftTestDriver = require('./thrift_test_driver').ThriftTestDriver;

-

-var connection = thrift.createConnection('localhost', 9090, 

-	                { protocol: TJSONProtocol, transport: TBufferedTransport} );

-var client = thrift.createClient(ThriftTest, connection);

-

-connection.on('error', function(err) {

-  assert(false, err);

-});

-

-ThriftTestDriver(client, function (status) {

-  console.log(status);

-  connection.end();

-});

-

-// to make it also run on expresso

-exports.expressoTest = function() {};

-

diff --git a/test/nodejs/client_json_frame.js b/test/nodejs/client_json_frame.js
deleted file mode 100644
index f23ddd4..0000000
--- a/test/nodejs/client_json_frame.js
+++ /dev/null
@@ -1,47 +0,0 @@
-/*

- * Licensed to the Apache Software Foundation (ASF) under one

- * or more contributor license agreements. See the NOTICE file

- * distributed with this work for additional information

- * regarding copyright ownership. The ASF licenses this file

- * to you under the Apache License, Version 2.0 (the

- * "License"); you may not use this file except in compliance

- * with the License. You may obtain a copy of the License at

- *

- *   http://www.apache.org/licenses/LICENSE-2.0

- *

- * Unless required by applicable law or agreed to in writing,

- * software distributed under the License is distributed on an

- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY

- * KIND, either express or implied. See the License for the

- * specific language governing permissions and limitations

- * under the License.

- */

-

-//Node client test for the following I/O stack:

-//    TJSONProtocol

-//    TBufferedTransport

-//    TSocket

-

-var assert = require('assert');

-var thrift = require('thrift');

-var TFramedTransport = require('thrift/transport').TFramedTransport;

-var TJSONProtocol = require('thrift/protocol').TJSONProtocol;

-var ThriftTest = require('./gen-nodejs/ThriftTest');

-var ThriftTestDriver = require('./thrift_test_driver').ThriftTestDriver;

-

-var connection = thrift.createConnection('localhost', 9090, 

-	                { protocol: TJSONProtocol, transport: TFramedTransport} );

-var client = thrift.createClient(ThriftTest, connection);

-

-connection.on('error', function(err) {

-  assert(false, err);

-});

-

-ThriftTestDriver(client, function (status) {

-  console.log(status);

-  connection.end();

-});

-

-// to make it also run on expresso

-exports.expressoTest = function() {};

-

diff --git a/test/nodejs/multiplex_server.js b/test/nodejs/multiplex_server.js
deleted file mode 100644
index 6b2d7d3..0000000
--- a/test/nodejs/multiplex_server.js
+++ /dev/null
@@ -1,242 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * 'License'); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * 'AS IS' BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-var thrift = require('thrift');
-var Thrift = thrift.Thrift;
-var ttransport = require('transport');
-
-var ThriftTest = require('./gen-nodejs/ThriftTest'),
-    SecondService = require('./gen-nodejs/SecondService'),
-    ttypes = require('./gen-nodejs/ThriftTest_types');
-
-var ThriftTestHandler = {
-    testVoid: function(result) {
-        console.log('testVoid()');
-        result(null);
-    },
-
-    testString: function(thing, result) {
-        console.log('testString(\'' + thing + '\')');
-        result(null, thing);
-    },
-
-    testByte: function(thing, result) {
-        console.log('testByte(' + thing + ')');
-        result(null, thing);
-    },
-
-    testI32: function(thing, result) {
-        console.log('testI32(' + thing + ')');
-        result(null, thing);
-    },
-
-    testI64: function(thing, result) {
-        console.log('testI64(' + thing + ')');
-        result(null, thing);
-    },
-
-    testDouble: function(thing, result) {
-        console.log('testDouble(' + thing + ')');
-        result(null, thing);
-    },
-
-    testStruct: function(thing, result) {
-        console.log('testStruct(');
-        console.log(thing);
-        console.log(')');
-        result(null, thing);
-    },
-
-    testNest: function(nest, result) {
-        console.log('testNest(');
-        console.log(nest);
-        console.log(')');
-        result(null, nest);
-    },
-
-    testMap: function(thing, result) {
-        console.log('testMap(');
-        console.log(thing);
-        console.log(')');
-        result(null, thing);
-    },
-
-    testStringMap: function(thing, result) {
-        console.log('testStringMap(');
-        console.log(thing);
-        console.log(')');
-        result(null, thing);
-    },
-
-    testSet: function(thing, result) {
-        console.log('testSet(');
-        console.log(thing);
-        console.log(')');
-        result(null, thing);
-    },
-
-    testList: function(thing, result) {
-        console.log('testList(');
-        console.log(thing);
-        console.log(')');
-        result(null, thing);
-    },
-
-    testEnum: function(thing, result) {
-        console.log('testEnum(' + thing + ')');
-        result(null, thing);
-    },
-
-    testTypedef: function(thing, result) {
-        console.log('testTypedef(' + thing + ')');
-        result(null, thing);
-    },
-
-    testMapMap: function(hello, result) {
-        console.log('testMapMap(' + hello + ')');
-
-        var mapmap = [];
-        var pos = [];
-        var neg = [];
-        for (var i = 1; i < 5; i++) {
-            pos[i] = i;
-            neg[-i] = -i;
-        }
-        mapmap[4] = pos;
-        mapmap[-4] = neg;
-
-        result(null, mapmap);
-    },
-
-    testInsanity: function(argument, result) {
-        console.log('testInsanity(');
-        console.log(argument);
-        console.log(')');
-
-        var hello = new ttypes.Xtruct();
-        hello.string_thing = 'Hello2';
-        hello.byte_thing = 2;
-        hello.i32_thing = 2;
-        hello.i64_thing = 2;
-
-        var goodbye = new ttypes.Xtruct();
-        goodbye.string_thing = 'Goodbye4';
-        goodbye.byte_thing = 4;
-        goodbye.i32_thing = 4;
-        goodbye.i64_thing = 4;
-
-        var crazy = new ttypes.Insanity();
-        crazy.userMap = [];
-        crazy.userMap[ttypes.Numberz.EIGHT] = 8;
-        crazy.userMap[ttypes.Numberz.FIVE] = 5;
-        crazy.xtructs = [goodbye, hello];
-
-        var first_map = [];
-        var second_map = [];
-
-        first_map[ttypes.Numberz.TWO] = crazy;
-        first_map[ttypes.Numberz.THREE] = crazy;
-
-        var looney = new ttypes.Insanity();
-        second_map[ttypes.Numberz.SIX] = looney;
-
-        var insane = [];
-        insane[1] = first_map;
-        insane[2] = second_map;
-
-        console.log('insane result:');
-        console.log(insane);
-        result(null, insane);
-    },
-
-    testMulti: function(arg0, arg1, arg2, arg3, arg4, arg5, result) {
-        console.log('testMulti()');
-
-        var hello = new ttypes.Xtruct();;
-        hello.string_thing = 'Hello2';
-        hello.byte_thing = arg0;
-        hello.i32_thing = arg1;
-        hello.i64_thing = arg2;
-        result(null, hello);
-    },
-
-    testException: function(arg, result) {
-        console.log('testException(' + arg + ')');
-        if (arg === 'Xception') {
-            var x = new ttypes.Xception();
-            x.errorCode = 1001;
-            x.message = arg;
-            result(x);
-        } else if (arg === 'TException') {
-            result(new Thrift.TException(arg));
-        } else {
-            result(null);
-        }
-    },
-
-    testMultiException: function(arg0, arg1, result) {
-        console.log('testMultiException(' + arg0 + ', ' + arg1 + ')');
-        if (arg0 === ('Xception')) {
-            var x = new ttypes.Xception();
-            x.errorCode = 1001;
-            x.message = 'This is an Xception';
-            result(x);
-        } else if (arg0 === ('Xception2')) {
-            var x = new ttypes.Xception2();
-            x.errorCode = 2002;
-            x.struct_thing = new ttypes.Xtruct();
-            x.struct_thing.string_thing = 'This is an Xception2';
-            result(x);
-        }
-
-        var res = new ttypes.Xtruct();
-        res.string_thing = arg1;
-        result(null, res);
-    },
-
-    testOneway: function(sleepFor, result) {
-        console.log('testOneway(' + sleepFor + ') => sleeping...');
-        setTimeout(function() {
-            console.log('Done sleeping for testOneway!');
-        }, sleepFor * 1000); //seconds
-    }
-};
-
-var SecondServiceHandler = {
-    secondtestString: function(thing, result) {
-        console.log('testString(\'' + thing + '\')');
-        result(null, thing);
-    }
-};
-
-var processor = new thrift.MultiplexedProcessor();
-
-processor.registerProcessor(
-    "ThriftTest",
-    new ThriftTest.Processor(ThriftTestHandler));
-
-processor.registerProcessor(
-    "SecondService",
-    new SecondService.Processor(SecondServiceHandler));
-
-
-var server = thrift.createMultiplexServer(processor, { //server options
-    'transport': ttransport.TFramedTransport
-});
-
-server.listen(9090);
diff --git a/test/nodejs/package.json b/test/nodejs/package.json
deleted file mode 100755
index 85adef1..0000000
--- a/test/nodejs/package.json
+++ /dev/null
@@ -1,30 +0,0 @@
-{
-  "name": "thrift-nodejs-test",
-  "version": "1.0.0-dev",
-  "description": "node.js test server and client for the Apache Thrift",
-  "homepage": "http://thrift.apache.org/",
-  "repository":
-    { "type" : "git",
-      "url" : "https://git-wip-us.apache.org/repos/asf/thrift.git"
-    },
-  "author":
-    { "name": "Apache Thrift Developers",
-      "email": "dev@thrift.apache.org",
-      "url": "http://thrift.apache.org"
-    },
-  "licenses":
-    [ { "type": "Apache-2.0",
-        "url": "http://www.apache.org/licenses/LICENSE-2.0"
-      }
-    ],
-  "bugs":
-    { "mail": "dev@thrift.apache.org",
-      "url": "https://issues.apache.org/jira/browse/THRIFT"
-    },
-  "directories" : { "lib" : "../lib/nodejs/lib/thrift" },
-  "main": "../lib/nodejs/lib/thrift",
-  "scripts": {
-    "start": "node ./http-server"
-  },
-  "engines": { "node": ">= 0.2.4" }
-}
diff --git a/test/nodejs/server.js b/test/nodejs/server.js
deleted file mode 100644
index 78a21c6..0000000
--- a/test/nodejs/server.js
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * 'License'); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * 'AS IS' BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-//Server test for the following I/O stack:
-//    TBinaryProtocol
-//    TFramedTransport
-//    TSocket
-
-var thrift = require('thrift');
-var TFramedTransport = require('thrift/transport').TFramedTransport;
-var ThriftTest = require('./gen-nodejs/ThriftTest');
-var ThriftTestHandler = require('./test_handler').ThriftTestHandler;
-
-thrift.createServer(ThriftTest, 
-                    ThriftTestHandler, 
-                    {'transport': TFramedTransport}).listen(9090);
-
diff --git a/test/nodejs/server_bin.js b/test/nodejs/server_bin.js
deleted file mode 100644
index ba84449..0000000
--- a/test/nodejs/server_bin.js
+++ /dev/null
@@ -1,38 +0,0 @@
-/*

- * Licensed to the Apache Software Foundation (ASF) under one

- * or more contributor license agreements. See the NOTICE file

- * distributed with this work for additional information

- * regarding copyright ownership. The ASF licenses this file

- * to you under the Apache License, Version 2.0 (the

- * 'License'); you may not use this file except in compliance

- * with the License. You may obtain a copy of the License at

- *

- *   http://www.apache.org/licenses/LICENSE-2.0

- *

- * Unless required by applicable law or agreed to in writing,

- * software distributed under the License is distributed on an

- * 'AS IS' BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY

- * KIND, either express or implied. See the License for the

- * specific language governing permissions and limitations

- * under the License.

- */

-

-//Node server test for the following I/O stack:

-//    TJSONProtocol

-//    TBufferedTransport

-//    TSocket

-

-var thrift = require('thrift');

-var TBufferedTransport = require('thrift/transport').TBufferedTransport;

-var TBinaryProtocol = require('thrift/protocol').TBinaryProtocol;

-var ThriftTestSvc = require('./gen-nodejs/ThriftTest');

-var ThriftTestHandler = require('./test_handler').ThriftTestHandler;

-

-var ThriftTestSvcOpt = {

-  transport: TBufferedTransport,

-  protocol: TBinaryProtocol

-};

-

-thrift.createServer(ThriftTestSvc, 

-                    ThriftTestHandler, 

-                    ThriftTestSvcOpt).listen(9090);

diff --git a/test/nodejs/server_json.js b/test/nodejs/server_json.js
deleted file mode 100644
index 406c982..0000000
--- a/test/nodejs/server_json.js
+++ /dev/null
@@ -1,38 +0,0 @@
-/*

- * Licensed to the Apache Software Foundation (ASF) under one

- * or more contributor license agreements. See the NOTICE file

- * distributed with this work for additional information

- * regarding copyright ownership. The ASF licenses this file

- * to you under the Apache License, Version 2.0 (the

- * 'License'); you may not use this file except in compliance

- * with the License. You may obtain a copy of the License at

- *

- *   http://www.apache.org/licenses/LICENSE-2.0

- *

- * Unless required by applicable law or agreed to in writing,

- * software distributed under the License is distributed on an

- * 'AS IS' BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY

- * KIND, either express or implied. See the License for the

- * specific language governing permissions and limitations

- * under the License.

- */

-

-//Node server test for the following I/O stack:

-//    TJSONProtocol

-//    TBufferedTransport

-//    TSocket

-

-var thrift = require('thrift');

-var TBufferedTransport = require('thrift/transport').TBufferedTransport;

-var TJSONProtocol = require('thrift/protocol').TJSONProtocol;

-var ThriftTestSvc = require('./gen-nodejs/ThriftTest');

-var ThriftTestHandler = require('./test_handler').ThriftTestHandler;

-

-var ThriftTestSvcOpt = {

-  transport: TBufferedTransport,

-  protocol: TJSONProtocol

-};

-

-thrift.createServer(ThriftTestSvc, 

-                    ThriftTestHandler, 

-                    ThriftTestSvcOpt).listen(9090);

diff --git a/test/nodejs/server_json_frame.js b/test/nodejs/server_json_frame.js
deleted file mode 100644
index 828063a..0000000
--- a/test/nodejs/server_json_frame.js
+++ /dev/null
@@ -1,38 +0,0 @@
-/*

- * Licensed to the Apache Software Foundation (ASF) under one

- * or more contributor license agreements. See the NOTICE file

- * distributed with this work for additional information

- * regarding copyright ownership. The ASF licenses this file

- * to you under the Apache License, Version 2.0 (the

- * 'License'); you may not use this file except in compliance

- * with the License. You may obtain a copy of the License at

- *

- *   http://www.apache.org/licenses/LICENSE-2.0

- *

- * Unless required by applicable law or agreed to in writing,

- * software distributed under the License is distributed on an

- * 'AS IS' BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY

- * KIND, either express or implied. See the License for the

- * specific language governing permissions and limitations

- * under the License.

- */

-

-//Node server test for the following I/O stack:

-//    TJSONProtocol

-//    TBufferedTransport

-//    TSocket

-

-var thrift = require('thrift');

-var TFramedTransport = require('thrift/transport').TFramedTransport;

-var TJSONProtocol = require('thrift/protocol').TJSONProtocol;

-var ThriftTestSvc = require('./gen-nodejs/ThriftTest');

-var ThriftTestHandler = require('./test_handler').ThriftTestHandler;

-

-var ThriftTestSvcOpt = {

-  transport: TFramedTransport,

-  protocol: TJSONProtocol

-};

-

-thrift.createServer(ThriftTestSvc, 

-                    ThriftTestHandler, 

-                    ThriftTestSvcOpt).listen(9090);

diff --git a/test/test.sh b/test/test.sh
index 520a632..5170e13 100755
--- a/test/test.sh
+++ b/test/test.sh
@@ -101,6 +101,9 @@
 java_sockets="ip ip-ssl"
 # TODO fastframed java transport is another implementation of framed transport
 
+nodejs_protocols="binary json"
+nodejs_transports="buffered framed"
+nodejs_sockets="ip"
 
 ant -f ../lib/java/build.xml compile-test 1>/dev/null
 
@@ -170,6 +173,34 @@
   done
 done
 
+
+NODE_TEST_DIR=${BASEDIR}/../bin/nodejs/tests
+export NODE_PATH=${NODE_TEST_DIR}:${NODE_TEST_DIR}/../lib:${NODE_PATH}
+######### nodejs client - cpp server ##############
+##
+for proto in $(intersection "${nodejs_protocols}" "${cpp_protocols}"); do
+  for trans in $(intersection "${nodejs_transports}" "${cpp_transports}"); do
+    for sock in $(intersection "${nodejs_sockets}" "${cpp_sockets}"); do
+      do_test "nodejs-cpp" "${proto}" "${trans}-ip" \
+              "nodejs ${NODE_TEST_DIR}/client.js -p ${proto} -t ${trans}" \
+              "cpp/TestServer --protocol=${proto} --transport=${trans} ${extraparam}" \
+              "10" "10"
+    done
+  done
+done
+
+######### cpp client - nodejs server ##############
+for proto in $(intersection "${nodejs_protocols}" "${cpp_protocols}"); do
+  for trans in $(intersection "${nodejs_transports}" "${cpp_transports}"); do
+    for sock in $(intersection "${nodejs_sockets}" "${cpp_sockets}"); do
+      do_test "cpp-nodejs" "${proto}" "${trans}-ip" \
+              "cpp/TestClient --protocol=${proto} --transport=${trans}" \
+              "nodejs ${NODE_TEST_DIR}/server.js -p ${proto} -t ${trans}" \
+              "10" "10"
+    done
+  done
+done
+
 # delete Unix Domain Socket used by cpp tests
 rm -f /tmp/ThriftTest.thrift
 
@@ -221,18 +252,6 @@
         "make -C php/ client" \
         "cpp/TestServer" \
         "10" "10"
-do_test "nodejs-nodejs" "binary" "framed-ip" \
-        "make -C nodejs/ client" \
-        "make -C nodejs/ server" \
-        "1" "5"
-do_test "nodejs-cpp" "binary" "framed-ip" \
-        "make -C nodejs/ client" \
-        "cpp/TestServer --transport=framed" \
-        "1" "10"
-do_test "cpp-nodejs" "binary" "framed-ip" \
-        "cpp/TestClient --transport=framed" \
-        "make -C nodejs/ server" \
-        "1" "5"
 do_test "rb-rb" "binary" "buffered-ip" \
         "ruby rb/integration/simple_client.rb" \
         "ruby rb/integration/simple_server.rb" \