summaryrefslogtreecommitdiff
path: root/lib/nodejs
diff options
context:
space:
mode:
authorbforbis <bpforbis@gmail.com>2018-10-28 11:27:38 -0400
committerJames E. King III <jking@apache.org>2018-10-28 11:27:38 -0400
commitda1169d75b154e48871851ea8d731fccb0876fe7 (patch)
tree6e74de09281e72039d2f7248d6e6349f2ca5f236 /lib/nodejs
parentcd829a0b9a5c66203b63350fa029589669ec43f6 (diff)
downloadthrift-da1169d75b154e48871851ea8d731fccb0876fe7.tar.gz
THRIFT-4653: ES6 classes support (#1615)
* ES6 classes support * Lint generated code * ES6 Tests for NodeJS * Add eslint rules for nodejs * Run prettier/eslint on nodejs test code
Diffstat (limited to 'lib/nodejs')
-rwxr-xr-xlib/nodejs/Makefile.am3
-rw-r--r--lib/nodejs/test/binary.test.js159
-rw-r--r--lib/nodejs/test/client.js140
-rw-r--r--lib/nodejs/test/deep-constructor.test.js322
-rw-r--r--lib/nodejs/test/exceptions.js166
-rw-r--r--lib/nodejs/test/helpers.js19
-rw-r--r--lib/nodejs/test/server.js121
-rw-r--r--lib/nodejs/test/test-cases.js229
-rwxr-xr-xlib/nodejs/test/testAll.sh24
-rw-r--r--lib/nodejs/test/test_driver.js403
-rw-r--r--lib/nodejs/test/test_handler.js129
11 files changed, 973 insertions, 742 deletions
diff --git a/lib/nodejs/Makefile.am b/lib/nodejs/Makefile.am
index 9a7b4eb2c..68ea3ea48 100755
--- a/lib/nodejs/Makefile.am
+++ b/lib/nodejs/Makefile.am
@@ -27,8 +27,9 @@ all-local: deps
precross: deps stubs
+# TODO: Lint nodejs lib and gen-code as part of build
check: deps
- cd $(top_srcdir) && $(NPM) test && cd lib/nodejs
+ cd $(top_srcdir) && $(NPM) test && $(NPM) run lint-tests && cd lib/nodejs
clean-local:
$(RM) -r test/gen-nodejs
diff --git a/lib/nodejs/test/binary.test.js b/lib/nodejs/test/binary.test.js
index 38ba63411..187cd1874 100644
--- a/lib/nodejs/test/binary.test.js
+++ b/lib/nodejs/test/binary.test.js
@@ -17,19 +17,19 @@
* under the License.
*/
-var test = require('tape');
-var binary = require('thrift/binary');
+const test = require("tape");
+const binary = require("thrift/binary");
-var cases = {
- "Should read signed byte": function(assert){
+const cases = {
+ "Should read signed byte": function(assert) {
assert.equal(1, binary.readByte(0x01));
- assert.equal(-1, binary.readByte(0xFF));
+ assert.equal(-1, binary.readByte(0xff));
- assert.equal(127, binary.readByte(0x7F));
+ assert.equal(127, binary.readByte(0x7f));
assert.equal(-128, binary.readByte(0x80));
assert.end();
},
- "Should write byte": function(assert){
+ "Should write byte": function(assert) {
//Protocol simply writes to the buffer. Nothing to test.. yet.
assert.ok(true);
assert.end();
@@ -76,58 +76,135 @@ var cases = {
assert.deepEqual([0xff, 0xff, 0xff, 0xff], binary.writeI32([], -1));
// Min I32
- assert.deepEqual([0x80, 0x00, 0x00, 0x00], binary.writeI32([], -2147483648));
+ assert.deepEqual(
+ [0x80, 0x00, 0x00, 0x00],
+ binary.writeI32([], -2147483648)
+ );
// Max I32
assert.deepEqual([0x7f, 0xff, 0xff, 0xff], binary.writeI32([], 2147483647));
assert.end();
},
"Should read doubles": function(assert) {
- assert.equal(0, binary.readDouble([0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]))
- assert.equal(0, binary.readDouble([0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]))
- assert.equal(1, binary.readDouble([0x3f, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]))
- assert.equal(2, binary.readDouble([0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]))
- assert.equal(-2, binary.readDouble([0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]))
-
- assert.equal(Math.PI, binary.readDouble([0x40, 0x9, 0x21, 0xfb, 0x54, 0x44, 0x2d, 0x18]))
-
- assert.equal(Infinity, binary.readDouble([0x7f, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]))
- assert.equal(-Infinity, binary.readDouble([0xff, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]))
-
- assert.ok(isNaN(binary.readDouble([0x7f, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00])))
-
- assert.equal(1/3, binary.readDouble([0x3f, 0xd5, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55]))
+ assert.equal(
+ 0,
+ binary.readDouble([0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00])
+ );
+ assert.equal(
+ 0,
+ binary.readDouble([0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00])
+ );
+ assert.equal(
+ 1,
+ binary.readDouble([0x3f, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00])
+ );
+ assert.equal(
+ 2,
+ binary.readDouble([0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00])
+ );
+ assert.equal(
+ -2,
+ binary.readDouble([0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00])
+ );
+
+ assert.equal(
+ Math.PI,
+ binary.readDouble([0x40, 0x9, 0x21, 0xfb, 0x54, 0x44, 0x2d, 0x18])
+ );
+
+ assert.equal(
+ Infinity,
+ binary.readDouble([0x7f, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00])
+ );
+ assert.equal(
+ -Infinity,
+ binary.readDouble([0xff, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00])
+ );
+
+ assert.ok(
+ isNaN(binary.readDouble([0x7f, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]))
+ );
+
+ assert.equal(
+ 1 / 3,
+ binary.readDouble([0x3f, 0xd5, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55])
+ );
// Min subnormal positive double
- assert.equal(4.9406564584124654e-324, binary.readDouble([0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01]))
+ assert.equal(
+ 4.9406564584124654e-324,
+ binary.readDouble([0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01])
+ );
// Min normal positive double
- assert.equal(2.2250738585072014e-308, binary.readDouble([0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]))
+ assert.equal(
+ 2.2250738585072014e-308,
+ binary.readDouble([0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00])
+ );
// Max positive double
- assert.equal(1.7976931348623157e308, binary.readDouble([0x7f, 0xef, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff]))
+ assert.equal(
+ 1.7976931348623157e308,
+ binary.readDouble([0x7f, 0xef, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff])
+ );
assert.end();
},
"Should write doubles": function(assert) {
- assert.deepEqual([0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], binary.writeDouble([], 0));
- assert.deepEqual([0x3f, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], binary.writeDouble([], 1));
- assert.deepEqual([0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], binary.writeDouble([], 2));
- assert.deepEqual([0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], binary.writeDouble([], -2));
-
- assert.deepEqual([0x40, 0x9, 0x21, 0xfb, 0x54, 0x44, 0x2d, 0x18], binary.writeDouble([], Math.PI));
-
- assert.deepEqual([0x7f, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], binary.writeDouble([], Infinity));
- assert.deepEqual([0xff, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], binary.writeDouble([], -Infinity));
-
- assert.deepEqual([0x7f, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], binary.writeDouble([], NaN));
-
- assert.deepEqual([0x3f, 0xd5, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55], binary.writeDouble([], 1/3));
+ assert.deepEqual(
+ [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00],
+ binary.writeDouble([], 0)
+ );
+ assert.deepEqual(
+ [0x3f, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00],
+ binary.writeDouble([], 1)
+ );
+ assert.deepEqual(
+ [0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00],
+ binary.writeDouble([], 2)
+ );
+ assert.deepEqual(
+ [0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00],
+ binary.writeDouble([], -2)
+ );
+
+ assert.deepEqual(
+ [0x40, 0x9, 0x21, 0xfb, 0x54, 0x44, 0x2d, 0x18],
+ binary.writeDouble([], Math.PI)
+ );
+
+ assert.deepEqual(
+ [0x7f, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00],
+ binary.writeDouble([], Infinity)
+ );
+ assert.deepEqual(
+ [0xff, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00],
+ binary.writeDouble([], -Infinity)
+ );
+
+ assert.deepEqual(
+ [0x7f, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00],
+ binary.writeDouble([], NaN)
+ );
+
+ assert.deepEqual(
+ [0x3f, 0xd5, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55],
+ binary.writeDouble([], 1 / 3)
+ );
// Min subnormal positive double
- assert.deepEqual([0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01], binary.writeDouble([], 4.9406564584124654e-324));
+ assert.deepEqual(
+ [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01],
+ binary.writeDouble([], 4.9406564584124654e-324)
+ );
// Min normal positive double
- assert.deepEqual([0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], binary.writeDouble([], 2.2250738585072014e-308));
+ assert.deepEqual(
+ [0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00],
+ binary.writeDouble([], 2.2250738585072014e-308)
+ );
// Max positive double
- assert.deepEqual([0x7f, 0xef, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff], binary.writeDouble([], 1.7976931348623157e308));
+ assert.deepEqual(
+ [0x7f, 0xef, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff],
+ binary.writeDouble([], 1.7976931348623157e308)
+ );
assert.end();
}
};
diff --git a/lib/nodejs/test/client.js b/lib/nodejs/test/client.js
index 55839f616..49e3a5ec9 100644
--- a/lib/nodejs/test/client.js
+++ b/lib/nodejs/test/client.js
@@ -19,125 +19,149 @@
* under the License.
*/
-var fs = require('fs');
-var assert = require('assert');
-var thrift = require('thrift');
-var helpers = require('./helpers');
-var ThriftTest = require('./gen-nodejs/ThriftTest');
-var ThriftTestDriver = require('./test_driver').ThriftTestDriver;
-var ThriftTestDriverPromise = require('./test_driver').ThriftTestDriverPromise;
-var SecondService = require('./gen-nodejs/SecondService');
-var ttypes = require('./gen-nodejs/ThriftTest_types');
-
-var program = require('commander');
+const assert = require("assert");
+const thrift = require("thrift");
+const helpers = require("./helpers");
+
+const ThriftTest = require(`./${helpers.genPath}/ThriftTest`);
+const ThriftTestDriver = require("./test_driver").ThriftTestDriver;
+const ThriftTestDriverPromise = require("./test_driver")
+ .ThriftTestDriverPromise;
+const SecondService = require(`./${helpers.genPath}/SecondService`);
+
+const program = require("commander");
program
- .option('-p, --protocol <protocol>', 'Set thrift protocol (binary|compact|json) [protocol]')
- .option('-t, --transport <transport>', 'Set thrift transport (buffered|framed|http) [transport]')
- .option('--port <port>', 'Set thrift server port number to connect', 9090)
- .option('--host <host>', 'Set thrift server host to connect', 'localhost')
- .option('--domain-socket <path>', 'Set thrift server unix domain socket to connect')
- .option('--ssl', 'use SSL transport')
- .option('--promise', 'test with promise style functions')
- .option('-t, --type <type>', 'Select server type (http|multiplex|tcp|websocket)', 'tcp')
+ .option(
+ "-p, --protocol <protocol>",
+ "Set thrift protocol (binary|compact|json) [protocol]"
+ )
+ .option(
+ "-t, --transport <transport>",
+ "Set thrift transport (buffered|framed|http) [transport]"
+ )
+ .option("--port <port>", "Set thrift server port number to connect", 9090)
+ .option("--host <host>", "Set thrift server host to connect", "localhost")
+ .option(
+ "--domain-socket <path>",
+ "Set thrift server unix domain socket to connect"
+ )
+ .option("--ssl", "use SSL transport")
+ .option("--callback", "test with callback style functions")
+ .option(
+ "-t, --type <type>",
+ "Select server type (http|multiplex|tcp|websocket)",
+ "tcp"
+ )
+ .option("--es6", "Use es6 code")
+ .option("--es5", "Use es5 code")
.parse(process.argv);
-var host = program.host;
-var port = program.port;
-var domainSocket = program.domainSocket;
-var type = program.type;
-var ssl = program.ssl;
-var promise = program.promise;
+const host = program.host;
+const port = program.port;
+const domainSocket = program.domainSocket;
+const ssl = program.ssl;
+let type = program.type;
/* for compatibility with cross test invocation for http transport testing */
-if (program.transport === 'http') {
- program.transport = 'buffered';
- type = 'http';
+if (program.transport === "http") {
+ program.transport = "buffered";
+ type = "http";
}
-var options = {
+const options = {
transport: helpers.transports[program.transport],
protocol: helpers.protocols[program.protocol]
};
-if (type === 'http' || type === 'websocket') {
- options.path = '/test';
+if (type === "http" || type === "websocket") {
+ options.path = "/test";
}
-if (type === 'http') {
- options.headers = {"Connection": "close"};
+if (type === "http") {
+ options.headers = { Connection: "close" };
}
if (ssl) {
- if (type === 'tcp' || type === 'multiplex') {
+ if (type === "tcp" || type === "multiplex") {
options.rejectUnauthorized = false;
- } else if (type === 'http') {
+ } else if (type === "http") {
options.nodeOptions = { rejectUnauthorized: false };
options.https = true;
- } else if (type === 'websocket') {
+ } else if (type === "websocket") {
options.wsOptions = { rejectUnauthorized: false };
options.secure = true;
}
}
-var connection;
-var client;
-var testDriver = promise ? ThriftTestDriverPromise : ThriftTestDriver;
+let connection;
+let client;
+const testDriver = program.callback
+ ? ThriftTestDriver
+ : ThriftTestDriverPromise;
+if (helpers.ecmaMode === "es6" && program.callback) {
+ console.log("ES6 does not support callback style");
+ process.exit(0);
+}
-if (type === 'tcp' || type === 'multiplex') {
+if (type === "tcp" || type === "multiplex") {
if (domainSocket) {
connection = thrift.createUDSConnection(domainSocket, options);
} else {
- connection = ssl ?
- thrift.createSSLConnection(host, port, options) :
- thrift.createConnection(host, port, options);
+ connection = ssl
+ ? thrift.createSSLConnection(host, port, options)
+ : thrift.createConnection(host, port, options);
}
-} else if (type === 'http') {
+} else if (type === "http") {
if (domainSocket) {
connection = thrift.createHttpUDSConnection(domainSocket, options);
} else {
connection = thrift.createHttpConnection(host, port, options);
}
-} else if (type === 'websocket') {
+} else if (type === "websocket") {
connection = thrift.createWSConnection(host, port, options);
connection.open();
}
-connection.on('error', function(err) {
- assert(false, err);
+connection.on("error", function(err) {
+ assert(false, err);
});
-if (type === 'tcp') {
+if (type === "tcp") {
client = thrift.createClient(ThriftTest, connection);
runTests();
-} else if (type === 'multiplex') {
- var mp = new thrift.Multiplexer();
+} else if (type === "multiplex") {
+ const mp = new thrift.Multiplexer();
client = mp.createClient("ThriftTest", ThriftTest, connection);
- secondclient = mp.createClient("SecondService", SecondService, connection);
+ const secondclient = mp.createClient(
+ "SecondService",
+ SecondService,
+ connection
+ );
- connection.on('connect', function() {
+ connection.on("connect", function() {
secondclient.secondtestString("Test", function(err, response) {
assert(!err);
- assert.equal("testString(\"Test\")", response);
+ assert.equal('testString("Test")', response);
});
runTests();
});
-} else if (type === 'http') {
+} else if (type === "http") {
client = thrift.createHttpClient(ThriftTest, connection);
runTests();
-} else if (type === 'websocket') {
+} else if (type === "websocket") {
client = thrift.createWSClient(ThriftTest, connection);
runTests();
}
function runTests() {
- testDriver(client, function (status) {
+ testDriver(client, function(status) {
console.log(status);
- if (type !== 'http' && type !== 'websocket') {
+ if (type !== "http" && type !== "websocket") {
connection.end();
}
- if (type !== 'multiplex') {
+ if (type !== "multiplex") {
process.exit(0);
}
});
diff --git a/lib/nodejs/test/deep-constructor.test.js b/lib/nodejs/test/deep-constructor.test.js
index 145b66875..504dacf0b 100644
--- a/lib/nodejs/test/deep-constructor.test.js
+++ b/lib/nodejs/test/deep-constructor.test.js
@@ -17,39 +17,36 @@
* under the License.
*/
-var ttypes = require('./gen-nodejs/JsDeepConstructorTest_types');
-var thrift = require('thrift');
-var test = require('tape');
-var bufferEquals = require('buffer-equals');
+const ttypes = require("./gen-nodejs/JsDeepConstructorTest_types");
+const thrift = require("thrift");
+const test = require("tape");
+const bufferEquals = require("buffer-equals");
function serializeBinary(data) {
- var buff;
- var transport = new thrift.TBufferedTransport(null, function(msg){
+ let buff;
+ const transport = new thrift.TBufferedTransport(null, function(msg) {
buff = msg;
});
- var prot = new thrift.TBinaryProtocol(transport);
+ const prot = new thrift.TBinaryProtocol(transport);
data.write(prot);
prot.flush();
return buff;
-
}
-
function deserializeBinary(serialized, type) {
- var t = new thrift.TFramedTransport(serialized);
- var p = new thrift.TBinaryProtocol(t);
- var data = new type();
+ const t = new thrift.TFramedTransport(serialized);
+ const p = new thrift.TBinaryProtocol(t);
+ const data = new type();
data.read(p);
return data;
}
-
function serializeJSON(data) {
- var buff;
- var transport = new thrift.TBufferedTransport(null, function(msg){
+ let buff;
+ const transport = new thrift.TBufferedTransport(null, function(msg) {
buff = msg;
});
- var protocol = new thrift.TJSONProtocol(transport);
+ const protocol = new thrift.TJSONProtocol(transport);
protocol.writeMessageBegin("", 0, 0);
data.write(protocol);
protocol.writeMessageEnd();
@@ -57,45 +54,41 @@ function serializeJSON(data) {
return buff;
}
-
function deserializeJSON(serialized, type) {
- var transport = new thrift.TFramedTransport(serialized);
- var protocol = new thrift.TJSONProtocol(transport);
+ const transport = new thrift.TFramedTransport(serialized);
+ const protocol = new thrift.TJSONProtocol(transport);
protocol.readMessageBegin();
- var data = new type();
+ const data = new type();
data.read(protocol);
protocol.readMessageEnd();
return data;
}
-
function createThriftObj() {
-
return new ttypes.Complex({
-
- struct_field: new ttypes.Simple({value: 'a'}),
+ struct_field: new ttypes.Simple({ value: "a" }),
struct_list_field: [
- new ttypes.Simple({value: 'b'}),
- new ttypes.Simple({value: 'c'}),
+ new ttypes.Simple({ value: "b" }),
+ new ttypes.Simple({ value: "c" })
],
struct_set_field: [
- new ttypes.Simple({value: 'd'}),
- new ttypes.Simple({value: 'e'}),
+ new ttypes.Simple({ value: "d" }),
+ new ttypes.Simple({ value: "e" })
],
struct_map_field: {
- A: new ttypes.Simple({value: 'f'}),
- B: new ttypes.Simple({value: 'g'})
+ A: new ttypes.Simple({ value: "f" }),
+ B: new ttypes.Simple({ value: "g" })
},
struct_nested_containers_field: [
[
{
C: [
- new ttypes.Simple({value: 'h'}),
- new ttypes.Simple({value: 'i'})
+ new ttypes.Simple({ value: "h" }),
+ new ttypes.Simple({ value: "i" })
]
}
]
@@ -104,59 +97,57 @@ function createThriftObj() {
struct_nested_containers_field2: {
D: [
{
- DA: new ttypes.Simple({value: 'j'})
+ DA: new ttypes.Simple({ value: "j" })
},
{
- DB: new ttypes.Simple({value: 'k'})
+ DB: new ttypes.Simple({ value: "k" })
}
]
},
list_of_list_field: [
- ['l00', 'l01', 'l02'],
- ['l10', 'l11', 'l12'],
- ['l20', 'l21', 'l22'],
+ ["l00", "l01", "l02"],
+ ["l10", "l11", "l12"],
+ ["l20", "l21", "l22"]
],
list_of_list_of_list_field: [
- [['m000', 'm001', 'm002'], ['m010', 'm011', 'm012'], ['m020', 'm021', 'm022']],
- [['m100', 'm101', 'm102'], ['m110', 'm111', 'm112'], ['m120', 'm121', 'm122']],
- [['m200', 'm201', 'm202'], ['m210', 'm211', 'm212'], ['m220', 'm221', 'm222']],
- ],
-
-
+ [
+ ["m000", "m001", "m002"],
+ ["m010", "m011", "m012"],
+ ["m020", "m021", "m022"]
+ ],
+ [
+ ["m100", "m101", "m102"],
+ ["m110", "m111", "m112"],
+ ["m120", "m121", "m122"]
+ ],
+ [
+ ["m200", "m201", "m202"],
+ ["m210", "m211", "m212"],
+ ["m220", "m221", "m222"]
+ ]
+ ]
});
}
-
function createJsObj() {
-
return {
+ struct_field: { value: "a" },
- struct_field: {value: 'a'},
+ struct_list_field: [{ value: "b" }, { value: "c" }],
- struct_list_field: [
- {value: 'b'},
- {value: 'c'},
- ],
-
- struct_set_field: [
- {value: 'd'},
- {value: 'e'},
- ],
+ struct_set_field: [{ value: "d" }, { value: "e" }],
struct_map_field: {
- A: {value: 'f'},
- B: {value: 'g'}
+ A: { value: "f" },
+ B: { value: "g" }
},
struct_nested_containers_field: [
[
{
- C: [
- {value: 'h'},
- {value: 'i'}
- ]
+ C: [{ value: "h" }, { value: "i" }]
}
]
],
@@ -164,131 +155,142 @@ function createJsObj() {
struct_nested_containers_field2: {
D: [
{
- DA: {value: 'j'}
+ DA: { value: "j" }
},
{
- DB: {value: 'k'}
+ DB: { value: "k" }
}
]
},
list_of_list_field: [
- ['l00', 'l01', 'l02'],
- ['l10', 'l11', 'l12'],
- ['l20', 'l21', 'l22'],
+ ["l00", "l01", "l02"],
+ ["l10", "l11", "l12"],
+ ["l20", "l21", "l22"]
],
list_of_list_of_list_field: [
- [['m000', 'm001', 'm002'], ['m010', 'm011', 'm012'], ['m020', 'm021', 'm022']],
- [['m100', 'm101', 'm102'], ['m110', 'm111', 'm112'], ['m120', 'm121', 'm122']],
- [['m200', 'm201', 'm202'], ['m210', 'm211', 'm212'], ['m220', 'm221', 'm222']],
- ],
-
+ [
+ ["m000", "m001", "m002"],
+ ["m010", "m011", "m012"],
+ ["m020", "m021", "m022"]
+ ],
+ [
+ ["m100", "m101", "m102"],
+ ["m110", "m111", "m112"],
+ ["m120", "m121", "m122"]
+ ],
+ [
+ ["m200", "m201", "m202"],
+ ["m210", "m211", "m212"],
+ ["m220", "m221", "m222"]
+ ]
+ ]
};
}
-
function assertValues(obj, assert) {
- assert.equals(obj.struct_field.value, 'a');
- assert.equals(obj.struct_list_field[0].value, 'b');
- assert.equals(obj.struct_list_field[1].value, 'c');
- assert.equals(obj.struct_set_field[0].value, 'd');
- assert.equals(obj.struct_set_field[1].value, 'e');
- assert.equals(obj.struct_map_field.A.value, 'f');
- assert.equals(obj.struct_map_field.B.value, 'g');
- assert.equals(obj.struct_nested_containers_field[0][0].C[0].value, 'h');
- assert.equals(obj.struct_nested_containers_field[0][0].C[1].value, 'i');
- assert.equals(obj.struct_nested_containers_field2.D[0].DA.value, 'j');
- assert.equals(obj.struct_nested_containers_field2.D[1].DB.value, 'k');
- assert.equals(obj.list_of_list_field[0][0], 'l00');
- assert.equals(obj.list_of_list_field[0][1], 'l01');
- assert.equals(obj.list_of_list_field[0][2], 'l02');
- assert.equals(obj.list_of_list_field[1][0], 'l10');
- assert.equals(obj.list_of_list_field[1][1], 'l11');
- assert.equals(obj.list_of_list_field[1][2], 'l12');
- assert.equals(obj.list_of_list_field[2][0], 'l20');
- assert.equals(obj.list_of_list_field[2][1], 'l21');
- assert.equals(obj.list_of_list_field[2][2], 'l22');
-
- assert.equals(obj.list_of_list_of_list_field[0][0][0], 'm000');
- assert.equals(obj.list_of_list_of_list_field[0][0][1], 'm001');
- assert.equals(obj.list_of_list_of_list_field[0][0][2], 'm002');
- assert.equals(obj.list_of_list_of_list_field[0][1][0], 'm010');
- assert.equals(obj.list_of_list_of_list_field[0][1][1], 'm011');
- assert.equals(obj.list_of_list_of_list_field[0][1][2], 'm012');
- assert.equals(obj.list_of_list_of_list_field[0][2][0], 'm020');
- assert.equals(obj.list_of_list_of_list_field[0][2][1], 'm021');
- assert.equals(obj.list_of_list_of_list_field[0][2][2], 'm022');
-
- assert.equals(obj.list_of_list_of_list_field[1][0][0], 'm100');
- assert.equals(obj.list_of_list_of_list_field[1][0][1], 'm101');
- assert.equals(obj.list_of_list_of_list_field[1][0][2], 'm102');
- assert.equals(obj.list_of_list_of_list_field[1][1][0], 'm110');
- assert.equals(obj.list_of_list_of_list_field[1][1][1], 'm111');
- assert.equals(obj.list_of_list_of_list_field[1][1][2], 'm112');
- assert.equals(obj.list_of_list_of_list_field[1][2][0], 'm120');
- assert.equals(obj.list_of_list_of_list_field[1][2][1], 'm121');
- assert.equals(obj.list_of_list_of_list_field[1][2][2], 'm122');
-
- assert.equals(obj.list_of_list_of_list_field[2][0][0], 'm200');
- assert.equals(obj.list_of_list_of_list_field[2][0][1], 'm201');
- assert.equals(obj.list_of_list_of_list_field[2][0][2], 'm202');
- assert.equals(obj.list_of_list_of_list_field[2][1][0], 'm210');
- assert.equals(obj.list_of_list_of_list_field[2][1][1], 'm211');
- assert.equals(obj.list_of_list_of_list_field[2][1][2], 'm212');
- assert.equals(obj.list_of_list_of_list_field[2][2][0], 'm220');
- assert.equals(obj.list_of_list_of_list_field[2][2][1], 'm221');
- assert.equals(obj.list_of_list_of_list_field[2][2][2], 'm222');
+ assert.equals(obj.struct_field.value, "a");
+ assert.equals(obj.struct_list_field[0].value, "b");
+ assert.equals(obj.struct_list_field[1].value, "c");
+ assert.equals(obj.struct_set_field[0].value, "d");
+ assert.equals(obj.struct_set_field[1].value, "e");
+ assert.equals(obj.struct_map_field.A.value, "f");
+ assert.equals(obj.struct_map_field.B.value, "g");
+ assert.equals(obj.struct_nested_containers_field[0][0].C[0].value, "h");
+ assert.equals(obj.struct_nested_containers_field[0][0].C[1].value, "i");
+ assert.equals(obj.struct_nested_containers_field2.D[0].DA.value, "j");
+ assert.equals(obj.struct_nested_containers_field2.D[1].DB.value, "k");
+ assert.equals(obj.list_of_list_field[0][0], "l00");
+ assert.equals(obj.list_of_list_field[0][1], "l01");
+ assert.equals(obj.list_of_list_field[0][2], "l02");
+ assert.equals(obj.list_of_list_field[1][0], "l10");
+ assert.equals(obj.list_of_list_field[1][1], "l11");
+ assert.equals(obj.list_of_list_field[1][2], "l12");
+ assert.equals(obj.list_of_list_field[2][0], "l20");
+ assert.equals(obj.list_of_list_field[2][1], "l21");
+ assert.equals(obj.list_of_list_field[2][2], "l22");
+
+ assert.equals(obj.list_of_list_of_list_field[0][0][0], "m000");
+ assert.equals(obj.list_of_list_of_list_field[0][0][1], "m001");
+ assert.equals(obj.list_of_list_of_list_field[0][0][2], "m002");
+ assert.equals(obj.list_of_list_of_list_field[0][1][0], "m010");
+ assert.equals(obj.list_of_list_of_list_field[0][1][1], "m011");
+ assert.equals(obj.list_of_list_of_list_field[0][1][2], "m012");
+ assert.equals(obj.list_of_list_of_list_field[0][2][0], "m020");
+ assert.equals(obj.list_of_list_of_list_field[0][2][1], "m021");
+ assert.equals(obj.list_of_list_of_list_field[0][2][2], "m022");
+
+ assert.equals(obj.list_of_list_of_list_field[1][0][0], "m100");
+ assert.equals(obj.list_of_list_of_list_field[1][0][1], "m101");
+ assert.equals(obj.list_of_list_of_list_field[1][0][2], "m102");
+ assert.equals(obj.list_of_list_of_list_field[1][1][0], "m110");
+ assert.equals(obj.list_of_list_of_list_field[1][1][1], "m111");
+ assert.equals(obj.list_of_list_of_list_field[1][1][2], "m112");
+ assert.equals(obj.list_of_list_of_list_field[1][2][0], "m120");
+ assert.equals(obj.list_of_list_of_list_field[1][2][1], "m121");
+ assert.equals(obj.list_of_list_of_list_field[1][2][2], "m122");
+
+ assert.equals(obj.list_of_list_of_list_field[2][0][0], "m200");
+ assert.equals(obj.list_of_list_of_list_field[2][0][1], "m201");
+ assert.equals(obj.list_of_list_of_list_field[2][0][2], "m202");
+ assert.equals(obj.list_of_list_of_list_field[2][1][0], "m210");
+ assert.equals(obj.list_of_list_of_list_field[2][1][1], "m211");
+ assert.equals(obj.list_of_list_of_list_field[2][1][2], "m212");
+ assert.equals(obj.list_of_list_of_list_field[2][2][0], "m220");
+ assert.equals(obj.list_of_list_of_list_field[2][2][1], "m221");
+ assert.equals(obj.list_of_list_of_list_field[2][2][2], "m222");
}
function createTestCases(serialize, deserialize) {
-
- var cases = {
-
- "Serialize/deserialize should return equal object": function(assert){
- var tObj = createThriftObj();
- var received = deserialize(serialize(tObj), ttypes.Complex);
- assert.ok(tObj !== received, 'not the same object');
+ const cases = {
+ "Serialize/deserialize should return equal object": function(assert) {
+ const tObj = createThriftObj();
+ const received = deserialize(serialize(tObj), ttypes.Complex);
+ assert.ok(tObj !== received, "not the same object");
assert.deepEqual(tObj, received);
assert.end();
},
- "Nested structs and containers initialized from plain js objects should serialize same as if initialized from thrift objects": function(assert) {
- var tObj1 = createThriftObj();
- var tObj2 = new ttypes.Complex(createJsObj());
+ "Nested structs and containers initialized from plain js objects should serialize same as if initialized from thrift objects": function(
+ assert
+ ) {
+ const tObj1 = createThriftObj();
+ const tObj2 = new ttypes.Complex(createJsObj());
assertValues(tObj2, assert);
- var s1 = serialize(tObj1);
- var s2 = serialize(tObj2);
+ const s1 = serialize(tObj1);
+ const s2 = serialize(tObj2);
assert.ok(bufferEquals(s1, s2));
assert.end();
},
- "Modifications to args object should not affect constructed Thrift object": function (assert) {
-
- var args = createJsObj();
+ "Modifications to args object should not affect constructed Thrift object": function(
+ assert
+ ) {
+ const args = createJsObj();
assertValues(args, assert);
- var tObj = new ttypes.Complex(args);
+ const tObj = new ttypes.Complex(args);
assertValues(tObj, assert);
- args.struct_field.value = 'ZZZ';
- args.struct_list_field[0].value = 'ZZZ';
- args.struct_list_field[1].value = 'ZZZ';
- args.struct_set_field[0].value = 'ZZZ';
- args.struct_set_field[1].value = 'ZZZ';
- args.struct_map_field.A.value = 'ZZZ';
- args.struct_map_field.B.value = 'ZZZ';
- args.struct_nested_containers_field[0][0].C[0] = 'ZZZ';
- args.struct_nested_containers_field[0][0].C[1] = 'ZZZ';
- args.struct_nested_containers_field2.D[0].DA = 'ZZZ';
- args.struct_nested_containers_field2.D[0].DB = 'ZZZ';
+ args.struct_field.value = "ZZZ";
+ args.struct_list_field[0].value = "ZZZ";
+ args.struct_list_field[1].value = "ZZZ";
+ args.struct_set_field[0].value = "ZZZ";
+ args.struct_set_field[1].value = "ZZZ";
+ args.struct_map_field.A.value = "ZZZ";
+ args.struct_map_field.B.value = "ZZZ";
+ args.struct_nested_containers_field[0][0].C[0] = "ZZZ";
+ args.struct_nested_containers_field[0][0].C[1] = "ZZZ";
+ args.struct_nested_containers_field2.D[0].DA = "ZZZ";
+ args.struct_nested_containers_field2.D[0].DB = "ZZZ";
assertValues(tObj, assert);
assert.end();
},
"nulls are ok": function(assert) {
- var tObj = new ttypes.Complex({
+ const tObj = new ttypes.Complex({
struct_field: null,
struct_list_field: null,
struct_set_field: null,
@@ -296,7 +298,7 @@ function createTestCases(serialize, deserialize) {
struct_nested_containers_field: null,
struct_nested_containers_field2: null
});
- var received = deserialize(serialize(tObj), ttypes.Complex);
+ const received = deserialize(serialize(tObj), ttypes.Complex);
assert.strictEqual(tObj.struct_field, null);
assert.ok(tObj !== received);
assert.deepEqual(tObj, received);
@@ -304,11 +306,11 @@ function createTestCases(serialize, deserialize) {
},
"Can make list with objects": function(assert) {
- var tObj = new ttypes.ComplexList({
- "struct_list_field": [new ttypes.Complex({})]
+ const tObj = new ttypes.ComplexList({
+ struct_list_field: [new ttypes.Complex({})]
});
- var innerObj = tObj.struct_list_field[0];
- assert.ok(innerObj instanceof ttypes.Complex)
+ const innerObj = tObj.struct_list_field[0];
+ assert.ok(innerObj instanceof ttypes.Complex);
assert.strictEqual(innerObj.struct_field, null);
assert.strictEqual(innerObj.struct_list_field, null);
assert.strictEqual(innerObj.struct_set_field, null);
@@ -317,17 +319,15 @@ function createTestCases(serialize, deserialize) {
assert.strictEqual(innerObj.struct_nested_containers_field2, null);
assert.end();
}
-
};
return cases;
}
-
-function run(name, cases){
+function run(name, cases) {
Object.keys(cases).forEach(function(caseName) {
- test(name + ': ' + caseName, cases[caseName]);
+ test(name + ": " + caseName, cases[caseName]);
});
}
-run('binary', createTestCases(serializeBinary, deserializeBinary));
-run('json', createTestCases(serializeJSON, deserializeJSON));
+run("binary", createTestCases(serializeBinary, deserializeBinary));
+run("json", createTestCases(serializeJSON, deserializeJSON));
diff --git a/lib/nodejs/test/exceptions.js b/lib/nodejs/test/exceptions.js
index afb3f67b7..ab2798a26 100644
--- a/lib/nodejs/test/exceptions.js
+++ b/lib/nodejs/test/exceptions.js
@@ -17,72 +17,130 @@
* under the License.
*/
-'use strict';
-var test = require('tape');
-var thrift = require('../lib/thrift/thrift.js');
-var InputBufferUnderrunError = require('../lib/thrift/input_buffer_underrun_error');
+"use strict";
+const test = require("tape");
+const thrift = require("../lib/thrift/thrift.js");
+const InputBufferUnderrunError = require("../lib/thrift/input_buffer_underrun_error");
-test('TApplicationException', function t(assert) {
- var e = new thrift.TApplicationException(1, 'foo');
- assert.ok(e instanceof thrift.TApplicationException, 'is instanceof TApplicationException');
- assert.ok(e instanceof thrift.TException, 'is instanceof TException');
- assert.ok(e instanceof Error, 'is instanceof Error');
- assert.equal(typeof e.stack, 'string', 'has stack trace');
- assert.ok(/^TApplicationException: foo/.test(e.stack), 'Stack trace has correct error name and message');
- assert.ok(e.stack.indexOf('test/exceptions.js:7:11') !== -1, 'stack trace starts on correct line and column');
- assert.equal(e.name, 'TApplicationException', 'has function name TApplicationException');
- assert.equal(e.message, 'foo', 'has error message "foo"');
- assert.equal(e.type, 1, 'has type 1');
+test("TApplicationException", function t(assert) {
+ const e = new thrift.TApplicationException(1, "foo");
+ assert.ok(
+ e instanceof thrift.TApplicationException,
+ "is instanceof TApplicationException"
+ );
+ assert.ok(e instanceof thrift.TException, "is instanceof TException");
+ assert.ok(e instanceof Error, "is instanceof Error");
+ assert.equal(typeof e.stack, "string", "has stack trace");
+ assert.ok(
+ /^TApplicationException: foo/.test(e.stack),
+ "Stack trace has correct error name and message"
+ );
+ assert.ok(
+ e.stack.indexOf("test/exceptions.js:7:11") !== -1,
+ "stack trace starts on correct line and column"
+ );
+ assert.equal(
+ e.name,
+ "TApplicationException",
+ "has function name TApplicationException"
+ );
+ assert.equal(e.message, "foo", 'has error message "foo"');
+ assert.equal(e.type, 1, "has type 1");
assert.end();
});
-test('unexpected TApplicationException ', function t(assert) {
- var e = new thrift.TApplicationException(1, 100);
- assert.ok(e instanceof thrift.TApplicationException, 'is instanceof TApplicationException');
- assert.ok(e instanceof thrift.TException, 'is instanceof TException');
- assert.ok(e instanceof Error, 'is instanceof Error');
- assert.equal(typeof e.stack, 'string', 'has stack trace');
- assert.ok(/^TApplicationException: 100/.test(e.stack), 'Stack trace has correct error name and message');
- assert.ok(e.stack.indexOf('test/exceptions.js:7:11') !== -1, 'stack trace starts on correct line and column');
- assert.equal(e.name, 'TApplicationException', 'has function name TApplicationException');
- assert.equal(e.message, 100, 'has error message 100');
- assert.equal(e.type, 1, 'has type 1');
+test("unexpected TApplicationException ", function t(assert) {
+ const e = new thrift.TApplicationException(1, 100);
+ assert.ok(
+ e instanceof thrift.TApplicationException,
+ "is instanceof TApplicationException"
+ );
+ assert.ok(e instanceof thrift.TException, "is instanceof TException");
+ assert.ok(e instanceof Error, "is instanceof Error");
+ assert.equal(typeof e.stack, "string", "has stack trace");
+ assert.ok(
+ /^TApplicationException: 100/.test(e.stack),
+ "Stack trace has correct error name and message"
+ );
+ assert.ok(
+ e.stack.indexOf("test/exceptions.js:7:11") !== -1,
+ "stack trace starts on correct line and column"
+ );
+ assert.equal(
+ e.name,
+ "TApplicationException",
+ "has function name TApplicationException"
+ );
+ assert.equal(e.message, 100, "has error message 100");
+ assert.equal(e.type, 1, "has type 1");
assert.end();
});
-test('TException', function t(assert) {
- var e = new thrift.TException('foo');
- assert.ok(e instanceof thrift.TException, 'is instanceof TException');
- assert.ok(e instanceof Error, 'is instanceof Error');
- assert.equal(typeof e.stack, 'string', 'has stack trace');
- assert.ok(/^TException: foo/.test(e.stack), 'Stack trace has correct error name and message');
- assert.ok(e.stack.indexOf('test/exceptions.js:21:11') !== -1, 'stack trace starts on correct line and column');
- assert.equal(e.name, 'TException', 'has function name TException');
- assert.equal(e.message, 'foo', 'has error message "foo"');
+test("TException", function t(assert) {
+ const e = new thrift.TException("foo");
+ assert.ok(e instanceof thrift.TException, "is instanceof TException");
+ assert.ok(e instanceof Error, "is instanceof Error");
+ assert.equal(typeof e.stack, "string", "has stack trace");
+ assert.ok(
+ /^TException: foo/.test(e.stack),
+ "Stack trace has correct error name and message"
+ );
+ assert.ok(
+ e.stack.indexOf("test/exceptions.js:21:11") !== -1,
+ "stack trace starts on correct line and column"
+ );
+ assert.equal(e.name, "TException", "has function name TException");
+ assert.equal(e.message, "foo", 'has error message "foo"');
assert.end();
});
-test('TProtocolException', function t(assert) {
- var e = new thrift.TProtocolException(1, 'foo');
- assert.ok(e instanceof thrift.TProtocolException, 'is instanceof TProtocolException');
- assert.ok(e instanceof Error, 'is instanceof Error');
- assert.equal(typeof e.stack, 'string', 'has stack trace');
- assert.ok(/^TProtocolException: foo/.test(e.stack), 'Stack trace has correct error name and message');
- assert.ok(e.stack.indexOf('test/exceptions.js:33:11') !== -1, 'stack trace starts on correct line and column');
- assert.equal(e.name, 'TProtocolException', 'has function name TProtocolException');
- assert.equal(e.message, 'foo', 'has error message "foo"');
- assert.equal(e.type, 1, 'has type 1');
+test("TProtocolException", function t(assert) {
+ const e = new thrift.TProtocolException(1, "foo");
+ assert.ok(
+ e instanceof thrift.TProtocolException,
+ "is instanceof TProtocolException"
+ );
+ assert.ok(e instanceof Error, "is instanceof Error");
+ assert.equal(typeof e.stack, "string", "has stack trace");
+ assert.ok(
+ /^TProtocolException: foo/.test(e.stack),
+ "Stack trace has correct error name and message"
+ );
+ assert.ok(
+ e.stack.indexOf("test/exceptions.js:33:11") !== -1,
+ "stack trace starts on correct line and column"
+ );
+ assert.equal(
+ e.name,
+ "TProtocolException",
+ "has function name TProtocolException"
+ );
+ assert.equal(e.message, "foo", 'has error message "foo"');
+ assert.equal(e.type, 1, "has type 1");
assert.end();
});
-test('InputBufferUnderrunError', function t(assert) {
- var e = new InputBufferUnderrunError('foo');
- assert.ok(e instanceof InputBufferUnderrunError, 'is instanceof InputBufferUnderrunError');
- assert.ok(e instanceof Error, 'is instanceof Error');
- assert.equal(typeof e.stack, 'string', 'has stack trace');
- assert.ok(/^InputBufferUnderrunError: foo/.test(e.stack), 'Stack trace has correct error name and message');
- assert.ok(e.stack.indexOf('test/exceptions.js:46:11') !== -1, 'stack trace starts on correct line and column');
- assert.equal(e.name, 'InputBufferUnderrunError', 'has function name InputBufferUnderrunError');
- assert.equal(e.message, 'foo', 'has error message "foo"');
+test("InputBufferUnderrunError", function t(assert) {
+ const e = new InputBufferUnderrunError("foo");
+ assert.ok(
+ e instanceof InputBufferUnderrunError,
+ "is instanceof InputBufferUnderrunError"
+ );
+ assert.ok(e instanceof Error, "is instanceof Error");
+ assert.equal(typeof e.stack, "string", "has stack trace");
+ assert.ok(
+ /^InputBufferUnderrunError: foo/.test(e.stack),
+ "Stack trace has correct error name and message"
+ );
+ assert.ok(
+ e.stack.indexOf("test/exceptions.js:46:11") !== -1,
+ "stack trace starts on correct line and column"
+ );
+ assert.equal(
+ e.name,
+ "InputBufferUnderrunError",
+ "has function name InputBufferUnderrunError"
+ );
+ assert.equal(e.message, "foo", 'has error message "foo"');
assert.end();
});
diff --git a/lib/nodejs/test/helpers.js b/lib/nodejs/test/helpers.js
index 5f828b31c..72d128d56 100644
--- a/lib/nodejs/test/helpers.js
+++ b/lib/nodejs/test/helpers.js
@@ -17,16 +17,21 @@
* under the License.
*/
-'use strict';
-var thrift = require('../lib/thrift');
+"use strict";
+const thrift = require("../lib/thrift");
module.exports.transports = {
- 'buffered': thrift.TBufferedTransport,
- 'framed': thrift.TFramedTransport
+ buffered: thrift.TBufferedTransport,
+ framed: thrift.TFramedTransport
};
module.exports.protocols = {
- 'json': thrift.TJSONProtocol,
- 'binary': thrift.TBinaryProtocol,
- 'compact': thrift.TCompactProtocol
+ json: thrift.TJSONProtocol,
+ binary: thrift.TBinaryProtocol,
+ compact: thrift.TCompactProtocol
};
+
+module.exports.ecmaMode = process.argv.includes("--es6") ? "es6" : "es5";
+module.exports.genPath = process.argv.includes("--es6")
+ ? "gen-nodejs-es6"
+ : "gen-nodejs";
diff --git a/lib/nodejs/test/server.js b/lib/nodejs/test/server.js
index 030d28b38..7402094bc 100644
--- a/lib/nodejs/test/server.js
+++ b/lib/nodejs/test/server.js
@@ -19,96 +19,119 @@
* under the License.
*/
-var fs = require('fs');
-var path = require('path');
-var thrift = require('../lib/thrift');
-var program = require('commander');
-var helpers = require('./helpers');
-
-var ThriftTest = require('./gen-nodejs/ThriftTest');
-var SecondService = require('./gen-nodejs/SecondService');
-var ThriftTestHandler = require('./test_handler').AsyncThriftTestHandler;
-var ThriftTestHandlerPromise = require('./test_handler').SyncThriftTestHandler;
-var ttypes = require('./gen-nodejs/ThriftTest_types');
+const fs = require("fs");
+const path = require("path");
+const thrift = require("../lib/thrift");
+const program = require("commander");
+const helpers = require("./helpers");
program
- .option('-p, --protocol <protocol>', 'Set thrift protocol (binary|compact|json)', 'binary')
- .option('-t, --transport <transport>', 'Set thrift transport (buffered|framed|http)', 'buffered')
- .option('--ssl', 'use ssl transport')
- .option('--port <port>', 'Set thrift server port', 9090)
- .option('--domain-socket <path>', 'Set thift server unix domain socket')
- .option('--promise', 'test with promise style functions')
- .option('-t, --type <type>', 'Select server type (http|multiplex|tcp|websocket)', 'tcp')
+ .option(
+ "-p, --protocol <protocol>",
+ "Set thrift protocol (binary|compact|json)",
+ "binary"
+ )
+ .option(
+ "-t, --transport <transport>",
+ "Set thrift transport (buffered|framed|http)",
+ "buffered"
+ )
+ .option("--ssl", "use ssl transport")
+ .option("--port <port>", "Set thrift server port", 9090)
+ .option("--domain-socket <path>", "Set thift server unix domain socket")
+ .option(
+ "-t, --type <type>",
+ "Select server type (http|multiplex|tcp|websocket)",
+ "tcp"
+ )
+ .option("--callback", "test with callback style functions")
+ .option("--es6", "Use es6 code")
+ .option("--es5", "Use es5 code")
.parse(process.argv);
-var port = program.port;
-var domainSocket = program.domainSocket;
-var type = program.type;
-var ssl = program.ssl;
-var promise = program.promise;
+const ThriftTest = require(`./${helpers.genPath}/ThriftTest`);
+const SecondService = require(`./${helpers.genPath}/SecondService`);
+const { ThriftTestHandler } = require("./test_handler");
-var handler = program.promise ? ThriftTestHandler : ThriftTestHandlerPromise;
+const port = program.port;
+const domainSocket = program.domainSocket;
+const ssl = program.ssl;
-if (program.transport === 'http') {
- program.transport = 'buffered';
- type = 'http';
+let type = program.type;
+if (program.transport === "http") {
+ program.transport = "buffered";
+ type = "http";
}
-var options = {
+let options = {
transport: helpers.transports[program.transport],
protocol: helpers.protocols[program.protocol]
};
-if (type === 'http' || type ==='websocket') {
- options.handler = handler;
+if (type === "http" || type === "websocket") {
+ options.handler = ThriftTestHandler;
options.processor = ThriftTest;
options = {
services: { "/test": options },
cors: {
- '*': true
+ "*": true
}
- }
+ };
}
-if (type === 'multiplex') {
- var SecondServiceHandler = {
+let processor;
+if (type === "multiplex") {
+ const SecondServiceHandler = {
secondtestString: function(thing, result) {
console.log('testString("' + thing + '")');
result(null, 'testString("' + thing + '")');
}
};
- var processor = new thrift.MultiplexedProcessor();
-
- processor.registerProcessor("ThriftTest",
- new ThriftTest.Processor(ThriftTestHandler));
+ processor = new thrift.MultiplexedProcessor();
- processor.registerProcessor("SecondService",
- new SecondService.Processor(SecondServiceHandler));
+ processor.registerProcessor(
+ "ThriftTest",
+ new ThriftTest.Processor(ThriftTestHandler)
+ );
+ processor.registerProcessor(
+ "SecondService",
+ new SecondService.Processor(SecondServiceHandler)
+ );
}
if (ssl) {
- if (type === 'tcp' || type === 'multiplex' || type === 'http' || type === 'websocket') {
+ if (
+ type === "tcp" ||
+ type === "multiplex" ||
+ type === "http" ||
+ type === "websocket"
+ ) {
options.tls = {
- key: fs.readFileSync(path.resolve(__dirname, 'server.key')),
- cert: fs.readFileSync(path.resolve(__dirname, 'server.crt'))
+ key: fs.readFileSync(path.resolve(__dirname, "server.key")),
+ cert: fs.readFileSync(path.resolve(__dirname, "server.crt"))
};
}
}
-var server;
-if (type === 'tcp') {
- server = thrift.createServer(ThriftTest, handler, options);
-} else if (type === 'multiplex') {
+let server;
+if (type === "tcp") {
+ server = thrift.createServer(ThriftTest, ThriftTestHandler, options);
+} else if (type === "multiplex") {
server = thrift.createMultiplexServer(processor, options);
-} else if (type === 'http' || type === 'websocket') {
+} else if (type === "http" || type === "websocket") {
server = thrift.createWebServer(options);
}
if (domainSocket) {
server.listen(domainSocket);
-} else if (type === 'tcp' || type === 'multiplex' || type === 'http' || type === 'websocket') {
+} else if (
+ type === "tcp" ||
+ type === "multiplex" ||
+ type === "http" ||
+ type === "websocket"
+) {
server.listen(port);
}
diff --git a/lib/nodejs/test/test-cases.js b/lib/nodejs/test/test-cases.js
index bd66dc496..02c566fbf 100644
--- a/lib/nodejs/test/test-cases.js
+++ b/lib/nodejs/test/test-cases.js
@@ -17,139 +17,156 @@
* under the License.
*/
-'use strict';
+"use strict";
-var ttypes = require('./gen-nodejs/ThriftTest_types');
-var Int64 = require('node-int64');
+const helpers = require("./helpers");
+const ttypes = require(`./${helpers.genPath}/ThriftTest_types`);
+const Int64 = require("node-int64");
//all Languages in UTF-8
/*jshint -W100 */
-var stringTest = module.exports.stringTest = "Afrikaans, Alemannisch, Aragonés, العربية, مصرى, " +
- "Asturianu, Aymar aru, Azərbaycan, Башҡорт, Boarisch, Žemaitėška, " +
- "Беларуская, Беларуская (тарашкевіца), Български, Bamanankan, " +
- "বাংলা, Brezhoneg, Bosanski, Català, Mìng-dĕ̤ng-ngṳ̄, Нохчийн, " +
- "Cebuano, ᏣᎳᎩ, Česky, Словѣ́ньскъ / ⰔⰎⰑⰂⰡⰐⰠⰔⰍⰟ, Чӑвашла, Cymraeg, " +
- "Dansk, Zazaki, ދިވެހިބަސް, Ελληνικά, Emiliàn e rumagnòl, English, " +
- "Esperanto, Español, Eesti, Euskara, فارسی, Suomi, Võro, Føroyskt, " +
- "Français, Arpetan, Furlan, Frysk, Gaeilge, 贛語, Gàidhlig, Galego, " +
- "Avañe'ẽ, ગુજરાતી, Gaelg, עברית, हिन्दी, Fiji Hindi, Hrvatski, " +
- "Kreyòl ayisyen, Magyar, Հայերեն, Interlingua, Bahasa Indonesia, " +
- "Ilokano, Ido, Íslenska, Italiano, 日本語, Lojban, Basa Jawa, " +
- "ქართული, Kongo, Kalaallisut, ಕನ್ನಡ, 한국어, Къарачай-Малкъар, " +
- "Ripoarisch, Kurdî, Коми, Kernewek, Кыргызча, Latina, Ladino, " +
- "Lëtzebuergesch, Limburgs, Lingála, ລາວ, Lietuvių, Latviešu, Basa " +
- "Banyumasan, Malagasy, Македонски, മലയാളം, मराठी, مازِرونی, Bahasa " +
- "Melayu, Nnapulitano, Nedersaksisch, नेपाल भाषा, Nederlands, ‪" +
- "Norsk (nynorsk)‬, ‪Norsk (bokmål)‬, Nouormand, Diné bizaad, " +
- "Occitan, Иронау, Papiamentu, Deitsch, Polski, پنجابی, پښتو, " +
- "Norfuk / Pitkern, Português, Runa Simi, Rumantsch, Romani, Română, " +
- "Русский, Саха тыла, Sardu, Sicilianu, Scots, Sámegiella, Simple " +
- "English, Slovenčina, Slovenščina, Српски / Srpski, Seeltersk, " +
- "Svenska, Kiswahili, தமிழ், తెలుగు, Тоҷикӣ, ไทย, Türkmençe, Tagalog, " +
- "Türkçe, Татарча/Tatarça, Українська, اردو, Tiếng Việt, Volapük, " +
- "Walon, Winaray, 吴语, isiXhosa, ייִדיש, Yorùbá, Zeêuws, 中文, " +
- "Bân-lâm-gú, 粵語";
+const stringTest = (module.exports.stringTest =
+ "Afrikaans, Alemannisch, Aragonés, العربية, مصرى, " +
+ "Asturianu, Aymar aru, Azərbaycan, Башҡорт, Boarisch, Žemaitėška, " +
+ "Беларуская, Беларуская (тарашкевіца), Български, Bamanankan, " +
+ "বাংলা, Brezhoneg, Bosanski, Català, Mìng-dĕ̤ng-ngṳ̄, Нохчийн, " +
+ "Cebuano, ᏣᎳᎩ, Česky, Словѣ́ньскъ / ⰔⰎⰑⰂⰡⰐⰠⰔⰍⰟ, Чӑвашла, Cymraeg, " +
+ "Dansk, Zazaki, ދިވެހިބަސް, Ελληνικά, Emiliàn e rumagnòl, English, " +
+ "Esperanto, Español, Eesti, Euskara, فارسی, Suomi, Võro, Føroyskt, " +
+ "Français, Arpetan, Furlan, Frysk, Gaeilge, 贛語, Gàidhlig, Galego, " +
+ "Avañe'ẽ, ગુજરાતી, Gaelg, עברית, हिन्दी, Fiji Hindi, Hrvatski, " +
+ "Kreyòl ayisyen, Magyar, Հայերեն, Interlingua, Bahasa Indonesia, " +
+ "Ilokano, Ido, Íslenska, Italiano, 日本語, Lojban, Basa Jawa, " +
+ "ქართული, Kongo, Kalaallisut, ಕನ್ನಡ, 한국어, Къарачай-Малкъар, " +
+ "Ripoarisch, Kurdî, Коми, Kernewek, Кыргызча, Latina, Ladino, " +
+ "Lëtzebuergesch, Limburgs, Lingála, ລາວ, Lietuvių, Latviešu, Basa " +
+ "Banyumasan, Malagasy, Македонски, മലയാളം, मराठी, مازِرونی, Bahasa " +
+ "Melayu, Nnapulitano, Nedersaksisch, नेपाल भाषा, Nederlands, ‪" +
+ "Norsk (nynorsk)‬, ‪Norsk (bokmål)‬, Nouormand, Diné bizaad, " +
+ "Occitan, Иронау, Papiamentu, Deitsch, Polski, پنجابی, پښتو, " +
+ "Norfuk / Pitkern, Português, Runa Simi, Rumantsch, Romani, Română, " +
+ "Русский, Саха тыла, Sardu, Sicilianu, Scots, Sámegiella, Simple " +
+ "English, Slovenčina, Slovenščina, Српски / Srpski, Seeltersk, " +
+ "Svenska, Kiswahili, தமிழ், తెలుగు, Тоҷикӣ, ไทย, Türkmençe, Tagalog, " +
+ "Türkçe, Татарча/Tatarça, Українська, اردو, Tiếng Việt, Volapük, " +
+ "Walon, Winaray, 吴语, isiXhosa, ייִדיש, Yorùbá, Zeêuws, 中文, " +
+ "Bân-lâm-gú, 粵語");
/*jshint +W100 */
-var specialCharacters = module.exports.specialCharacters = 'quote: \" backslash:' +
- ' forwardslash-escaped: \/ ' +
- ' backspace: \b formfeed: \f newline: \n return: \r tab: ' +
- ' now-all-of-them-together: "\\\/\b\n\r\t' +
- ' now-a-bunch-of-junk: !@#$%&()(&%$#{}{}<><><' +
- ' char-to-test-json-parsing: ]] \"]] \\" }}}{ [[[ ';
+const specialCharacters = (module.exports.specialCharacters =
+ 'quote: " backslash:' +
+ " forwardslash-escaped: / " +
+ " backspace: \b formfeed: \f newline: \n return: \r tab: " +
+ ' now-all-of-them-together: "\\/\b\n\r\t' +
+ " now-a-bunch-of-junk: !@#$%&()(&%$#{}{}<><><" +
+ ' char-to-test-json-parsing: ]] "]] \\" }}}{ [[[ ');
+
+const mapTestInput = (module.exports.mapTestInput = {
+ a: "123",
+ "a b": "with spaces ",
+ same: "same",
+ "0": "numeric key",
+ longValue: stringTest,
+ stringTest: "long key"
+});
-var mapTestInput = module.exports.mapTestInput = {
- "a":"123", "a b":"with spaces ", "same":"same", "0":"numeric key",
- "longValue":stringTest, stringTest:"long key"
-};
+const simple = [
+ ["testVoid", undefined],
+ ["testString", "Test"],
+ ["testString", ""],
+ ["testString", stringTest],
+ ["testString", specialCharacters],
+ ["testBool", true],
+ ["testBool", false],
+ ["testByte", 1],
+ ["testByte", 0],
+ ["testByte", -1],
+ ["testByte", -127],
+ ["testI32", -1],
+ ["testDouble", -5.2098523],
+ ["testDouble", 7.012052175215044],
+ ["testEnum", ttypes.Numberz.ONE],
+ ["testI64", 5],
+ ["testI64", -5],
+ ["testI64", 734359738368],
+ ["testI64", -734359738368],
+ ["testI64", new Int64(new Buffer([0, 0x20, 0, 0, 0, 0, 0, 1]))], // 2^53+1
+ [
+ "testI64",
+ new Int64(new Buffer([0xff, 0xdf, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff]))
+ ], // -2^53-1
+ ["testTypedef", 69]
+];
-var simple = [
- ['testVoid', undefined],
- ['testString', 'Test'],
- ['testString', ''],
- ['testString', stringTest],
- ['testString', specialCharacters],
- ['testBool', true],
- ['testBool', false],
- ['testByte', 1],
- ['testByte', 0],
- ['testByte', -1],
- ['testByte', -127],
- ['testI32', -1],
- ['testDouble', -5.2098523],
- ['testDouble', 7.012052175215044],
- ['testEnum', ttypes.Numberz.ONE],
- ['testI64', 5],
- ['testI64', -5],
- ['testI64', 734359738368],
- ['testI64', -734359738368],
- ['testI64', new Int64(new Buffer([0, 0x20, 0, 0, 0, 0, 0, 1]))], // 2^53+1
- ['testI64', new Int64(
- new Buffer([0xff, 0xdf, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff]))], // -2^53-1
- ['testTypedef', 69]
-]
-
-var mapout = {};
-for (var i = 0; i < 5; ++i) {
- mapout[i] = i-10;
+const mapout = {};
+for (let i = 0; i < 5; ++i) {
+ mapout[i] = i - 10;
}
-var deep = [
- ['testList', [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20]],
+const deep = [
+ [
+ "testList",
+ [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]
+ ]
];
-var deepUnordered = [
- ['testMap', mapout],
- ['testSet', [1,2,3]],
- ['testStringMap', mapTestInput]
+const deepUnordered = [
+ ["testMap", mapout],
+ ["testSet", [1, 2, 3]],
+ ["testStringMap", mapTestInput]
];
-var out = new ttypes.Xtruct({
- string_thing: 'Zero',
+const out = new ttypes.Xtruct({
+ string_thing: "Zero",
byte_thing: 1,
i32_thing: -3,
i64_thing: 1000000
});
-var out2 = new ttypes.Xtruct2();
+const out2 = new ttypes.Xtruct2();
out2.byte_thing = 1;
out2.struct_thing = out;
out2.i32_thing = 5;
-var crazy = new ttypes.Insanity({
- "userMap":{ "5":5, "8":8 },
- "xtructs":[new ttypes.Xtruct({
- "string_thing":"Goodbye4",
- "byte_thing":4,
- "i32_thing":4,
- "i64_thing":4
- }), new ttypes.Xtruct({
- "string_thing":"Hello2",
- "byte_thing":2,
- "i32_thing":2,
- "i64_thing":2
- })]
+const crazy = new ttypes.Insanity({
+ userMap: { "5": 5, "8": 8 },
+ xtructs: [
+ new ttypes.Xtruct({
+ string_thing: "Goodbye4",
+ byte_thing: 4,
+ i32_thing: 4,
+ i64_thing: 4
+ }),
+ new ttypes.Xtruct({
+ string_thing: "Hello2",
+ byte_thing: 2,
+ i32_thing: 2,
+ i64_thing: 2
+ })
+ ]
});
-var crazy2 = new ttypes.Insanity({
- "userMap":{ "5":5, "8":8 },
- "xtructs":[{
- "string_thing":"Goodbye4",
- "byte_thing":4,
- "i32_thing":4,
- "i64_thing":4
- }, {
- "string_thing":"Hello2",
- "byte_thing":2,
- "i32_thing":2,
- "i64_thing":2
- }]
+const crazy2 = new ttypes.Insanity({
+ userMap: { "5": 5, "8": 8 },
+ xtructs: [
+ {
+ string_thing: "Goodbye4",
+ byte_thing: 4,
+ i32_thing: 4,
+ i64_thing: 4
+ },
+ {
+ string_thing: "Hello2",
+ byte_thing: 2,
+ i32_thing: 2,
+ i64_thing: 2
+ }
+ ]
});
-
-var insanity = {
- "1":{ "2": crazy, "3": crazy },
- "2":{ "6":{ "userMap":{}, "xtructs":[] } }
+const insanity = {
+ "1": { "2": crazy, "3": crazy },
+ "2": { "6": { userMap: {}, xtructs: [] } }
};
module.exports.simple = simple;
diff --git a/lib/nodejs/test/testAll.sh b/lib/nodejs/test/testAll.sh
index ac22b64e8..24f1f2ea1 100755
--- a/lib/nodejs/test/testAll.sh
+++ b/lib/nodejs/test/testAll.sh
@@ -33,21 +33,21 @@ export NODE_PATH="${DIR}:${DIR}/../lib:${NODE_PATH}"
testServer()
{
- echo " Testing $1 Client/Server with protocol $2 and transport $3 $4";
+ echo " [ECMA $1] Testing $2 Client/Server with protocol $3 and transport $4 $5";
RET=0
if [ -n "${COVER}" ]; then
- ${ISTANBUL} cover ${DIR}/server.js --dir ${REPORT_PREFIX}${COUNT} --handle-sigint -- --type $1 -p $2 -t $3 $4 &
+ ${ISTANBUL} cover ${DIR}/server.js --dir ${REPORT_PREFIX}${COUNT} --handle-sigint -- --type $2 -p $3 -t $4 $5 &
COUNT=$((COUNT+1))
else
- node ${DIR}/server.js --type $1 -p $2 -t $3 $4 &
+ node ${DIR}/server.js --${1} --type $2 -p $3 -t $4 $5 &
fi
SERVERPID=$!
sleep 0.1
if [ -n "${COVER}" ]; then
- ${ISTANBUL} cover ${DIR}/client.js --dir ${REPORT_PREFIX}${COUNT} -- --type $1 -p $2 -t $3 $4 || RET=1
+ ${ISTANBUL} cover ${DIR}/client.js --dir ${REPORT_PREFIX}${COUNT} -- --${1} --type $2 -p $3 -t $4 $5 || RET=1
COUNT=$((COUNT+1))
else
- node ${DIR}/client.js --type $1 -p $2 -t $3 $4 || RET=1
+ node ${DIR}/client.js --${1} --type $2 -p $3 -t $4 $5 || RET=1
fi
kill -2 $SERVERPID || RET=1
wait $SERVERPID
@@ -61,6 +61,9 @@ TESTOK=0
${DIR}/../../../compiler/cpp/thrift -o ${DIR} --gen js:node ${DIR}/../../../test/ThriftTest.thrift
${DIR}/../../../compiler/cpp/thrift -o ${DIR} --gen js:node ${DIR}/../../../test/JsDeepConstructorTest.thrift
+mkdir ${DIR}/gen-nodejs-es6
+${DIR}/../../../compiler/cpp/thrift -out ${DIR}/gen-nodejs-es6 --gen js:node,es6 ${DIR}/../../../test/ThriftTest.thrift
+${DIR}/../../../compiler/cpp/thrift -out ${DIR}/gen-nodejs-es6 --gen js:node,es6 ${DIR}/../../../test/JsDeepConstructorTest.thrift
#unit tests
@@ -71,15 +74,16 @@ node ${DIR}/deep-constructor.test.js || TESTOK=1
for type in tcp multiplex websocket http
do
-
for protocol in compact binary json
do
-
for transport in buffered framed
do
- testServer $type $protocol $transport || TESTOK=1
- testServer $type $protocol $transport --ssl || TESTOK=1
- testServer $type $protocol $transport --promise || TESTOK=1
+ for ecma_version in es5 es6
+ do
+ testServer $ecma_version $type $protocol $transport || TESTOK=1
+ testServer $ecma_version $type $protocol $transport --ssl || TESTOK=1
+ testServer $ecma_version $type $protocol $transport --callback || TESTOK=1
+ done
done
done
done
diff --git a/lib/nodejs/test/test_driver.js b/lib/nodejs/test/test_driver.js
index 4612a326a..7c9a91914 100644
--- a/lib/nodejs/test/test_driver.js
+++ b/lib/nodejs/test/test_driver.js
@@ -17,252 +17,279 @@
* under the License.
*/
- // This is the Node.js test driver for the standard Apache Thrift
- // test service. The driver invokes every function defined in the
- // Thrift Test service with a representative range of parameters.
- //
- // The ThriftTestDriver function requires a client object
- // connected to a server hosting the Thrift Test service and
- // supports an optional callback function which is called with
- // a status message when the test is complete.
-
-var test = require('tape');
-//var assert = require('assert');
-var ttypes = require('./gen-nodejs/ThriftTest_types');
-var TException = require('thrift').Thrift.TException;
-var Int64 = require('node-int64');
-var testCases = require('./test-cases');
+// This is the Node.js test driver for the standard Apache Thrift
+// test service. The driver invokes every function defined in the
+// Thrift Test service with a representative range of parameters.
+//
+// The ThriftTestDriver function requires a client object
+// connected to a server hosting the Thrift Test service and
+// supports an optional callback function which is called with
+// a status message when the test is complete.
+
+const test = require("tape");
+
+const helpers = require("./helpers");
+const ttypes = require(`./${helpers.genPath}/ThriftTest_types`);
+const TException = require("thrift").Thrift.TException;
+const Int64 = require("node-int64");
+const testCases = require("./test-cases");
exports.ThriftTestDriver = function(client, callback) {
+ test(
+ "NodeJS Style Callback Client Tests",
+ { skip: helpers.ecmaMode === "es6" },
+ function(assert) {
+ const checkRecursively = makeRecursiveCheck(assert);
+
+ function makeAsserter(assertionFn) {
+ return function(c) {
+ const fnName = c[0];
+ const expected = c[1];
+ client[fnName](expected, function(err, actual) {
+ assert.error(err, fnName + ": no callback error");
+ assertionFn(actual, expected, fnName);
+ });
+ };
+ }
- test('NodeJS Style Callback Client Tests', function(assert) {
+ testCases.simple.forEach(
+ makeAsserter(function(a, e, m) {
+ if (a instanceof Int64) {
+ const e64 = e instanceof Int64 ? e : new Int64(e);
+ assert.deepEqual(a.buffer, e64.buffer, m);
+ } else {
+ assert.equal(a, e, m);
+ }
+ })
+ );
+ testCases.deep.forEach(makeAsserter(assert.deepEqual));
+ testCases.deepUnordered.forEach(
+ makeAsserter(makeUnorderedDeepEqual(assert))
+ );
+
+ const arr = [];
+ for (let i = 0; i < 256; ++i) {
+ arr[i] = 255 - i;
+ }
+ let buf = new Buffer(arr);
+ client.testBinary(buf, function(err, response) {
+ assert.error(err, "testBinary: no callback error");
+ assert.equal(response.length, 256, "testBinary");
+ assert.deepEqual(response, buf, "testBinary(Buffer)");
+ });
+ buf = new Buffer(arr);
+ client.testBinary(buf.toString("binary"), function(err, response) {
+ assert.error(err, "testBinary: no callback error");
+ assert.equal(response.length, 256, "testBinary");
+ assert.deepEqual(response, buf, "testBinary(string)");
+ });
- var checkRecursively = makeRecursiveCheck(assert);
+ client.testMapMap(42, function(err, response) {
+ const expected = {
+ "4": { "1": 1, "2": 2, "3": 3, "4": 4 },
+ "-4": { "-4": -4, "-3": -3, "-2": -2, "-1": -1 }
+ };
+ assert.error(err, "testMapMap: no callback error");
+ assert.deepEqual(expected, response, "testMapMap");
+ });
- function makeAsserter(assertionFn) {
- return function(c) {
- var fnName = c[0];
- var expected = c[1];
- client[fnName](expected, function(err, actual) {
- assert.error(err, fnName + ': no callback error');
- assertionFn(actual, expected, fnName);
- })
- };
- }
+ client.testStruct(testCases.out, function(err, response) {
+ assert.error(err, "testStruct: no callback error");
+ checkRecursively(testCases.out, response, "testStruct");
+ });
- testCases.simple.forEach(makeAsserter(function(a, e, m){
- if (a instanceof Int64) {
- var e64 = e instanceof Int64 ? e : new Int64(e);
- assert.deepEqual(a.buffer, e64.buffer, m);
- } else {
- assert.equal(a, e, m);
- }
- }));
- testCases.deep.forEach(makeAsserter(assert.deepEqual));
- testCases.deepUnordered.forEach(makeAsserter(makeUnorderedDeepEqual(assert)));
+ client.testNest(testCases.out2, function(err, response) {
+ assert.error(err, "testNest: no callback error");
+ checkRecursively(testCases.out2, response, "testNest");
+ });
- var arr = [];
- for (var i = 0; i < 256; ++i) {
- arr[i] = 255 - i;
- }
- var buf = new Buffer(arr);
- client.testBinary(buf, function(err, response) {
- assert.error(err, 'testBinary: no callback error');
- assert.equal(response.length, 256, 'testBinary');
- assert.deepEqual(response, buf, 'testBinary(Buffer)');
- });
- var buf = new Buffer(arr);
- client.testBinary(buf.toString('binary'), function(err, response) {
- assert.error(err, 'testBinary: no callback error');
- assert.equal(response.length, 256, 'testBinary');
- assert.deepEqual(response, buf, 'testBinary(string)');
- });
-
- client.testMapMap(42, function(err, response) {
- var expected = {
- "4": {"1":1, "2":2, "3":3, "4":4},
- "-4": {"-4":-4, "-3":-3, "-2":-2, "-1":-1}
- };
- assert.error(err, 'testMapMap: no callback error');
- assert.deepEqual(expected, response, 'testMapMap');
- });
-
- client.testStruct(testCases.out, function(err, response) {
- assert.error(err, 'testStruct: no callback error');
- checkRecursively(testCases.out, response, 'testStruct');
- });
-
- client.testNest(testCases.out2, function(err, response) {
- assert.error(err, 'testNest: no callback error');
- checkRecursively(testCases.out2, response, 'testNest');
- });
-
- client.testInsanity(testCases.crazy, function(err, response) {
- assert.error(err, 'testInsanity: no callback error');
- checkRecursively(testCases.insanity, response, 'testInsanity');
- });
-
- client.testInsanity(testCases.crazy2, function(err, response) {
- assert.error(err, 'testInsanity2: no callback error');
- checkRecursively(testCases.insanity, response, 'testInsanity2');
- });
-
- client.testException('TException', function(err, response) {
- assert.ok(err instanceof TException, 'testException: correct error type');
- assert.ok(!response, 'testException: no response');
- });
-
- client.testException('Xception', function(err, response) {
- assert.ok(err instanceof ttypes.Xception, 'testException: correct error type');
- assert.ok(!response, 'testException: no response');
- assert.equal(err.errorCode, 1001, 'testException: correct error code');
- assert.equal('Xception', err.message, 'testException: correct error message');
- });
-
- client.testException('no Exception', function(err, response) {
- assert.error(err, 'testException: no callback error');
- assert.ok(!response, 'testException: no response');
- });
-
- client.testOneway(0, function(err, response) {
- assert.error(err, 'testOneway: no callback error');
- assert.strictEqual(response, undefined, 'testOneway: void response');
- });
+ client.testInsanity(testCases.crazy, function(err, response) {
+ assert.error(err, "testInsanity: no callback error");
+ checkRecursively(testCases.insanity, response, "testInsanity");
+ });
- checkOffByOne(function(done) {
- client.testI32(-1, function(err, response) {
- assert.error(err, 'checkOffByOne: no callback error');
- assert.equal(-1, response);
- assert.end();
- done();
+ client.testInsanity(testCases.crazy2, function(err, response) {
+ assert.error(err, "testInsanity2: no callback error");
+ checkRecursively(testCases.insanity, response, "testInsanity2");
});
- }, callback);
- });
-};
+ client.testException("TException", function(err, response) {
+ assert.ok(
+ err instanceof TException,
+ "testException: correct error type"
+ );
+ assert.ok(!response, "testException: no response");
+ });
-exports.ThriftTestDriverPromise = function(client, callback) {
+ client.testException("Xception", function(err, response) {
+ assert.ok(
+ err instanceof ttypes.Xception,
+ "testException: correct error type"
+ );
+ assert.ok(!response, "testException: no response");
+ assert.equal(err.errorCode, 1001, "testException: correct error code");
+ assert.equal(
+ "Xception",
+ err.message,
+ "testException: correct error message"
+ );
+ });
- test('Q Promise Client Tests', function(assert) {
+ client.testException("no Exception", function(err, response) {
+ assert.error(err, "testException: no callback error");
+ assert.ok(!response, "testException: no response");
+ });
- var checkRecursively = makeRecursiveCheck(assert);
+ client.testOneway(0, function(err, response) {
+ assert.error(err, "testOneway: no callback error");
+ assert.strictEqual(response, undefined, "testOneway: void response");
+ });
- function fail(msg) {
- return function() {
- assert.fail(msg);
- }
+ checkOffByOne(function(done) {
+ client.testI32(-1, function(err, response) {
+ assert.error(err, "checkOffByOne: no callback error");
+ assert.equal(-1, response);
+ assert.end();
+ done();
+ });
+ }, callback);
}
+ );
+
+ // ES6 does not support callback style
+ if (helpers.ecmaMode === "es6") {
+ checkOffByOne(done => done(), callback);
+ }
+};
+
+exports.ThriftTestDriverPromise = function(client, callback) {
+ test("Promise Client Tests", function(assert) {
+ const checkRecursively = makeRecursiveCheck(assert);
function makeAsserter(assertionFn) {
return function(c) {
- var fnName = c[0];
- var expected = c[1];
+ const fnName = c[0];
+ const expected = c[1];
client[fnName](expected)
.then(function(actual) {
assertionFn(actual, expected, fnName);
})
- .fail(fail('fnName'));
+ .catch(() => assert.fail("fnName"));
};
}
- testCases.simple.forEach(makeAsserter(function(a, e, m){
- if (a instanceof Int64) {
- var e64 = e instanceof Int64 ? e : new Int64(e);
- assert.deepEqual(a.buffer, e64.buffer, m);
- } else {
- assert.equal(a, e, m);
- }
- }));
+ testCases.simple.forEach(
+ makeAsserter(function(a, e, m) {
+ if (a instanceof Int64) {
+ const e64 = e instanceof Int64 ? e : new Int64(e);
+ assert.deepEqual(a.buffer, e64.buffer, m);
+ } else {
+ assert.equal(a, e, m);
+ }
+ })
+ );
testCases.deep.forEach(makeAsserter(assert.deepEqual));
- testCases.deepUnordered.forEach(makeAsserter(makeUnorderedDeepEqual(assert)));
+ testCases.deepUnordered.forEach(
+ makeAsserter(makeUnorderedDeepEqual(assert))
+ );
- client.testStruct(testCases.out)
+ client
+ .testStruct(testCases.out)
.then(function(response) {
- checkRecursively(testCases.out, response, 'testStruct');
+ checkRecursively(testCases.out, response, "testStruct");
})
- .fail(fail('testStruct'));
+ .catch(() => assert.fail("testStruct"));
- client.testNest(testCases.out2)
+ client
+ .testNest(testCases.out2)
.then(function(response) {
- checkRecursively(testCases.out2, response, 'testNest');
+ checkRecursively(testCases.out2, response, "testNest");
})
- .fail(fail('testNest'));
+ .catch(() => assert.fail("testNest"));
- client.testInsanity(testCases.crazy)
+ client
+ .testInsanity(testCases.crazy)
.then(function(response) {
- checkRecursively(testCases.insanity, response, 'testInsanity');
+ checkRecursively(testCases.insanity, response, "testInsanity");
})
- .fail(fail('testInsanity'));
+ .catch(() => assert.fail("testInsanity"));
- client.testInsanity(testCases.crazy2)
+ client
+ .testInsanity(testCases.crazy2)
.then(function(response) {
- checkRecursively(testCases.insanity, response, 'testInsanity2');
+ checkRecursively(testCases.insanity, response, "testInsanity2");
})
- .fail(fail('testInsanity2'));
+ .catch(() => assert.fail("testInsanity2"));
- client.testException('TException')
- .then(function(response) {
- fail('testException: TException');
+ client
+ .testException("TException")
+ .then(function() {
+ assert.fail("testException: TException");
})
- .fail(function(err) {
+ .catch(function(err) {
assert.ok(err instanceof TException);
});
- client.testException('Xception')
- .then(function(response) {
- fail('testException: Xception');
+ client
+ .testException("Xception")
+ .then(function() {
+ assert.fail("testException: Xception");
})
- .fail(function(err) {
+ .catch(function(err) {
assert.ok(err instanceof ttypes.Xception);
assert.equal(err.errorCode, 1001);
- assert.equal('Xception', err.message);
+ assert.equal("Xception", err.message);
});
- client.testException('no Exception')
+ client
+ .testException("no Exception")
.then(function(response) {
assert.equal(undefined, response); //void
})
- .fail(fail('testException'));
+ .catch(() => assert.fail("testException"));
- client.testOneway(0)
+ client
+ .testOneway(0)
.then(function(response) {
- assert.strictEqual(response, undefined, 'testOneway: void response')
+ assert.strictEqual(response, undefined, "testOneway: void response");
})
- .fail(fail('testOneway: should not reject'));
+ .catch(() => assert.fail("testOneway: should not reject"));
checkOffByOne(function(done) {
- client.testI32(-1)
+ client
+ .testI32(-1)
.then(function(response) {
- assert.equal(-1, response);
- assert.end();
- done();
+ assert.equal(-1, response);
+ assert.end();
+ done();
})
- .fail(fail('checkOffByOne'));
+ .catch(() => assert.fail("checkOffByOne"));
}, callback);
});
};
-
// Helper Functions
// =========================================================
function makeRecursiveCheck(assert) {
-
- return function (map1, map2, msg) {
- var equal = true;
-
- var equal = checkRecursively(map1, map2);
+ return function(map1, map2, msg) {
+ const equal = checkRecursively(map1, map2);
assert.ok(equal, msg);
// deepEqual doesn't work with fields using node-int64
function checkRecursively(map1, map2) {
- if (typeof map1 !== 'function' && typeof map2 !== 'function') {
- if (!map1 || typeof map1 !== 'object') {
+ if (typeof map1 !== "function" && typeof map2 !== "function") {
+ if (!map1 || typeof map1 !== "object") {
//Handle int64 types (which use node-int64 in Node.js JavaScript)
- if ((typeof map1 === "number") && (typeof map2 === "object") &&
- (map2.buffer) && (map2.buffer instanceof Buffer) && (map2.buffer.length === 8)) {
- var n = new Int64(map2.buffer);
+ if (
+ typeof map1 === "number" &&
+ typeof map2 === "object" &&
+ map2.buffer &&
+ map2.buffer instanceof Buffer &&
+ map2.buffer.length === 8
+ ) {
+ const n = new Int64(map2.buffer);
return map1 === n.toNumber();
} else {
return map1 == map2;
@@ -274,15 +301,14 @@ function makeRecursiveCheck(assert) {
}
}
}
- }
+ };
}
function checkOffByOne(done, callback) {
-
- var retry_limit = 30;
- var retry_interval = 100;
- var test_complete = false;
- var retrys = 0;
+ const retry_limit = 30;
+ const retry_interval = 100;
+ let test_complete = false;
+ let retrys = 0;
/**
* redo a simple test after the oneway to make sure we aren't "off by one" --
@@ -299,14 +325,17 @@ function checkOffByOne(done, callback) {
//We wait up to retry_limit * retry_interval for the test suite to complete
function TestForCompletion() {
- if(test_complete && callback) {
+ if (test_complete && callback) {
callback("Server successfully tested!");
} else {
if (++retrys < retry_limit) {
setTimeout(TestForCompletion, retry_interval);
} else if (callback) {
- callback("Server test failed to complete after " +
- (retry_limit * retry_interval / 1000) + " seconds");
+ callback(
+ "Server test failed to complete after " +
+ (retry_limit * retry_interval) / 1000 +
+ " seconds"
+ );
}
}
}
@@ -317,15 +346,15 @@ function checkOffByOne(done, callback) {
function makeUnorderedDeepEqual(assert) {
return function(actual, expected, name) {
assert.equal(actual.length, expected.length, name);
- for (var k in actual) {
- var found = false;
- for (var k2 in expected) {
+ for (const k in actual) {
+ let found = false;
+ for (const k2 in expected) {
if (actual[k] === expected[k2]) {
found = true;
}
}
if (!found) {
- assert.fail('Unexpected value ' + actual[k] + ' with key ' + k);
+ assert.fail("Unexpected value " + actual[k] + " with key " + k);
}
}
};
diff --git a/lib/nodejs/test/test_handler.js b/lib/nodejs/test/test_handler.js
index 5c89f7acd..317a7c810 100644
--- a/lib/nodejs/test/test_handler.js
+++ b/lib/nodejs/test/test_handler.js
@@ -19,18 +19,17 @@
//This is the server side Node test handler for the standard
// Apache Thrift test service.
+const helpers = require("./helpers");
+const ttypes = require(`./${helpers.genPath}/ThriftTest_types`);
+const TException = require("thrift").Thrift.TException;
-var ttypes = require('./gen-nodejs/ThriftTest_types');
-var TException = require('thrift').Thrift.TException;
-
-function makeSyncHandler(label) {
+function makeSyncHandler() {
return function(thing) {
- //console.log(label + '(\'' + thing + '\')');
return thing;
- }
+ };
}
-var syncHandlers = {
+const syncHandlers = {
testVoid: testVoid,
testMapMap: testMapMap,
testInsanity: testInsanity,
@@ -44,10 +43,10 @@ function makeAsyncHandler(label) {
return function(thing, result) {
thing = syncHandlers[label](thing);
result(null, thing);
- }
+ };
}
-var asyncHandlers = {
+const asyncHandlers = {
testVoid: testVoidAsync,
testMulti: testMultiAsync,
testException: testExceptionAsync,
@@ -55,22 +54,22 @@ var asyncHandlers = {
testOneway: testOnewayAsync
};
-var identityHandlers = [
- 'testString',
- 'testBool',
- 'testByte',
- 'testI32',
- 'testI64',
- 'testDouble',
- 'testBinary',
- 'testStruct',
- 'testNest',
- 'testMap',
- 'testStringMap',
- 'testSet',
- 'testList',
- 'testEnum',
- 'testTypedef'
+const identityHandlers = [
+ "testString",
+ "testBool",
+ "testByte",
+ "testI32",
+ "testI64",
+ "testDouble",
+ "testBinary",
+ "testStruct",
+ "testNest",
+ "testMap",
+ "testStringMap",
+ "testSet",
+ "testList",
+ "testEnum",
+ "testTypedef"
];
function testVoid() {
@@ -81,13 +80,11 @@ function testVoidAsync(result) {
result(testVoid());
}
-function testMapMap(hello) {
- //console.log('testMapMap(' + hello + ')');
-
- var mapmap = [];
- var pos = [];
- var neg = [];
- for (var i = 1; i < 5; i++) {
+function testMapMap() {
+ const mapmap = [];
+ const pos = [];
+ const neg = [];
+ for (let i = 1; i < 5; i++) {
pos[i] = i;
neg[-i] = -i;
}
@@ -102,16 +99,16 @@ function testInsanity(argument) {
//console.log(argument);
//console.log(')');
- var first_map = [];
- var second_map = [];
+ const first_map = [];
+ const second_map = [];
first_map[ttypes.Numberz.TWO] = argument;
first_map[ttypes.Numberz.THREE] = argument;
- var looney = new ttypes.Insanity();
+ const looney = new ttypes.Insanity();
second_map[ttypes.Numberz.SIX] = looney;
- var insane = [];
+ const insane = [];
insane[1] = first_map;
insane[2] = second_map;
@@ -120,11 +117,11 @@ function testInsanity(argument) {
return insane;
}
-function testMulti(arg0, arg1, arg2, arg3, arg4, arg5) {
+function testMulti(arg0, arg1, arg2) {
//console.log('testMulti()');
- var hello = new ttypes.Xtruct();
- hello.string_thing = 'Hello2';
+ const hello = new ttypes.Xtruct();
+ hello.string_thing = "Hello2";
hello.byte_thing = arg0;
hello.i32_thing = arg1;
hello.i64_thing = arg2;
@@ -132,18 +129,18 @@ function testMulti(arg0, arg1, arg2, arg3, arg4, arg5) {
}
function testMultiAsync(arg0, arg1, arg2, arg3, arg4, arg5, result) {
- var hello = testMulti(arg0, arg1, arg2, arg3, arg4, arg5);
+ const hello = testMulti(arg0, arg1, arg2, arg3, arg4, arg5);
result(null, hello);
}
function testException(arg) {
//console.log('testException('+arg+')');
- if (arg === 'Xception') {
- var x = new ttypes.Xception();
+ if (arg === "Xception") {
+ const x = new ttypes.Xception();
x.errorCode = 1001;
x.message = arg;
throw x;
- } else if (arg === 'TException') {
+ } else if (arg === "TException") {
throw new TException(arg);
} else {
return;
@@ -152,12 +149,12 @@ function testException(arg) {
function testExceptionAsync(arg, result) {
//console.log('testException('+arg+')');
- if (arg === 'Xception') {
- var x = new ttypes.Xception();
+ if (arg === "Xception") {
+ const x = new ttypes.Xception();
x.errorCode = 1001;
x.message = arg;
result(x);
- } else if (arg === 'TException') {
+ } else if (arg === "TException") {
result(new TException(arg));
} else {
result(null);
@@ -166,49 +163,48 @@ function testExceptionAsync(arg, result) {
function testMultiException(arg0, arg1) {
//console.log('testMultiException(' + arg0 + ', ' + arg1 + ')');
- if (arg0 === ('Xception')) {
- var x = new ttypes.Xception();
+ if (arg0 === "Xception") {
+ const x = new ttypes.Xception();
x.errorCode = 1001;
- x.message = 'This is an Xception';
+ x.message = "This is an Xception";
throw x;
- } else if (arg0 === ('Xception2')) {
- var x2 = new ttypes.Xception2();
+ } else if (arg0 === "Xception2") {
+ const x2 = new ttypes.Xception2();
x2.errorCode = 2002;
x2.struct_thing = new ttypes.Xtruct();
- x2.struct_thing.string_thing = 'This is an Xception2';
+ x2.struct_thing.string_thing = "This is an Xception2";
throw x2;
}
- var res = new ttypes.Xtruct();
+ const res = new ttypes.Xtruct();
res.string_thing = arg1;
return res;
}
function testMultiExceptionAsync(arg0, arg1, result) {
//console.log('testMultiException(' + arg0 + ', ' + arg1 + ')');
- if (arg0 === ('Xception')) {
- var x = new ttypes.Xception();
+ if (arg0 === "Xception") {
+ const x = new ttypes.Xception();
x.errorCode = 1001;
- x.message = 'This is an Xception';
+ x.message = "This is an Xception";
result(x);
- } else if (arg0 === ('Xception2')) {
- var x2 = new ttypes.Xception2();
+ } else if (arg0 === "Xception2") {
+ const x2 = new ttypes.Xception2();
x2.errorCode = 2002;
x2.struct_thing = new ttypes.Xtruct();
- x2.struct_thing.string_thing = 'This is an Xception2';
+ x2.struct_thing.string_thing = "This is an Xception2";
result(x2);
} else {
- var res = new ttypes.Xtruct();
+ const res = new ttypes.Xtruct();
res.string_thing = arg1;
result(null, res);
}
}
-function testOneway(sleepFor) {
- //console.log('testOneway(' + sleepFor + ') => JavaScript (like Rust) never sleeps!');
-}
+//console.log('testOneway(' + sleepFor + ') => JavaScript (like Rust) never sleeps!');
+function testOneway() {}
-function testOnewayAsync(sleepFor, result) {
+function testOnewayAsync(sleepFor) {
testOneway(sleepFor);
}
@@ -217,11 +213,8 @@ identityHandlers.forEach(function(label) {
asyncHandlers[label] = makeAsyncHandler(label);
});
-['testMapMap', 'testInsanity'].forEach(function(label) {
+["testMapMap", "testInsanity"].forEach(function(label) {
asyncHandlers[label] = makeAsyncHandler(label);
});
exports.ThriftTestHandler = asyncHandlers;
-
-exports.AsyncThriftTestHandler = asyncHandlers;
-exports.SyncThriftTestHandler = asyncHandlers;