THRIFT-4625: Use let/const variable decorators in ES6 Javascript
diff --git a/lib/js/test/build.xml b/lib/js/test/build.xml
index 0ba3828..04c1360 100755
--- a/lib/js/test/build.xml
+++ b/lib/js/test/build.xml
@@ -100,9 +100,8 @@
<target name="download_jslibs">
<get src="http://code.jquery.com/jquery-1.11.3.min.js" dest="${build}/js/lib/jquery.js" usetimestamp="true"/>
- <get src="http://code.jquery.com/qunit/qunit-1.18.0.js" dest="${build}/js/lib/qunit.js" usetimestamp="true"/>
- <get src="http://code.jquery.com/qunit/qunit-1.18.0.css" dest="${build}/js/lib/qunit.css" usetimestamp="true"/>
- <get src="https://cdn.jsdelivr.net/npm/es6-promise@4/dist/es6-promise.auto.js" dest="${build}/js/lib/es6-promise.js" usetimestamp="true"/>
+ <get src="http://code.jquery.com/qunit/qunit-2.6.2.js" dest="${build}/js/lib/qunit.js" usetimestamp="true"/>
+ <get src="http://code.jquery.com/qunit/qunit-2.6.2.css" dest="${build}/js/lib/qunit.css" usetimestamp="true"/>
</target>
<target name="jslibs" depends="init, proxy, download_jslibs">
diff --git a/lib/js/test/deep-constructor.test.js b/lib/js/test/deep-constructor.test.js
index f349e46..82d3a1e 100644
--- a/lib/js/test/deep-constructor.test.js
+++ b/lib/js/test/deep-constructor.test.js
@@ -1,6 +1,6 @@
function serialize(data) {
- var transport = new Thrift.Transport('/service');
- var protocol = new Thrift.Protocol(transport);
+ const transport = new Thrift.Transport('/service');
+ const protocol = new Thrift.Protocol(transport);
protocol.writeMessageBegin('', 0, 0);
data.write(protocol);
protocol.writeMessageEnd();
@@ -8,11 +8,11 @@
}
function deserialize(serialized, type) {
- var transport = new Thrift.Transport('/service');
+ const transport = new Thrift.Transport('/service');
transport.setRecvBuffer(serialized);
- var protocol = new Thrift.Protocol(transport);
+ const protocol = new Thrift.Protocol(transport);
protocol.readMessageBegin();
- var data = new type();
+ const data = new type();
data.read(protocol);
protocol.readMessageEnd();
return data;
@@ -145,36 +145,36 @@
assert.equal(obj.list_of_list_field[2][1], 'six');
}
-var cases = {
+const cases = {
'Serialize/deserialize simple struct should return equal object': function(assert) {
- var tObj = new Simple({value: 'a'});
- var received = deserialize(serialize(tObj), Simple);
+ const tObj = new Simple({value: 'a'});
+ const received = deserialize(serialize(tObj), Simple);
assert.ok(tObj !== received);
assert.deepEqual(received, tObj);
},
'Serialize/deserialize should return equal object': function(assert) {
- var tObj = createThriftObj();
- var received = deserialize(serialize(tObj), Complex);
+ const tObj = createThriftObj();
+ const received = deserialize(serialize(tObj), Complex);
assert.ok(tObj !== received);
assert.deepEqual(received, tObj);
},
'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 Complex(createJsObj());
+ const tObj1 = createThriftObj();
+ const tObj2 = new Complex(createJsObj());
assertValues(tObj2, assert);
assert.equal(serialize(tObj2), serialize(tObj1));
},
'Modifications to args object should not affect constructed Thrift object': function(assert) {
- var args = createJsObj();
+ const args = createJsObj();
assertValues(args, assert);
- var tObj = new Complex(args);
+ const tObj = new Complex(args);
assertValues(tObj, assert);
args.struct_field.value = 'ZZZ';
@@ -193,7 +193,7 @@
},
'nulls are ok': function(assert) {
- var tObj = new Complex({
+ const tObj = new Complex({
struct_field: null,
struct_list_field: null,
struct_set_field: null,
@@ -201,7 +201,7 @@
struct_nested_containers_field: null,
struct_nested_containers_field2: null
});
- var received = deserialize(serialize(tObj), Complex);
+ const received = deserialize(serialize(tObj), Complex);
assert.ok(tObj !== received);
assert.deepEqual(tObj, received);
}
@@ -209,5 +209,5 @@
};
Object.keys(cases).forEach(function(caseName) {
- test(caseName, cases[caseName]);
+ QUnit.test(caseName, cases[caseName]);
});
diff --git a/lib/js/test/server_http.js b/lib/js/test/server_http.js
index 1115474..d04f578 100644
--- a/lib/js/test/server_http.js
+++ b/lib/js/test/server_http.js
@@ -17,33 +17,39 @@
* under the License.
*/
-//This HTTP server is designed to serve the test.html browser
+// This HTTP server is designed to serve the test.html browser
// based JavaScript test page (which must be in the current directory).
// This server also supplies the Thrift based test service, which depends
// on the standard ThriftTest.thrift IDL service (which must be compiled
// for Node and browser based JavaScript in ./gen-nodejs and ./gen-js
// respectively).
+//
+// Using the command flag --es6, this server can be run using nodejs code built
+// for the es6 environment or for pre-es6 environment.
+//
-var thrift = require('../../nodejs/lib/thrift');
-var ThriftTestSvc = require('./gen-nodejs/ThriftTest.js');
-var ThriftTestHandler = require('./test_handler').ThriftTestHandler;
+const thrift = require('../../nodejs/lib/thrift');
+const es6Mode = process.argv.includes('--es6');
+const genFolder = es6Mode ? 'gen-nodejs-es6' : 'gen-nodejs';
+const ThriftTestSvc = require(`./${genFolder}/ThriftTest.js`);
+const ThriftTestHandler = require('./test_handler').ThriftTestHandler;
-var ThriftTestSvcOpt = {
+const ThriftTestSvcOpt = {
transport: thrift.TBufferedTransport,
protocol: thrift.TJSONProtocol,
processor: ThriftTestSvc,
handler: ThriftTestHandler
};
-var ThriftWebServerOptions = {
+const ThriftWebServerOptions = {
files: '.',
services: {
'/service': ThriftTestSvcOpt
}
};
-var server = thrift.createWebServer(ThriftWebServerOptions);
-var port = 8088;
+const server = thrift.createWebServer(ThriftWebServerOptions);
+const port = es6Mode ? 8088 : 8089;
server.listen(port);
-console.log('Serving files from: ' + __dirname);
-console.log('Http/Thrift Server running on port: ' + port);
+console.log(`Serving files from: ${__dirname}`);
+console.log(`Http/Thrift Server (ES6 mode ${es6Mode}) running on port: ${port}`);
diff --git a/lib/js/test/server_https.js b/lib/js/test/server_https.js
index 7e78d9e..504f3b5 100644
--- a/lib/js/test/server_https.js
+++ b/lib/js/test/server_https.js
@@ -26,20 +26,22 @@
// support libraries for test.html (jquery.js, qunit.js and qunit.css
// in ./build/js/lib).
-var fs = require('fs');
-var thrift = require('../../nodejs/lib/thrift');
-var ThriftTestSvc = require('./gen-nodejs/ThriftTest.js');
-var ThriftTestHandler = require('./test_handler').ThriftTestHandler;
+const fs = require('fs');
+const thrift = require('../../nodejs/lib/thrift');
+const es6Mode = process.argv.includes('--es6');
+const genFolder = es6Mode ? 'gen-nodejs-es6' : 'gen-nodejs';
+const ThriftTestSvc = require(`./${genFolder}/ThriftTest.js`);
+const ThriftTestHandler = require('./test_handler').ThriftTestHandler;
//Setup the I/O stack options for the ThriftTest service
-var ThriftTestSvcOpt = {
+const ThriftTestSvcOpt = {
transport: thrift.TBufferedTransport,
protocol: thrift.TJSONProtocol,
processor: ThriftTestSvc,
handler: ThriftTestHandler
};
-var ThriftWebServerOptions = {
+const ThriftWebServerOptions = {
files: '.',
tls: {
key: fs.readFileSync('../../../test/keys/server.key'),
@@ -50,8 +52,8 @@
}
};
-var server = thrift.createWebServer(ThriftWebServerOptions);
-var port = 8089;
+const server = thrift.createWebServer(ThriftWebServerOptions);
+const port = es6Mode ? 8090 : 8091;
server.listen(port);
-console.log('Serving files from: ' + __dirname);
-console.log('Http/Thrift Server running on port: ' + port);
+console.log(`Serving files from: ${__dirname}`);
+console.log(`Http/Thrift Server (ES6 mode ${es6Mode}) running on port: ${port}`);
diff --git a/lib/js/test/test-async.js b/lib/js/test/test-async.js
index b4e9854..8c6b13e 100644
--- a/lib/js/test/test-async.js
+++ b/lib/js/test/test-async.js
@@ -30,128 +30,130 @@
// all Languages in UTF-8
-var 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, Norfuk / Pitkern, Polski, پنجابی, پښتو, 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 = "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, Norfuk / Pitkern, Polski, پنجابی, پښتو, 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ú, 粵語";
-function checkRecursively(map1, map2) {
+function checkRecursively(assert, map1, map2) {
if (typeof map1 !== 'function' && typeof map2 !== 'function') {
if (!map1 || typeof map1 !== 'object') {
- equal(map1, map2);
+ assert.equal(map1, map2);
} else {
- for (var key in map1) {
- checkRecursively(map1[key], map2[key]);
+ for (let key in map1) {
+ checkRecursively(assert, map1[key], map2[key]);
}
}
}
}
-module('Base Types');
+QUnit.module('Base Types');
- asyncTest('Void', function() {
- expect(1);
+ QUnit.test('Void', function(assert) {
+ assert.expect(1);
+ const done = assert.async();
client.testVoid(function(result) {
- equal(result, undefined);
- QUnit.start();
+ assert.equal(result, undefined);
+ done();
});
});
- asyncTest('String', function() {
- expect(3);
- QUnit.stop(2);
+ QUnit.test('String', function(assert) {
+ assert.expect(3);
+ const done = assert.async(3);
client.testString('', function(result) {
- equal(result, '');
- QUnit.start();
+ assert.equal(result, '');
+ done();
});
client.testString(stringTest, function(result) {
- equal(result, stringTest);
- QUnit.start();
+ assert.equal(result, stringTest);
+ done();
});
- var specialCharacters = 'quote: \" backslash:' +
+ const 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: !@#$%&()(&%$#{}{}<><><';
client.testString(specialCharacters, function(result) {
- equal(result, specialCharacters);
- QUnit.start();
+ assert.equal(result, specialCharacters);
+ done();
});
});
- asyncTest('Double', function() {
- expect(4);
- QUnit.stop(3);
+ QUnit.test('Double', function(assert) {
+ assert.expect(4);
+ const done = assert.async(4);
client.testDouble(0, function(result) {
- equal(result, 0);
- QUnit.start();
+ assert.equal(result, 0);
+ done();
});
client.testDouble(-1, function(result) {
- equal(result, -1);
- QUnit.start();
+ assert.equal(result, -1);
+ done();
});
client.testDouble(3.14, function(result) {
- equal(result, 3.14);
- QUnit.start();
+ assert.equal(result, 3.14);
+ done();
});
client.testDouble(Math.pow(2, 60), function(result) {
- equal(result, Math.pow(2, 60));
- QUnit.start();
+ assert.equal(result, Math.pow(2, 60));
+ done();
});
});
// TODO: add testBinary()
- asyncTest('Byte', function() {
- expect(2);
- QUnit.stop();
+ QUnit.test('Byte', function(assert) {
+ assert.expect(2);
+ const done = assert.async(2);
client.testByte(0, function(result) {
- equal(result, 0);
- QUnit.start();
+ assert.equal(result, 0);
+ done();
});
client.testByte(0x01, function(result) {
- equal(result, 0x01);
- QUnit.start();
+ assert.equal(result, 0x01);
+ done();
});
});
- asyncTest('I32', function() {
- expect(3);
- QUnit.stop(2);
+ QUnit.test('I32', function(assert) {
+ assert.expect(3);
+ const done = assert.async(3);
client.testI32(0, function(result) {
- equal(result, 0);
- QUnit.start();
+ assert.equal(result, 0);
+ done();
});
client.testI32(Math.pow(2, 30), function(result) {
- equal(result, Math.pow(2, 30));
- QUnit.start();
+ assert.equal(result, Math.pow(2, 30));
+ done();
});
client.testI32(-Math.pow(2, 30), function(result) {
- equal(result, -Math.pow(2, 30));
- QUnit.start();
+ assert.equal(result, -Math.pow(2, 30));
+ done();
});
});
- asyncTest('I64', function() {
- expect(3);
- QUnit.stop(2);
+ QUnit.test('I64', function(assert) {
+ assert.expect(3);
+ const done = assert.async(3);
client.testI64(0, function(result) {
- equal(result, 0);
- QUnit.start();
+ assert.equal(result, 0);
+ done();
});
//This is usually 2^60 but JS cannot represent anything over 2^52 accurately
client.testI64(Math.pow(2, 52), function(result) {
- equal(result, Math.pow(2, 52));
- QUnit.start();
+ assert.equal(result, Math.pow(2, 52));
+ done();
});
client.testI64(-Math.pow(2, 52), function(result) {
- equal(result, -Math.pow(2, 52));
- QUnit.start();
+ assert.equal(result, -Math.pow(2, 52));
+ done();
});
});
-module('Structured Types');
+QUnit.module('Structured Types');
- asyncTest('Struct', function() {
- expect(5);
- var structTestInput = new ThriftTest.Xtruct();
+ QUnit.test('Struct', function(assert) {
+ assert.expect(5);
+ const done = assert.async();
+ const structTestInput = new ThriftTest.Xtruct();
structTestInput.string_thing = 'worked';
structTestInput.byte_thing = 0x01;
structTestInput.i32_thing = Math.pow(2, 30);
@@ -159,148 +161,159 @@
structTestInput.i64_thing = Math.pow(2, 52);
client.testStruct(structTestInput, function(result) {
- equal(result.string_thing, structTestInput.string_thing);
- equal(result.byte_thing, structTestInput.byte_thing);
- equal(result.i32_thing, structTestInput.i32_thing);
- equal(result.i64_thing, structTestInput.i64_thing);
- equal(JSON.stringify(result), JSON.stringify(structTestInput));
- QUnit.start();
+ assert.equal(result.string_thing, structTestInput.string_thing);
+ assert.equal(result.byte_thing, structTestInput.byte_thing);
+ assert.equal(result.i32_thing, structTestInput.i32_thing);
+ assert.equal(result.i64_thing, structTestInput.i64_thing);
+ assert.equal(JSON.stringify(result), JSON.stringify(structTestInput));
+ done();
});
});
- asyncTest('Nest', function() {
- expect(7);
- var xtrTestInput = new ThriftTest.Xtruct();
+ QUnit.test('Nest', function(assert) {
+ assert.expect(7);
+ const done = assert.async();
+ const xtrTestInput = new ThriftTest.Xtruct();
xtrTestInput.string_thing = 'worked';
xtrTestInput.byte_thing = 0x01;
xtrTestInput.i32_thing = Math.pow(2, 30);
//This is usually 2^60 but JS cannot represent anything over 2^52 accurately
xtrTestInput.i64_thing = Math.pow(2, 52);
- var nestTestInput = new ThriftTest.Xtruct2();
+ const nestTestInput = new ThriftTest.Xtruct2();
nestTestInput.byte_thing = 0x02;
nestTestInput.struct_thing = xtrTestInput;
nestTestInput.i32_thing = Math.pow(2, 15);
client.testNest(nestTestInput, function(result) {
- equal(result.byte_thing, nestTestInput.byte_thing);
- equal(result.struct_thing.string_thing, nestTestInput.struct_thing.string_thing);
- equal(result.struct_thing.byte_thing, nestTestInput.struct_thing.byte_thing);
- equal(result.struct_thing.i32_thing, nestTestInput.struct_thing.i32_thing);
- equal(result.struct_thing.i64_thing, nestTestInput.struct_thing.i64_thing);
- equal(result.i32_thing, nestTestInput.i32_thing);
- equal(JSON.stringify(result), JSON.stringify(nestTestInput));
- QUnit.start();
+ assert.equal(result.byte_thing, nestTestInput.byte_thing);
+ assert.equal(result.struct_thing.string_thing, nestTestInput.struct_thing.string_thing);
+ assert.equal(result.struct_thing.byte_thing, nestTestInput.struct_thing.byte_thing);
+ assert.equal(result.struct_thing.i32_thing, nestTestInput.struct_thing.i32_thing);
+ assert.equal(result.struct_thing.i64_thing, nestTestInput.struct_thing.i64_thing);
+ assert.equal(result.i32_thing, nestTestInput.i32_thing);
+ assert.equal(JSON.stringify(result), JSON.stringify(nestTestInput));
+ done();
});
});
- asyncTest('Map', function() {
- expect(3);
- var mapTestInput = {7: 77, 8: 88, 9: 99};
+ QUnit.test('Map', function(assert) {
+ assert.expect(3);
+ const done = assert.async();
+ const mapTestInput = {7: 77, 8: 88, 9: 99};
client.testMap(mapTestInput, function(result) {
- for (var key in result) {
- equal(result[key], mapTestInput[key]);
+ for (let key in result) {
+ assert.equal(result[key], mapTestInput[key]);
}
- QUnit.start();
+ done();
});
});
- asyncTest('StringMap', function() {
- expect(6);
- var mapTestInput = {
+ QUnit.test('StringMap', function(assert) {
+ assert.expect(6);
+ const done = assert.async();
+ const mapTestInput = {
'a': '123', 'a b': 'with spaces ', 'same': 'same', '0': 'numeric key',
'longValue': stringTest, stringTest: 'long key'
};
client.testStringMap(mapTestInput, function(result) {
- for (var key in result) {
- equal(result[key], mapTestInput[key]);
+ for (let key in result) {
+ assert.equal(result[key], mapTestInput[key]);
}
- QUnit.start();
+ done();
});
});
- asyncTest('Set', function() {
- expect(1);
- var setTestInput = [1, 2, 3];
+ QUnit.test('Set', function(assert) {
+ assert.expect(1);
+ const done = assert.async();
+ const setTestInput = [1, 2, 3];
client.testSet(setTestInput, function(result) {
- ok(result, setTestInput);
- QUnit.start();
+ assert.ok(result, setTestInput);
+ done();
});
});
- asyncTest('List', function() {
- expect(1);
- var listTestInput = [1, 2, 3];
+ QUnit.test('List', function(assert) {
+ assert.expect(1);
+ const done = assert.async();
+ const listTestInput = [1, 2, 3];
client.testList(listTestInput, function(result) {
- ok(result, listTestInput);
- QUnit.start();
+ assert.ok(result, listTestInput);
+ done();
});
});
- asyncTest('Enum', function() {
- expect(1);
+ QUnit.test('Enum', function(assert) {
+ assert.expect(1);
+ const done = assert.async();
client.testEnum(ThriftTest.Numberz.ONE, function(result) {
- equal(result, ThriftTest.Numberz.ONE);
- QUnit.start();
+ assert.equal(result, ThriftTest.Numberz.ONE);
+ done();
});
});
- asyncTest('TypeDef', function() {
- expect(1);
+ QUnit.test('TypeDef', function(assert) {
+ assert.expect(1);
+ const done = assert.async();
client.testTypedef(69, function(result) {
- equal(result, 69);
- QUnit.start();
+ assert.equal(result, 69);
+ done();
});
});
-module('deeper!');
+QUnit.module('deeper!');
- asyncTest('MapMap', function() {
- expect(16);
- var mapMapTestExpectedResult = {
+ QUnit.test('MapMap', function(assert) {
+ assert.expect(16);
+ const done = assert.async();
+ const mapMapTestExpectedResult = {
'4': {'1': 1, '2': 2, '3': 3, '4': 4},
'-4': {'-4': -4, '-3': -3, '-2': -2, '-1': -1}
};
client.testMapMap(1, function(result) {
- for (var key in result) {
- for (var key2 in result[key]) {
- equal(result[key][key2], mapMapTestExpectedResult[key][key2]);
+ for (let key in result) {
+ for (let key2 in result[key]) {
+ assert.equal(result[key][key2], mapMapTestExpectedResult[key][key2]);
}
}
- checkRecursively(result, mapMapTestExpectedResult);
- QUnit.start();
+ checkRecursively(assert, result, mapMapTestExpectedResult);
+ done();
});
});
-module('Exception');
+QUnit.module('Exception');
- asyncTest('Xception', function() {
- expect(2);
+ QUnit.test('Xception', function(assert) {
+ assert.expect(2);
+ const done = assert.async();
client.testException('Xception', function(e) {
- equal(e.errorCode, 1001);
- equal(e.message, 'Xception');
- QUnit.start();
+ assert.equal(e.errorCode, 1001);
+ assert.equal(e.message, 'Xception');
+ done();
});
});
- asyncTest('no Exception', 0, function() {
- expect(1);
+ QUnit.test('no Exception', function(assert) {
+ assert.expect(1);
+ const done = assert.async();
client.testException('no Exception', function(e) {
- ok(!e);
- QUnit.start();
+ assert.ok(!e);
+ done();
});
});
-module('Insanity');
+QUnit.module('Insanity');
- asyncTest('testInsanity', function() {
- expect(24);
- var insanity = {
+ QUnit.test('testInsanity', function(assert) {
+ assert.expect(24);
+ const done = assert.async();
+ const insanity = {
'1': {
'2': {
'userMap': { '5': 5, '8': 8 },
@@ -338,19 +351,20 @@
'2': { '6': { 'userMap': null, 'xtructs': null } }
};
client.testInsanity(new ThriftTest.Insanity(), function(res) {
- ok(res, JSON.stringify(res));
- ok(insanity, JSON.stringify(insanity));
- checkRecursively(res, insanity);
- QUnit.start();
+ assert.ok(res, JSON.stringify(res));
+ assert.ok(insanity, JSON.stringify(insanity));
+ checkRecursively(assert, res, insanity);
+ done();
});
});
-module('Oneway');
+QUnit.module('Oneway');
- asyncTest('testOneway', function() {
- expect(1);
+ QUnit.test('testOneway', function(assert) {
+ assert.expect(1);
+ const done = assert.async();
client.testOneway(1, function(result) {
- equal(result, undefined);
- QUnit.start();
+ assert.equal(result, undefined);
+ done();
});
- });
\ No newline at end of file
+ });
diff --git a/lib/js/test/test-double-rendering.js b/lib/js/test/test-double-rendering.js
index 5d9cd2a..b4b79b8 100644
--- a/lib/js/test/test-double-rendering.js
+++ b/lib/js/test/test-double-rendering.js
@@ -46,7 +46,7 @@
*/
// double assertion threshold
-var EPSILON = 0.0000001;
+const EPSILON = 0.0000001;
// Work around for old API used by QUnitAdapter of jsTestDriver
if (typeof QUnit.log == 'function') {
@@ -67,17 +67,17 @@
QUnit.test('Double (rendering)', function(assert) {
console.log('Double rendering test -- starts');
- var EXPECTED_DOUBLE_ASSIGNED_TO_INT_CONSTANT = 1;
- var EXPECTED_DOUBLE_ASSIGNED_TO_NEGATIVE_INT_CONSTANT = -100;
- var EXPECTED_DOUBLE_ASSIGNED_TO_LARGEST_INT_CONSTANT = 9223372036854775807;
- var EXPECTED_DOUBLE_ASSIGNED_TO_SMALLEST_INT_CONSTANT = -9223372036854775807;
- var EXPECTED_DOUBLE_ASSIGNED_TO_DOUBLE_WITH_MANY_DECIMALS = 3.14159265359;
- var EXPECTED_DOUBLE_ASSIGNED_TO_FRACTIONAL_DOUBLE = 1000000.1;
- var EXPECTED_DOUBLE_ASSIGNED_TO_NEGATIVE_FRACTIONAL_DOUBLE = -1000000.1;
- var EXPECTED_DOUBLE_ASSIGNED_TO_LARGE_DOUBLE = 1.7e+308;
- var EXPECTED_DOUBLE_ASSIGNED_TO_LARGE_FRACTIONAL_DOUBLE = 9223372036854775816.43;
- var EXPECTED_DOUBLE_ASSIGNED_TO_SMALL_DOUBLE = -1.7e+308;
- var EXPECTED_DOUBLE_ASSIGNED_TO_NEGATIVE_BUT_LARGE_FRACTIONAL_DOUBLE = -9223372036854775816.43;
+ const EXPECTED_DOUBLE_ASSIGNED_TO_INT_CONSTANT = 1;
+ const EXPECTED_DOUBLE_ASSIGNED_TO_NEGATIVE_INT_CONSTANT = -100;
+ const EXPECTED_DOUBLE_ASSIGNED_TO_LARGEST_INT_CONSTANT = 9223372036854775807;
+ const EXPECTED_DOUBLE_ASSIGNED_TO_SMALLEST_INT_CONSTANT = -9223372036854775807;
+ const EXPECTED_DOUBLE_ASSIGNED_TO_DOUBLE_WITH_MANY_DECIMALS = 3.14159265359;
+ const EXPECTED_DOUBLE_ASSIGNED_TO_FRACTIONAL_DOUBLE = 1000000.1;
+ const EXPECTED_DOUBLE_ASSIGNED_TO_NEGATIVE_FRACTIONAL_DOUBLE = -1000000.1;
+ const EXPECTED_DOUBLE_ASSIGNED_TO_LARGE_DOUBLE = 1.7e+308;
+ const EXPECTED_DOUBLE_ASSIGNED_TO_LARGE_FRACTIONAL_DOUBLE = 9223372036854775816.43;
+ const EXPECTED_DOUBLE_ASSIGNED_TO_SMALL_DOUBLE = -1.7e+308;
+ const EXPECTED_DOUBLE_ASSIGNED_TO_NEGATIVE_BUT_LARGE_FRACTIONAL_DOUBLE = -9223372036854775816.43;
assert.ok(
Math.abs(EXPECTED_DOUBLE_ASSIGNED_TO_INT_CONSTANT - DOUBLE_ASSIGNED_TO_INT_CONSTANT_TEST) <= EPSILON);
assert.ok(
@@ -131,11 +131,11 @@
assert.equal(typeof DOUBLE_ASSIGNED_TO_LARGE_FRACTIONAL_DOUBLE_TEST, 'number');
assert.equal(typeof DOUBLE_ASSIGNED_TO_SMALL_DOUBLE_TEST, 'number');
assert.equal(typeof DOUBLE_ASSIGNED_TO_NEGATIVE_BUT_LARGE_FRACTIONAL_DOUBLE_TEST, 'number');
- var EXPECTED_DOUBLE_LIST =
+ const EXPECTED_DOUBLE_LIST =
[1,-100,100,9223372036854775807,-9223372036854775807,3.14159265359,1000000.1,-1000000.1,1.7e+308,-1.7e+308,
9223372036854775816.43,-9223372036854775816.43];
assert.equal(DOUBLE_LIST_TEST.length, EXPECTED_DOUBLE_LIST.length);
- for (var i = 0; i < EXPECTED_DOUBLE_LIST.length; ++i) {
+ for (let i = 0; i < EXPECTED_DOUBLE_LIST.length; ++i) {
assert.ok(Math.abs(EXPECTED_DOUBLE_LIST[i] - DOUBLE_LIST_TEST[i]) <= EPSILON);
}
console.log('Double rendering test -- ends');
diff --git a/lib/js/test/test-es6.html b/lib/js/test/test-es6.html
index 92d0738..5f55da7 100644
--- a/lib/js/test/test-es6.html
+++ b/lib/js/test/test-es6.html
@@ -23,11 +23,8 @@
<title>Thrift Javascript Bindings: Unit Test</title>
<script src="build/js/thrift.js" type="text/javascript" charset="utf-8"></script>
- <script src="gen-js/ThriftTest_types.js" type="text/javascript" charset="utf-8"></script>
- <script src="gen-js/ThriftTest.js" type="text/javascript" charset="utf-8"></script>
-
- <!-- ES6 Promise Polyfill -->
- <script type="text/javascript" src="build/js/lib/es6-promise.js" charset="utf-8"></script>
+ <script src="gen-js-es6/ThriftTest_types.js" type="text/javascript" charset="utf-8"></script>
+ <script src="gen-js-es6/ThriftTest.js" type="text/javascript" charset="utf-8"></script>
<!-- jQuery -->
<script type="text/javascript" src="build/js/lib/jquery.js" charset="utf-8"></script>
@@ -38,12 +35,12 @@
<!-- the Test Suite-->
<script>
- var loc = window.location;
- var ws_uri = ((loc.protocol === "https:") ? "wss://" : "ws://") +
+ const loc = window.location;
+ const ws_uri = ((loc.protocol === "https:") ? "wss://" : "ws://") +
loc.hostname + ":" + loc.port + loc.pathname;
- var transport = new Thrift.TWebSocketTransport(ws_uri);
- var protocol = new Thrift.Protocol(transport);
- var client = new ThriftTest.ThriftTestClient(protocol);
+ const transport = new Thrift.TWebSocketTransport(ws_uri);
+ const protocol = new Thrift.Protocol(transport);
+ const client = new ThriftTest.ThriftTestClient(protocol);
transport.open();
</script>
<script type="text/javascript" src="test-es6.js" charset="utf-8"></script>
diff --git a/lib/js/test/test-es6.js b/lib/js/test/test-es6.js
index a3a31dc..845171b 100644
--- a/lib/js/test/test-es6.js
+++ b/lib/js/test/test-es6.js
@@ -24,46 +24,48 @@
* (which is exclusively async).
*
* To compile client code for this test use:
- * $ thrift -gen js ThriftTest.thrift
+ * $ thrift -gen js:es6 ThriftTest.thrift
*/
// all Languages in UTF-8
-var 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, Norfuk / Pitkern, Polski, پنجابی, پښتو, 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ú, 粵語";
-function checkRecursively(map1, map2) {
+const 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, Norfuk / Pitkern, Polski, پنجابی, پښتو, 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ú, 粵語";
+
+function checkRecursively(assert, map1, map2) {
if (typeof map1 !== 'function' && typeof map2 !== 'function') {
if (!map1 || typeof map1 !== 'object') {
- equal(map1, map2);
+ assert.equal(map1, map2);
} else {
for (var key in map1) {
- checkRecursively(map1[key], map2[key]);
+ checkRecursively(assert, map1[key], map2[key]);
}
}
}
}
-module('Base Types');
+QUnit.module('Base Types');
- asyncTest('Void', function() {
- expect(1);
+ QUnit.test('Void', function( assert ) {
+ assert.expect(1);
+ const done = assert.async();
client.testVoid().then(function(result) {
- equal(result, undefined);
- QUnit.start();
+ assert.equal(result, undefined);
+ done();
});
});
- asyncTest('String', function() {
- expect(3);
- QUnit.stop(2);
+ QUnit.test('String', function( assert ) {
+ assert.expect(3);
+ const done = assert.async(3);
client.testString('').then(function(result) {
- equal(result, '');
- QUnit.start();
+ assert.equal(result, '');
+ done();
});
client.testString(stringTest).then(function(result) {
- equal(result, stringTest);
- QUnit.start();
+ assert.equal(result, stringTest);
+ done();
});
var specialCharacters = 'quote: \" backslash:' +
' forwardslash-escaped: \/ ' +
@@ -71,83 +73,84 @@
' now-all-of-them-together: "\\\/\b\n\r\t' +
' now-a-bunch-of-junk: !@#$%&()(&%$#{}{}<><><';
client.testString(specialCharacters).then(function(result) {
- equal(result, specialCharacters);
- QUnit.start();
+ assert.equal(result, specialCharacters);
+ done();
});
});
- asyncTest('Double', function() {
- expect(4);
- QUnit.stop(3);
+ QUnit.test('Double', function( assert ) {
+ assert.expect(4);
+ const done = assert.async(4);
client.testDouble(0).then(function(result) {
- equal(result, 0);
- QUnit.start();
+ assert.equal(result, 0);
+ done();
});
client.testDouble(-1).then(function(result) {
- equal(result, -1);
- QUnit.start();
+ assert.equal(result, -1);
+ done();
});
client.testDouble(3.14).then(function(result) {
- equal(result, 3.14);
- QUnit.start();
+ assert.equal(result, 3.14);
+ done();
});
client.testDouble(Math.pow(2, 60)).then(function(result) {
- equal(result, Math.pow(2, 60));
- QUnit.start();
+ assert.equal(result, Math.pow(2, 60));
+ done();
});
});
// TODO: add testBinary()
- asyncTest('Byte', function() {
- expect(2);
- QUnit.stop();
+ QUnit.test('Byte', function( assert ) {
+ assert.expect(2);
+ const done = assert.async(2);
client.testByte(0).then(function(result) {
- equal(result, 0);
- QUnit.start();
+ assert.equal(result, 0);
+ done();
});
client.testByte(0x01).then(function(result) {
- equal(result, 0x01);
- QUnit.start();
+ assert.equal(result, 0x01);
+ done();
});
});
- asyncTest('I32', function() {
- expect(3);
- QUnit.stop(2);
+ QUnit.test('I32', function( assert ) {
+ assert.expect(3);
+ const done = assert.async(3);
client.testI32(0).then(function(result) {
- equal(result, 0);
- QUnit.start();
+ assert.equal(result, 0);
+ done();
});
client.testI32(Math.pow(2, 30)).then(function(result) {
- equal(result, Math.pow(2, 30));
- QUnit.start();
+ assert.equal(result, Math.pow(2, 30));
+ done();
});
client.testI32(-Math.pow(2, 30)).then(function(result) {
- equal(result, -Math.pow(2, 30));
- QUnit.start();
+ assert.equal(result, -Math.pow(2, 30));
+ done();
});
});
- asyncTest('I64', function() {
- expect(3);
- QUnit.stop(2);
+ QUnit.test('I64', function( assert ) {
+ assert.expect(3);
+ const done = assert.async(3);
client.testI64(0).then(function(result) {
- equal(result, 0);
- QUnit.start();
+ assert.equal(result, 0);
+ done();
});
//This is usually 2^60 but JS cannot represent anything over 2^52 accurately
client.testI64(Math.pow(2, 52)).then(function(result) {
- equal(result, Math.pow(2, 52));
- QUnit.start();
+ assert.equal(result, Math.pow(2, 52));
+ done();
});
client.testI64(-Math.pow(2, 52)).then(function(result) {
- equal(result, -Math.pow(2, 52));
- QUnit.start();
+ assert.equal(result, -Math.pow(2, 52));
+ done();
});
});
-module('Structured Types');
+QUnit.module('Structured Types');
- asyncTest('Struct', function() {
- expect(5);
+ QUnit.test('Struct', function( assert ) {
+ assert.expect(5);
+ const done = assert.async();
var structTestInput = new ThriftTest.Xtruct();
structTestInput.string_thing = 'worked';
structTestInput.byte_thing = 0x01;
@@ -156,17 +159,18 @@
structTestInput.i64_thing = Math.pow(2, 52);
client.testStruct(structTestInput).then(function(result) {
- equal(result.string_thing, structTestInput.string_thing);
- equal(result.byte_thing, structTestInput.byte_thing);
- equal(result.i32_thing, structTestInput.i32_thing);
- equal(result.i64_thing, structTestInput.i64_thing);
- equal(JSON.stringify(result), JSON.stringify(structTestInput));
- QUnit.start();
+ assert.equal(result.string_thing, structTestInput.string_thing);
+ assert.equal(result.byte_thing, structTestInput.byte_thing);
+ assert.equal(result.i32_thing, structTestInput.i32_thing);
+ assert.equal(result.i64_thing, structTestInput.i64_thing);
+ assert.equal(JSON.stringify(result), JSON.stringify(structTestInput));
+ done();
});
});
- asyncTest('Nest', function() {
- expect(7);
+ QUnit.test('Nest', function( assert ) {
+ assert.expect(7);
+ const done = assert.async();
var xtrTestInput = new ThriftTest.Xtruct();
xtrTestInput.string_thing = 'worked';
xtrTestInput.byte_thing = 0x01;
@@ -180,31 +184,33 @@
nestTestInput.i32_thing = Math.pow(2, 15);
client.testNest(nestTestInput).then(function(result) {
- equal(result.byte_thing, nestTestInput.byte_thing);
- equal(result.struct_thing.string_thing, nestTestInput.struct_thing.string_thing);
- equal(result.struct_thing.byte_thing, nestTestInput.struct_thing.byte_thing);
- equal(result.struct_thing.i32_thing, nestTestInput.struct_thing.i32_thing);
- equal(result.struct_thing.i64_thing, nestTestInput.struct_thing.i64_thing);
- equal(result.i32_thing, nestTestInput.i32_thing);
- equal(JSON.stringify(result), JSON.stringify(nestTestInput));
- QUnit.start();
+ assert.equal(result.byte_thing, nestTestInput.byte_thing);
+ assert.equal(result.struct_thing.string_thing, nestTestInput.struct_thing.string_thing);
+ assert.equal(result.struct_thing.byte_thing, nestTestInput.struct_thing.byte_thing);
+ assert.equal(result.struct_thing.i32_thing, nestTestInput.struct_thing.i32_thing);
+ assert.equal(result.struct_thing.i64_thing, nestTestInput.struct_thing.i64_thing);
+ assert.equal(result.i32_thing, nestTestInput.i32_thing);
+ assert.equal(JSON.stringify(result), JSON.stringify(nestTestInput));
+ done();
});
});
- asyncTest('Map', function() {
- expect(3);
+ QUnit.test('Map', function( assert ) {
+ assert.expect(3);
+ const done = assert.async();
var mapTestInput = {7: 77, 8: 88, 9: 99};
client.testMap(mapTestInput).then(function(result) {
for (var key in result) {
- equal(result[key], mapTestInput[key]);
+ assert.equal(result[key], mapTestInput[key]);
}
- QUnit.start();
+ done();
});
});
- asyncTest('StringMap', function() {
- expect(6);
+ QUnit.test('StringMap', function( assert ) {
+ assert.expect(6);
+ const done = assert.async();
var mapTestInput = {
'a': '123', 'a b': 'with spaces ', 'same': 'same', '0': 'numeric key',
'longValue': stringTest, stringTest: 'long key'
@@ -212,51 +218,56 @@
client.testStringMap(mapTestInput).then(function(result) {
for (var key in result) {
- equal(result[key], mapTestInput[key]);
+ assert.equal(result[key], mapTestInput[key]);
}
- QUnit.start();
+ done();
});
});
- asyncTest('Set', function() {
- expect(1);
+ QUnit.test('Set', function( assert ) {
+ assert.expect(1);
+ const done = assert.async();
var setTestInput = [1, 2, 3];
client.testSet(setTestInput).then(function(result) {
- ok(result, setTestInput);
- QUnit.start();
+ assert.ok(result, setTestInput);
+ done();
});
});
- asyncTest('List', function() {
- expect(1);
+ QUnit.test('List', function( assert ) {
+ assert.expect(1);
+ const done = assert.async();
var listTestInput = [1, 2, 3];
client.testList(listTestInput).then(function(result) {
- ok(result, listTestInput);
- QUnit.start();
+ assert.ok(result, listTestInput);
+ done();
});
});
- asyncTest('Enum', function() {
- expect(1);
+ QUnit.test('Enum', function( assert ) {
+ assert.expect(1);
+ const done = assert.async();
client.testEnum(ThriftTest.Numberz.ONE).then(function(result) {
- equal(result, ThriftTest.Numberz.ONE);
- QUnit.start();
+ assert.equal(result, ThriftTest.Numberz.ONE);
+ done();
});
});
- asyncTest('TypeDef', function() {
- expect(1);
+ QUnit.test('TypeDef', function( assert ) {
+ assert.expect(1);
+ const done = assert.async();
client.testTypedef(69).then(function(result) {
- equal(result, 69);
- QUnit.start();
+ assert.equal(result, 69);
+ done();
});
});
-module('deeper!');
+QUnit.module('deeper!');
- asyncTest('MapMap', function() {
- expect(16);
+ QUnit.test('MapMap', function( assert ) {
+ assert.expect(16);
+ const done = assert.async();
var mapMapTestExpectedResult = {
'4': {'1': 1, '2': 2, '3': 3, '4': 4},
'-4': {'-4': -4, '-3': -3, '-2': -2, '-1': -1}
@@ -265,40 +276,48 @@
client.testMapMap(1).then(function(result) {
for (var key in result) {
for (var key2 in result[key]) {
- equal(result[key][key2], mapMapTestExpectedResult[key][key2]);
+ assert.equal(result[key][key2], mapMapTestExpectedResult[key][key2]);
}
}
- checkRecursively(result, mapMapTestExpectedResult);
- QUnit.start();
+ checkRecursively(assert, result, mapMapTestExpectedResult);
+ done();
});
});
-module('Exception');
+QUnit.module('Exception');
- asyncTest('Xception', function() {
- expect(2);
+ QUnit.test('Xception', function( assert ) {
+ assert.expect(2);
+ const done = assert.async();
client.testException('Xception').then(function(res) {
- ok(false);
+ assert.ok(false);
}).catch(function(e) {
- equal(e.errorCode, 1001);
- equal(e.message, 'Xception');
- QUnit.start();
+
+ console.log(`Exception exception e`);
+ console.log(e);
+ console.log(JSON.stringify(e, null, 2));
+
+ assert.equal(e.errorCode, 1001);
+ assert.equal(e.message, 'Xception');
+ done();
});
});
- asyncTest('no Exception', 0, function() {
- expect(1);
+ QUnit.test('no Exception', function( assert ) {
+ assert.expect(1);
+ const done = assert.async();
client.testException('no Exception').then(function(e) {
- ok(!e);
- QUnit.start();
+ assert.ok(!e);
+ done();
});
});
-module('Insanity');
+QUnit.module('Insanity');
- asyncTest('testInsanity', function() {
- expect(24);
+ QUnit.test('testInsanity', function( assert ) {
+ assert.expect(24);
+ const done = assert.async();
var insanity = {
'1': {
'2': {
@@ -337,18 +356,19 @@
'2': { '6': { 'userMap': null, 'xtructs': null } }
};
client.testInsanity(new ThriftTest.Insanity()).then(function(res) {
- ok(res, JSON.stringify(res));
- ok(insanity, JSON.stringify(insanity));
- checkRecursively(res, insanity);
- QUnit.start();
+ assert.ok(res, JSON.stringify(res));
+ assert.ok(insanity, JSON.stringify(insanity));
+ checkRecursively(assert, res, insanity);
+ done();
});
});
-module('Oneway');
- asyncTest('testOneway', function() {
- expect(1);
+QUnit.module('Oneway');
+ QUnit.test('testOneway', function( assert ) {
+ assert.expect(1);
+ const done = assert.async();
client.testOneway(1).then(function(result) {
- equal(result, undefined);
- QUnit.start();
+ assert.equal(result, undefined);
+ done();
});
- });
\ No newline at end of file
+ });
diff --git a/lib/js/test/test-jq.js b/lib/js/test/test-jq.js
index d8649a0..f62bb95 100644
--- a/lib/js/test/test-jq.js
+++ b/lib/js/test/test-jq.js
@@ -33,19 +33,18 @@
//////////////////////////////////
//jQuery asynchronous tests
jQuery.ajaxSetup({ timeout: 0 });
-$(document).ajaxError(function() { QUnit.start(); });
-module('jQ Async Manual');
+QUnit.module('jQ Async Manual');
- test('testI32', function() {
- expect(2);
- QUnit.stop();
+ QUnit.test('testI32', function(assert) {
+ assert.expect(2);
+ const done = assert.async(2);
- var transport = new Thrift.Transport();
- var protocol = new Thrift.Protocol(transport);
- var client = new ThriftTest.ThriftTestClient(protocol);
+ const transport = new Thrift.Transport();
+ const protocol = new Thrift.Protocol(transport);
+ const client = new ThriftTest.ThriftTestClient(protocol);
- var jqxhr = jQuery.ajax({
+ const jqxhr = jQuery.ajax({
url: '/service',
data: client.send_testI32(Math.pow(-2, 31)),
type: 'POST',
@@ -53,23 +52,24 @@
dataType: 'text',
success: function(res) {
transport.setRecvBuffer(res);
- equal(client.recv_testI32(), Math.pow(-2, 31));
+ assert.equal(client.recv_testI32(), Math.pow(-2, 31));
+ done();
},
- error: function() { ok(false); },
+ error: function() { assert.ok(false); },
complete: function() {
- ok(true);
- QUnit.start();
+ assert.ok(true);
+ done();
}
});
});
- test('testI64', function() {
- expect(2);
- QUnit.stop();
+ QUnit.test('testI64', function(assert) {
+ assert.expect(2);
+ const done = assert.async(2);
- var transport = new Thrift.Transport();
- var protocol = new Thrift.Protocol(transport);
- var client = new ThriftTest.ThriftTestClient(protocol);
+ const transport = new Thrift.Transport();
+ const protocol = new Thrift.Protocol(transport);
+ const client = new ThriftTest.ThriftTestClient(protocol);
jQuery.ajax({
url: '/service',
@@ -81,78 +81,79 @@
success: function(res) {
transport.setRecvBuffer(res);
//This is usually 2^61 but JS cannot represent anything over 2^52 accurately
- equal(client.recv_testI64(), Math.pow(-2, 52));
+ assert.equal(client.recv_testI64(), Math.pow(-2, 52));
+ done();
},
- error: function() { ok(false); },
+ error: function() { assert.ok(false); },
complete: function() {
- ok(true);
- QUnit.start();
+ assert.ok(true);
+ done();
}
});
});
-module('jQ Async');
- test('I32', function() {
- expect(3);
+QUnit.module('jQ Async');
+ QUnit.test('I32', function(assert) {
+ assert.expect(3);
- QUnit.stop();
+ const done = assert.async(3);
client.testI32(Math.pow(2, 30), function(result) {
- equal(result, Math.pow(2, 30));
- QUnit.start();
+ assert.equal(result, Math.pow(2, 30));
+ done();
});
- QUnit.stop();
- var jqxhr = client.testI32(Math.pow(-2, 31), function(result) {
- equal(result, Math.pow(-2, 31));
+ const jqxhr = client.testI32(Math.pow(-2, 31), function(result) {
+ assert.equal(result, Math.pow(-2, 31));
+ done();
});
jqxhr.success(function(result) {
- equal(result, Math.pow(-2, 31));
- QUnit.start();
+ assert.equal(result, Math.pow(-2, 31));
+ done();
});
});
- test('I64', function() {
- expect(4);
+ QUnit.test('I64', function(assert) {
+ assert.expect(4);
- QUnit.stop();
+ const done = assert.async(4);
//This is usually 2^60 but JS cannot represent anything over 2^52 accurately
client.testI64(Math.pow(2, 52), function(result) {
- equal(result, Math.pow(2, 52));
- QUnit.start();
+ assert.equal(result, Math.pow(2, 52));
+ done();
});
- QUnit.stop();
//This is usually 2^60 but JS cannot represent anything over 2^52 accurately
client.testI64(Math.pow(-2, 52), function(result) {
- equal(result, Math.pow(-2, 52));
+ assert.equal(result, Math.pow(-2, 52));
+ done();
})
- .error(function(xhr, status, e) { ok(false, e.message); })
+ .error(function(xhr, status, e) { assert.ok(false, e.message); })
.success(function(result) {
//This is usually 2^60 but JS cannot represent anything over 2^52 accurately
- equal(result, Math.pow(-2, 52));
+ assert.equal(result, Math.pow(-2, 52));
+ done();
})
.complete(function() {
- ok(true);
- QUnit.start();
+ assert.ok(true);
+ done();
});
});
- test('Xception', function() {
- expect(2);
+ QUnit.test('Xception', function(assert) {
+ assert.expect(2);
- QUnit.stop();
+ const done = assert.async(2);
- var dfd = client.testException('Xception', function(result) {
- ok(false);
- QUnit.start();
+ const dfd = client.testException('Xception', function(result) {
+ assert.ok(false);
+ done();
})
.error(function(xhr, status, e) {
- equal(e.errorCode, 1001);
- equal(e.message, 'Xception');
- //QUnit.start();
- //Note start is not required here because:
- //$(document).ajaxError( function() { QUnit.start(); } );
+ assert.equal(e.errorCode, 1001);
+ assert.equal(e.message, 'Xception');
+ done();
+ $(document).ajaxError( function() { done(); } );
});
});
diff --git a/lib/js/test/test-nojq.html b/lib/js/test/test-nojq.html
index 541bffe..9eec7fc 100644
--- a/lib/js/test/test-nojq.html
+++ b/lib/js/test/test-nojq.html
@@ -29,7 +29,7 @@
<!-- QUnit Test framework-->
<script type="text/javascript" src="build/js/lib/qunit.js" charset="utf-8"></script>
<link rel="stylesheet" href="build/js/lib/qunit.css" type="text/css" media="screen" />
-
+
<!-- the Test Suite-->
<script type="text/javascript" src="test.js" charset="utf-8"></script>
<script type="text/javascript" src="test-nojq.js" charset="utf-8"></script>
@@ -37,7 +37,7 @@
<body>
<h1 id="qunit-header">Thrift Javascript Bindings: Unit Test (<a href="https://git-wip-us.apache.org/repos/asf?p=thrift.git;a=blob;f=test/ThriftTest.thrift;hb=HEAD">ThriftTest.thrift</a>)</h1>
<h2 id="qunit-banner"></h2>
- <div id="qunit-testrunner-toolbar"></div>
+ <div id="qunit-testrunner-toolbar"></div>
<h2 id="qunit-userAgent"></h2>
<ol id="qunit-tests"><li><!-- get valid xhtml strict--></li></ol>
<!-- Uncomment this to check the validity. This significantly slows down the test.
diff --git a/lib/js/test/test-nojq.js b/lib/js/test/test-nojq.js
index c4f3cf7..2b801d2 100644
--- a/lib/js/test/test-nojq.js
+++ b/lib/js/test/test-nojq.js
@@ -33,17 +33,16 @@
//////////////////////////////////
//Async exception tests
-module('NojQ Async');
+QUnit.module('NojQ Async');
- test('Xception', function() {
- expect(2);
-
- QUnit.stop();
+QUnit.test('Xception', function(assert) {
+ assert.expect(2);
+ const done = assert.async();
client.testException('Xception', function(result) {
- equal(result.errorCode, 1001);
- equal(result.message, 'Xception');
- QUnit.start();
+ assert.equal(result.errorCode, 1001);
+ assert.equal(result.message, 'Xception');
+ done();
});
});
diff --git a/lib/js/test/test.html b/lib/js/test/test.html
index edec3a3..af035b6 100755
--- a/lib/js/test/test.html
+++ b/lib/js/test/test.html
@@ -23,8 +23,8 @@
<title>Thrift Javascript Bindings: Unit Test</title>
<script src="build/js/thrift.js" type="text/javascript" charset="utf-8"></script>
- <script src="gen-js/ThriftTest_types.js" type="text/javascript" charset="utf-8"></script>
- <script src="gen-js/ThriftTest.js" type="text/javascript" charset="utf-8"></script>
+ <script src="gen-js-jquery/ThriftTest_types.js" type="text/javascript" charset="utf-8"></script>
+ <script src="gen-js-jquery/ThriftTest.js" type="text/javascript" charset="utf-8"></script>
<!-- jQuery -->
<script type="text/javascript" src="build/js/lib/jquery.js" charset="utf-8"></script>
@@ -34,11 +34,6 @@
<link rel="stylesheet" href="build/js/lib/qunit.css" type="text/css" media="screen" />
<!-- the Test Suite-->
- <script>
- var transport = new Thrift.Transport("/service");
- var protocol = new Thrift.Protocol(transport);
- var client = new ThriftTest.ThriftTestClient(protocol);
- </script>
<script type="text/javascript" src="test.js" charset="utf-8"></script>
<script type="text/javascript" src="test-jq.js" charset="utf-8"></script>
</head>
diff --git a/lib/js/test/test.js b/lib/js/test/test.js
index e3b8d51..a86a509 100755
--- a/lib/js/test/test.js
+++ b/lib/js/test/test.js
@@ -47,9 +47,9 @@
* ++ test-jq.js for "-gen js:jquery" only tests
*/
-var transport = new Thrift.Transport('/service');
-var protocol = new Thrift.Protocol(transport);
-var client = new ThriftTest.ThriftTestClient(protocol);
+const transport = new Thrift.Transport('/service');
+const protocol = new Thrift.Protocol(transport);
+const client = new ThriftTest.ThriftTestClient(protocol);
// Work around for old API used by QUnitAdapter of jsTestDriver
if (typeof QUnit.log == 'function') {
@@ -67,170 +67,170 @@
}
// all Languages in UTF-8
-var 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, Norfuk / Pitkern, Polski, پنجابی, پښتو, 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 = "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, Norfuk / Pitkern, Polski, پنجابی, پښتو, 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ú, 粵語";
-function checkRecursively(map1, map2) {
+function checkRecursively(assert, map1, map2) {
if (typeof map1 !== 'function' && typeof map2 !== 'function') {
if (!map1 || typeof map1 !== 'object') {
- equal(map1, map2);
+ assert.equal(map1, map2);
} else {
- for (var key in map1) {
- checkRecursively(map1[key], map2[key]);
+ for (let key in map1) {
+ checkRecursively(assert, map1[key], map2[key]);
}
}
}
}
-module('Base Types');
+QUnit.module('Base Types');
- test('Void', function() {
- equal(client.testVoid(), undefined);
+ QUnit.test('Void', function(assert) {
+ assert.equal(client.testVoid(), undefined);
});
- test('Binary (String)', function() {
- var binary = '';
- for (var v = 255; v >= 0; --v) {
+ QUnit.test('Binary (String)', function(assert) {
+ let binary = '';
+ for (let v = 255; v >= 0; --v) {
binary += String.fromCharCode(v);
}
- equal(client.testBinary(binary), binary);
+ assert.equal(client.testBinary(binary), binary);
});
- test('Binary (Uint8Array)', function() {
- var binary = '';
- for (var v = 255; v >= 0; --v) {
+ QUnit.test('Binary (Uint8Array)', function(assert) {
+ let binary = '';
+ for (let v = 255; v >= 0; --v) {
binary += String.fromCharCode(v);
}
- var arr = new Uint8Array(binary.length);
- for (var i = 0; i < binary.length; ++i) {
+ const arr = new Uint8Array(binary.length);
+ for (let i = 0; i < binary.length; ++i) {
arr[i] = binary[i].charCodeAt();
}
- equal(client.testBinary(arr), binary);
+ assert.equal(client.testBinary(arr), binary);
});
- test('String', function() {
- equal(client.testString(''), '');
- equal(client.testString(stringTest), stringTest);
+ QUnit.test('String', function(assert) {
+ assert.equal(client.testString(''), '');
+ assert.equal(client.testString(stringTest), stringTest);
- var specialCharacters = 'quote: \" backslash:' +
+ const 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: !@#$%&()(&%$#{}{}<><><';
- equal(client.testString(specialCharacters), specialCharacters);
+ assert.equal(client.testString(specialCharacters), specialCharacters);
});
- test('Double', function() {
- equal(client.testDouble(0), 0);
- equal(client.testDouble(-1), -1);
- equal(client.testDouble(3.14), 3.14);
- equal(client.testDouble(Math.pow(2, 60)), Math.pow(2, 60));
+ QUnit.test('Double', function(assert) {
+ assert.equal(client.testDouble(0), 0);
+ assert.equal(client.testDouble(-1), -1);
+ assert.equal(client.testDouble(3.14), 3.14);
+ assert.equal(client.testDouble(Math.pow(2, 60)), Math.pow(2, 60));
});
- test('Byte', function() {
- equal(client.testByte(0), 0);
- equal(client.testByte(0x01), 0x01);
+ QUnit.test('Byte', function(assert) {
+ assert.equal(client.testByte(0), 0);
+ assert.equal(client.testByte(0x01), 0x01);
});
- test('I32', function() {
- equal(client.testI32(0), 0);
- equal(client.testI32(Math.pow(2, 30)), Math.pow(2, 30));
- equal(client.testI32(-Math.pow(2, 30)), -Math.pow(2, 30));
+ QUnit.test('I32', function(assert) {
+ assert.equal(client.testI32(0), 0);
+ assert.equal(client.testI32(Math.pow(2, 30)), Math.pow(2, 30));
+ assert.equal(client.testI32(-Math.pow(2, 30)), -Math.pow(2, 30));
});
- test('I64', function() {
- equal(client.testI64(0), 0);
+ QUnit.test('I64', function(assert) {
+ assert.equal(client.testI64(0), 0);
//This is usually 2^60 but JS cannot represent anything over 2^52 accurately
- equal(client.testI64(Math.pow(2, 52)), Math.pow(2, 52));
- equal(client.testI64(-Math.pow(2, 52)), -Math.pow(2, 52));
+ assert.equal(client.testI64(Math.pow(2, 52)), Math.pow(2, 52));
+ assert.equal(client.testI64(-Math.pow(2, 52)), -Math.pow(2, 52));
});
-module('Structured Types');
+QUnit.module('Structured Types');
- test('Struct', function() {
- var structTestInput = new ThriftTest.Xtruct();
+ QUnit.test('Struct', function(assert) {
+ const structTestInput = new ThriftTest.Xtruct();
structTestInput.string_thing = 'worked';
structTestInput.byte_thing = 0x01;
structTestInput.i32_thing = Math.pow(2, 30);
//This is usually 2^60 but JS cannot represent anything over 2^52 accurately
structTestInput.i64_thing = Math.pow(2, 52);
- var structTestOutput = client.testStruct(structTestInput);
+ const structTestOutput = client.testStruct(structTestInput);
- equal(structTestOutput.string_thing, structTestInput.string_thing);
- equal(structTestOutput.byte_thing, structTestInput.byte_thing);
- equal(structTestOutput.i32_thing, structTestInput.i32_thing);
- equal(structTestOutput.i64_thing, structTestInput.i64_thing);
+ assert.equal(structTestOutput.string_thing, structTestInput.string_thing);
+ assert.equal(structTestOutput.byte_thing, structTestInput.byte_thing);
+ assert.equal(structTestOutput.i32_thing, structTestInput.i32_thing);
+ assert.equal(structTestOutput.i64_thing, structTestInput.i64_thing);
- equal(JSON.stringify(structTestOutput), JSON.stringify(structTestInput));
+ assert.equal(JSON.stringify(structTestOutput), JSON.stringify(structTestInput));
});
- test('Nest', function() {
- var xtrTestInput = new ThriftTest.Xtruct();
+ QUnit.test('Nest', function(assert) {
+ const xtrTestInput = new ThriftTest.Xtruct();
xtrTestInput.string_thing = 'worked';
xtrTestInput.byte_thing = 0x01;
xtrTestInput.i32_thing = Math.pow(2, 30);
//This is usually 2^60 but JS cannot represent anything over 2^52 accurately
xtrTestInput.i64_thing = Math.pow(2, 52);
- var nestTestInput = new ThriftTest.Xtruct2();
+ const nestTestInput = new ThriftTest.Xtruct2();
nestTestInput.byte_thing = 0x02;
nestTestInput.struct_thing = xtrTestInput;
nestTestInput.i32_thing = Math.pow(2, 15);
- var nestTestOutput = client.testNest(nestTestInput);
+ const nestTestOutput = client.testNest(nestTestInput);
- equal(nestTestOutput.byte_thing, nestTestInput.byte_thing);
- equal(nestTestOutput.struct_thing.string_thing, nestTestInput.struct_thing.string_thing);
- equal(nestTestOutput.struct_thing.byte_thing, nestTestInput.struct_thing.byte_thing);
- equal(nestTestOutput.struct_thing.i32_thing, nestTestInput.struct_thing.i32_thing);
- equal(nestTestOutput.struct_thing.i64_thing, nestTestInput.struct_thing.i64_thing);
- equal(nestTestOutput.i32_thing, nestTestInput.i32_thing);
+ assert.equal(nestTestOutput.byte_thing, nestTestInput.byte_thing);
+ assert.equal(nestTestOutput.struct_thing.string_thing, nestTestInput.struct_thing.string_thing);
+ assert.equal(nestTestOutput.struct_thing.byte_thing, nestTestInput.struct_thing.byte_thing);
+ assert.equal(nestTestOutput.struct_thing.i32_thing, nestTestInput.struct_thing.i32_thing);
+ assert.equal(nestTestOutput.struct_thing.i64_thing, nestTestInput.struct_thing.i64_thing);
+ assert.equal(nestTestOutput.i32_thing, nestTestInput.i32_thing);
- equal(JSON.stringify(nestTestOutput), JSON.stringify(nestTestInput));
+ assert.equal(JSON.stringify(nestTestOutput), JSON.stringify(nestTestInput));
});
- test('Map', function() {
- var mapTestInput = {7: 77, 8: 88, 9: 99};
+ QUnit.test('Map', function(assert) {
+ const mapTestInput = {7: 77, 8: 88, 9: 99};
- var mapTestOutput = client.testMap(mapTestInput);
+ const mapTestOutput = client.testMap(mapTestInput);
- for (var key in mapTestOutput) {
- equal(mapTestOutput[key], mapTestInput[key]);
+ for (let key in mapTestOutput) {
+ assert.equal(mapTestOutput[key], mapTestInput[key]);
}
});
- test('StringMap', function() {
- var mapTestInput = {
+ QUnit.test('StringMap', function(assert) {
+ const mapTestInput = {
'a': '123', 'a b': 'with spaces ', 'same': 'same', '0': 'numeric key',
'longValue': stringTest, stringTest: 'long key'
};
- var mapTestOutput = client.testStringMap(mapTestInput);
+ const mapTestOutput = client.testStringMap(mapTestInput);
- for (var key in mapTestOutput) {
- equal(mapTestOutput[key], mapTestInput[key]);
+ for (let key in mapTestOutput) {
+ assert.equal(mapTestOutput[key], mapTestInput[key]);
}
});
- test('Set', function() {
- var setTestInput = [1, 2, 3];
- ok(client.testSet(setTestInput), setTestInput);
+ QUnit.test('Set', function(assert) {
+ const setTestInput = [1, 2, 3];
+ assert.ok(client.testSet(setTestInput), setTestInput);
});
- test('List', function() {
- var listTestInput = [1, 2, 3];
- ok(client.testList(listTestInput), listTestInput);
+ QUnit.test('List', function(assert) {
+ const listTestInput = [1, 2, 3];
+ assert.ok(client.testList(listTestInput), listTestInput);
});
- test('Enum', function() {
- equal(client.testEnum(ThriftTest.Numberz.ONE), ThriftTest.Numberz.ONE);
+ QUnit.test('Enum', function(assert) {
+ assert.equal(client.testEnum(ThriftTest.Numberz.ONE), ThriftTest.Numberz.ONE);
});
- test('TypeDef', function() {
- equal(client.testTypedef(69), 69);
+ QUnit.test('TypeDef', function(assert) {
+ assert.equal(client.testTypedef(69), 69);
});
- test('Skip', function() {
- var structTestInput = new ThriftTest.Xtruct();
- var modifiedClient = new ThriftTest.ThriftTestClient(protocol);
+ QUnit.test('Skip', function(assert) {
+ const structTestInput = new ThriftTest.Xtruct();
+ const modifiedClient = new ThriftTest.ThriftTestClient(protocol);
modifiedClient.recv_testStruct = function() {
- var input = modifiedClient.input;
- var xtruct3 = new ThriftTest.Xtruct3();
+ const input = modifiedClient.input;
+ const xtruct3 = new ThriftTest.Xtruct3();
input.readMessageBegin();
input.readStructBegin();
@@ -254,74 +254,79 @@
structTestInput.i32_thing = Math.pow(2, 30);
structTestInput.i64_thing = Math.pow(2, 52);
- var structTestOutput = modifiedClient.testStruct(structTestInput);
+ const structTestOutput = modifiedClient.testStruct(structTestInput);
- equal(structTestOutput instanceof ThriftTest.Xtruct3, true);
- equal(structTestOutput.string_thing, structTestInput.string_thing);
- equal(structTestOutput.changed, null);
- equal(structTestOutput.i32_thing, structTestInput.i32_thing);
- equal(structTestOutput.i64_thing, structTestInput.i64_thing);
+ assert.equal(structTestOutput instanceof ThriftTest.Xtruct3, true);
+ assert.equal(structTestOutput.string_thing, structTestInput.string_thing);
+ assert.equal(structTestOutput.changed, null);
+ assert.equal(structTestOutput.i32_thing, structTestInput.i32_thing);
+ assert.equal(structTestOutput.i64_thing, structTestInput.i64_thing);
});
-module('deeper!');
+QUnit.module('deeper!');
- test('MapMap', function() {
- var mapMapTestExpectedResult = {
+ QUnit.test('MapMap', function(assert) {
+ const mapMapTestExpectedResult = {
'4': {'1': 1, '2': 2, '3': 3, '4': 4},
'-4': {'-4': -4, '-3': -3, '-2': -2, '-1': -1}
};
- var mapMapTestOutput = client.testMapMap(1);
+ const mapMapTestOutput = client.testMapMap(1);
- for (var key in mapMapTestOutput) {
- for (var key2 in mapMapTestOutput[key]) {
- equal(mapMapTestOutput[key][key2], mapMapTestExpectedResult[key][key2]);
+ for (let key in mapMapTestOutput) {
+ for (let key2 in mapMapTestOutput[key]) {
+ assert.equal(mapMapTestOutput[key][key2], mapMapTestExpectedResult[key][key2]);
}
}
- checkRecursively(mapMapTestOutput, mapMapTestExpectedResult);
+ checkRecursively(assert, mapMapTestOutput, mapMapTestExpectedResult);
});
-module('Exception');
+QUnit.module('Exception');
- test('Xception', function() {
- expect(2);
+ QUnit.test('Xception', function(assert) {
+ assert.expect(2);
+ const done = assert.async();
try {
client.testException('Xception');
+ assert.ok(false);
}catch (e) {
- equal(e.errorCode, 1001);
- equal(e.message, 'Xception');
+ assert.equal(e.errorCode, 1001);
+ assert.equal(e.message, 'Xception');
+ done();
}
});
- test('no Exception', 0, function() {
+ QUnit.test('no Exception', function(assert) {
+ assert.expect(1);
try {
client.testException('no Exception');
+ assert.ok(true);
}catch (e) {
- ok(false);
+ assert.ok(false);
}
});
- test('TException', function() {
+ QUnit.test('TException', function(assert) {
//ThriftTest does not list TException as a legal exception so it will
// generate an exception on the server that does not propagate back to
// the client. This test has been modified to equate to "no exception"
- expect(1);
+ assert.expect(1);
try {
client.testException('TException');
} catch (e) {
- //ok(false);
+ //assert.ok(false);
}
- ok(true);
+ assert.ok(true);
});
-module('Insanity');
+QUnit.module('Insanity');
- var crazy = {
+ const crazy = {
'userMap': { '5': 5, '8': 8 },
'xtructs': [{
'string_thing': 'Goodbye4',
@@ -336,77 +341,75 @@
'i64_thing': 2
}]
};
- test('testInsanity', function() {
- var insanity = {
+ QUnit.test('testInsanity', function(assert) {
+ const insanity = {
'1': {
'2': crazy,
'3': crazy
},
'2': { '6': { 'userMap': null, 'xtructs': null } }
};
- var res = client.testInsanity(new ThriftTest.Insanity(crazy));
- ok(res, JSON.stringify(res));
- ok(insanity, JSON.stringify(insanity));
+ const res = client.testInsanity(new ThriftTest.Insanity(crazy));
+ assert.ok(res, JSON.stringify(res));
+ assert.ok(insanity, JSON.stringify(insanity));
- checkRecursively(res, insanity);
+ checkRecursively(assert, res, insanity);
});
//////////////////////////////////
//Run same tests asynchronously
-module('Async');
+QUnit.module('Async');
- test('Double', function() {
- expect(1);
+ QUnit.test('Double', function(assert) {
+ assert.expect(1);
- QUnit.stop();
+ const done = assert.async();
client.testDouble(3.14159265, function(result) {
- equal(result, 3.14159265);
- QUnit.start();
+ assert.equal(result, 3.14159265);
+ done();
});
});
- test('Byte', function() {
- expect(1);
+ QUnit.test('Byte', function(assert) {
+ assert.expect(1);
- QUnit.stop();
+ const done = assert.async();
client.testByte(0x01, function(result) {
- equal(result, 0x01);
- QUnit.start();
+ assert.equal(result, 0x01);
+ done();
});
});
- test('I32', function() {
- expect(2);
+ QUnit.test('I32', function(assert) {
+ assert.expect(2);
- QUnit.stop();
+ const done = assert.async(2);
client.testI32(Math.pow(2, 30), function(result) {
- equal(result, Math.pow(2, 30));
- QUnit.start();
+ assert.equal(result, Math.pow(2, 30));
+ done();
});
- QUnit.stop();
client.testI32(Math.pow(-2, 31), function(result) {
- equal(result, Math.pow(-2, 31));
- QUnit.start();
+ assert.equal(result, Math.pow(-2, 31));
+ done();
});
});
- test('I64', function() {
- expect(2);
+ QUnit.test('I64', function(assert) {
+ assert.expect(2);
- QUnit.stop();
+ const done = assert.async(2);
//This is usually 2^60 but JS cannot represent anything over 2^52 accurately
client.testI64(Math.pow(2, 52), function(result) {
- equal(result, Math.pow(2, 52));
- QUnit.start();
+ assert.equal(result, Math.pow(2, 52));
+ done();
});
- QUnit.stop();
//This is usually 2^60 but JS cannot represent anything over 2^52 accurately
client.testI64(Math.pow(-2, 52), function(result) {
- equal(result, Math.pow(-2, 52));
- QUnit.start();
+ assert.equal(result, Math.pow(-2, 52));
+ done();
});
});
diff --git a/lib/js/test/test_handler.js b/lib/js/test/test_handler.js
index 496b5e0..af5f7bd 100644
--- a/lib/js/test/test_handler.js
+++ b/lib/js/test/test_handler.js
@@ -20,10 +20,12 @@
//This is the server side Node test handler for the standard
// Apache Thrift test service.
-var ttypes = require('./gen-nodejs/ThriftTest_types');
-var TException = require('../../nodejs/lib/thrift').TException;
+const es6Mode = process.argv.includes('--es6');
+const genFolder = es6Mode ? 'gen-nodejs-es6' : 'gen-nodejs';
+const ttypes = require(`./${genFolder}/ThriftTest_types`);
+const TException = require('../../nodejs/lib/thrift').TException;
-var ThriftTestHandler = exports.ThriftTestHandler = {
+exports.ThriftTestHandler = {
testVoid: function(result) {
console.log('testVoid()');
result(null);
@@ -99,10 +101,10 @@
testMapMap: function(hello, result) {
console.log('testMapMap(' + hello + ')');
- var mapmap = [];
- var pos = [];
- var neg = [];
- for (var i = 1; i < 5; i++) {
+ const mapmap = [];
+ const pos = [];
+ const neg = [];
+ for (let i = 1; i < 5; i++) {
pos[i] = i;
neg[-i] = -i;
}
@@ -116,34 +118,34 @@
console.log(argument);
console.log(')');
- var hello = new ttypes.Xtruct();
+ const 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();
+ const 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();
+ const 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 = [];
+ const first_map = [];
+ const second_map = [];
first_map[ttypes.Numberz.TWO] = crazy;
first_map[ttypes.Numberz.THREE] = crazy;
- 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;
@@ -154,7 +156,7 @@
testMulti: function(arg0, arg1, arg2, arg3, arg4, arg5, result) {
console.log('testMulti()');
- var hello = new ttypes.Xtruct();
+ const hello = new ttypes.Xtruct();
hello.string_thing = 'Hello2';
hello.byte_thing = arg0;
hello.i32_thing = arg1;
@@ -164,7 +166,7 @@
testException: function(arg, result) {
console.log('testException(' + arg + ')');
if (arg === 'Xception') {
- var x = new ttypes.Xception();
+ const x = new ttypes.Xception();
x.errorCode = 1001;
x.message = arg;
result(x);
@@ -177,19 +179,19 @@
testMultiException: function(arg0, arg1, result) {
console.log('testMultiException(' + arg0 + ', ' + arg1 + ')');
if (arg0 === ('Xception')) {
- var x = new ttypes.Xception();
+ const x = new ttypes.Xception();
x.errorCode = 1001;
x.message = 'This is an Xception';
result(x);
} else if (arg0 === ('Xception2')) {
- var x2 = new ttypes.Xception2();
+ const x2 = new ttypes.Xception2();
x2.errorCode = 2002;
x2.struct_thing = new ttypes.Xtruct();
x2.struct_thing.string_thing = 'This is an Xception2';
result(x2);
}
- var res = new ttypes.Xtruct();
+ const res = new ttypes.Xtruct();
res.string_thing = arg1;
result(null, res);
},
diff --git a/lib/js/test/testws.html b/lib/js/test/testws.html
index f99a146..1edf0e0 100644
--- a/lib/js/test/testws.html
+++ b/lib/js/test/testws.html
@@ -35,12 +35,12 @@
<!-- the Test Suite-->
<script>
- var loc = window.location;
- var ws_uri = ((loc.protocol === "https:") ? "wss://" : "ws://") +
+ const loc = window.location;
+ const ws_uri = ((loc.protocol === "https:") ? "wss://" : "ws://") +
loc.hostname + ":" + loc.port + loc.pathname;
- var transport = new Thrift.TWebSocketTransport(ws_uri);
- var protocol = new Thrift.Protocol(transport);
- var client = new ThriftTest.ThriftTestClient(protocol);
+ const transport = new Thrift.TWebSocketTransport(ws_uri);
+ const protocol = new Thrift.Protocol(transport);
+ const client = new ThriftTest.ThriftTestClient(protocol);
transport.open();
</script>
<script type="text/javascript" src="test-async.js" charset="utf-8"></script>