THRIFT-5811: Update eslint & prettier
Client: js
Patch: Cameron Martin
This closes #3087
diff --git a/lib/nodets/test/client.ts b/lib/nodets/test/client.ts
index 4fa3c28..a95567f 100644
--- a/lib/nodets/test/client.ts
+++ b/lib/nodets/test/client.ts
@@ -39,15 +39,15 @@
var options = {
transport: Thrift.TBufferedTransport,
- protocol: Thrift.TBinaryProtocol
+ protocol: Thrift.TBinaryProtocol,
};
var testDriver = promise ? ThriftTestDriverPromise : ThriftTestDriver;
var connection = thrift.createConnection("localhost", port, options);
-connection.on("error", function(err: string) {
- assert(false, err);
+connection.on("error", function (err: string) {
+ assert(false, err);
});
var client = thrift.createClient(ThriftTest.Client, connection);
@@ -60,4 +60,4 @@
});
}
-exports.expressoTest = function() {};
+exports.expressoTest = function () {};
diff --git a/lib/nodets/test/int64.test.ts b/lib/nodets/test/int64.test.ts
index d209234..bb03458 100644
--- a/lib/nodets/test/int64.test.ts
+++ b/lib/nodets/test/int64.test.ts
@@ -18,18 +18,26 @@
*/
import Int64 = require("node-int64");
-import JSONInt64 = require('json-int64');
+import JSONInt64 = require("json-int64");
import i64types = require("./gen-nodejs/Int64Test_types");
import test = require("tape");
const cases = {
- "should correctly generate Int64 constants": function(assert) {
+ "should correctly generate Int64 constants": function (assert) {
const EXPECTED_SMALL_INT64_AS_NUMBER: number = 42;
const EXPECTED_SMALL_INT64: Int64 = new Int64(42);
- const EXPECTED_MAX_JS_SAFE_INT64: Int64 = new Int64(Number.MAX_SAFE_INTEGER);
- const EXPECTED_MIN_JS_SAFE_INT64: Int64 = new Int64(Number.MIN_SAFE_INTEGER);
- const EXPECTED_MAX_JS_SAFE_PLUS_ONE_INT64: Int64 = new Int64("0020000000000000"); // hex-encoded
- const EXPECTED_MIN_JS_SAFE_MINUS_ONE_INT64: Int64 = new Int64("ffe0000000000000"); // hex-encoded 2's complement
+ const EXPECTED_MAX_JS_SAFE_INT64: Int64 = new Int64(
+ Number.MAX_SAFE_INTEGER,
+ );
+ const EXPECTED_MIN_JS_SAFE_INT64: Int64 = new Int64(
+ Number.MIN_SAFE_INTEGER,
+ );
+ const EXPECTED_MAX_JS_SAFE_PLUS_ONE_INT64: Int64 = new Int64(
+ "0020000000000000",
+ ); // hex-encoded
+ const EXPECTED_MIN_JS_SAFE_MINUS_ONE_INT64: Int64 = new Int64(
+ "ffe0000000000000",
+ ); // hex-encoded 2's complement
const EXPECTED_MAX_SIGNED_INT64: Int64 = new Int64("7fffffffffffffff"); // hex-encoded
const EXPECTED_MIN_SIGNED_INT64: Int64 = new Int64("8000000000000000"); // hex-encoded 2's complement
const EXPECTED_INT64_LIST: Int64[] = [
@@ -39,7 +47,7 @@
EXPECTED_MAX_JS_SAFE_PLUS_ONE_INT64,
EXPECTED_MIN_JS_SAFE_MINUS_ONE_INT64,
EXPECTED_MAX_SIGNED_INT64,
- EXPECTED_MIN_SIGNED_INT64
+ EXPECTED_MIN_SIGNED_INT64,
];
assert.ok(EXPECTED_SMALL_INT64.equals(i64types.SMALL_INT64));
@@ -47,42 +55,46 @@
assert.ok(EXPECTED_MIN_JS_SAFE_INT64.equals(i64types.MIN_JS_SAFE_INT64));
assert.ok(
EXPECTED_MAX_JS_SAFE_PLUS_ONE_INT64.equals(
- i64types.MAX_JS_SAFE_PLUS_ONE_INT64
- )
+ i64types.MAX_JS_SAFE_PLUS_ONE_INT64,
+ ),
);
assert.ok(
EXPECTED_MIN_JS_SAFE_MINUS_ONE_INT64.equals(
- i64types.MIN_JS_SAFE_MINUS_ONE_INT64
- )
+ i64types.MIN_JS_SAFE_MINUS_ONE_INT64,
+ ),
);
assert.ok(EXPECTED_MAX_SIGNED_INT64.equals(i64types.MAX_SIGNED_INT64));
assert.ok(EXPECTED_MIN_SIGNED_INT64.equals(i64types.MIN_SIGNED_INT64));
assert.equal(
EXPECTED_SMALL_INT64_AS_NUMBER,
- i64types.SMALL_INT64.toNumber()
+ i64types.SMALL_INT64.toNumber(),
);
assert.equal(
Number.MAX_SAFE_INTEGER,
- i64types.MAX_JS_SAFE_INT64.toNumber()
+ i64types.MAX_JS_SAFE_INT64.toNumber(),
);
assert.equal(
Number.MIN_SAFE_INTEGER,
- i64types.MIN_JS_SAFE_INT64.toNumber()
+ i64types.MIN_JS_SAFE_INT64.toNumber(),
);
for (let i = 0; i < EXPECTED_INT64_LIST.length; ++i) {
assert.ok(EXPECTED_INT64_LIST[i].equals(i64types.INT64_LIST[i]));
}
- for (let i = 0; i < EXPECTED_INT64_LIST.length; ++i){
+ for (let i = 0; i < EXPECTED_INT64_LIST.length; ++i) {
let int64Object = EXPECTED_INT64_LIST[i];
- assert.ok(i64types.INT64_2_INT64_MAP[JSONInt64.toDecimalString(int64Object)].equals(int64Object));
+ assert.ok(
+ i64types.INT64_2_INT64_MAP[
+ JSONInt64.toDecimalString(int64Object)
+ ].equals(int64Object),
+ );
}
assert.end();
- }
+ },
};
-Object.keys(cases).forEach(function(caseName) {
+Object.keys(cases).forEach(function (caseName) {
test(caseName, cases[caseName]);
});
diff --git a/lib/nodets/test/server.ts b/lib/nodets/test/server.ts
index 2da53ae..79457ce 100644
--- a/lib/nodets/test/server.ts
+++ b/lib/nodets/test/server.ts
@@ -1,26 +1,33 @@
import thrift = require("thrift");
-var program = require('commander');
-import ThriftTest = require('./gen-nodejs/ThriftTest');
-import test_handler = require('./test_handler');
-
+var program = require("commander");
+import ThriftTest = require("./gen-nodejs/ThriftTest");
+import test_handler = require("./test_handler");
program
- .option('--port <port>', 'Set thrift server port', 9090)
- .option('--promise', 'test with promise style functions')
- .option('--protocol', '"Set thrift protocol (binary) [protocol]"')
+ .option("--port <port>", "Set thrift server port", 9090)
+ .option("--promise", "test with promise style functions")
+ .option("--protocol", '"Set thrift protocol (binary) [protocol]"')
.parse(process.argv);
var port: number = program.port;
var options: thrift.ServerOptions = {
transport: thrift.TBufferedTransport,
- protocol: thrift.TBinaryProtocol
+ protocol: thrift.TBinaryProtocol,
};
var server: thrift.Server;
if (program.promise) {
- server = thrift.createServer(ThriftTest.Processor, new test_handler.AsyncThriftTestHandler(), options);
+ server = thrift.createServer(
+ ThriftTest.Processor,
+ new test_handler.AsyncThriftTestHandler(),
+ options,
+ );
} else {
- server = thrift.createServer(ThriftTest.Processor, new test_handler.SyncThriftTestHandler(), options);
+ server = thrift.createServer(
+ ThriftTest.Processor,
+ new test_handler.SyncThriftTestHandler(),
+ options,
+ );
}
server.listen(port);
diff --git a/lib/nodets/test/test-cases.ts b/lib/nodets/test/test-cases.ts
index 44f254e..98f54af 100644
--- a/lib/nodets/test/test-cases.ts
+++ b/lib/nodets/test/test-cases.ts
@@ -1,91 +1,100 @@
-'use strict';
+"use strict";
-import ttypes = require('./gen-nodejs/ThriftTest_types');
-import Int64 = require('node-int64');
+import ttypes = require("./gen-nodejs/ThriftTest_types");
+import Int64 = require("node-int64");
//all Languages in UTF-8
/*jshint -W100 */
-export 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, 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ú, 粵語";
+export 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, 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 */
-export var 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: ]] \"]] \\" }}}{ [[[ ';
+export var 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: ]] \"]] \\" }}}{ [[[ ';
export var mapTestInput = {
- "a":"123", "a b":"with spaces ", "same":"same", "0":"numeric key",
- "longValue":stringTest, stringTest:"long key"
+ a: "123",
+ "a b": "with spaces ",
+ same: "same",
+ "0": "numeric key",
+ longValue: stringTest,
+ stringTest: "long key",
};
export var simple = [
- ['testVoid', undefined],
- ['testString', 'Test'],
- ['testString', ''],
- ['testString', stringTest],
- ['testString', specialCharacters],
- ['testByte', 1],
- ['testByte', 0],
- ['testByte', -1],
- ['testByte', -127],
- ['testI32', -1],
- ['testDouble', -5.2098523],
- ['testDouble', 7.012052175215044],
- ['testEnum', ttypes.Numberz.ONE]
+ ["testVoid", undefined],
+ ["testString", "Test"],
+ ["testString", ""],
+ ["testString", stringTest],
+ ["testString", specialCharacters],
+ ["testByte", 1],
+ ["testByte", 0],
+ ["testByte", -1],
+ ["testByte", -127],
+ ["testI32", -1],
+ ["testDouble", -5.2098523],
+ ["testDouble", 7.012052175215044],
+ ["testEnum", ttypes.Numberz.ONE],
];
export var simpleLoose = [
- ['testI64', 5],
- ['testI64', -5],
- ['testI64', 734359738368],
- ['testI64', -34359738368],
- ['testI64', -734359738368],
- ['testTypedef', 69]
-]
+ ["testI64", 5],
+ ["testI64", -5],
+ ["testI64", 734359738368],
+ ["testI64", -34359738368],
+ ["testI64", -734359738368],
+ ["testTypedef", 69],
+];
-var mapout: {[key: number]: number; } = {};
+var mapout: { [key: number]: number } = {};
for (var i = 0; i < 5; ++i) {
- mapout[i] = i-10;
+ mapout[i] = i - 10;
}
export var deep = [
- ['testMap', mapout],
- ['testSet', [1,2,3]],
- ['testList', [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20]],
- ['testStringMap', mapTestInput]
+ ["testMap", mapout],
+ ["testSet", [1, 2, 3]],
+ [
+ "testList",
+ [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],
+ ],
+ ["testStringMap", mapTestInput],
];
export var out = new ttypes.Xtruct({
- string_thing: 'Zero',
+ string_thing: "Zero",
byte_thing: 1,
i32_thing: -3,
- i64_thing: new Int64(1000000)
+ i64_thing: new Int64(1000000),
});
export var out2 = new ttypes.Xtruct2();
@@ -94,21 +103,24 @@
out2.i32_thing = 5;
export var crazy = new ttypes.Insanity({
- "userMap":{ "5":new Int64(5), "8":new Int64(8) },
- "xtructs":[new ttypes.Xtruct({
- "string_thing":"Goodbye4",
- "byte_thing":4,
- "i32_thing":4,
- "i64_thing":new Int64(4)
- }), new ttypes.Xtruct({
- "string_thing":"Hello2",
- "byte_thing":2,
- "i32_thing":2,
- "i64_thing":new Int64(2)
- })]
+ userMap: { "5": new Int64(5), "8": new Int64(8) },
+ xtructs: [
+ new ttypes.Xtruct({
+ string_thing: "Goodbye4",
+ byte_thing: 4,
+ i32_thing: 4,
+ i64_thing: new Int64(4),
+ }),
+ new ttypes.Xtruct({
+ string_thing: "Hello2",
+ byte_thing: 2,
+ i32_thing: 2,
+ i64_thing: new Int64(2),
+ }),
+ ],
});
export var insanity: any = {
- "1":{ "2": crazy, "3": crazy },
- "2":{ "6":{ "userMap":{}, "xtructs":[] } }
+ "1": { "2": crazy, "3": crazy },
+ "2": { "6": { userMap: {}, xtructs: [] } },
};
diff --git a/lib/nodets/test/test_driver.ts b/lib/nodets/test/test_driver.ts
index 2c41526..604d5e5 100644
--- a/lib/nodets/test/test_driver.ts
+++ b/lib/nodets/test/test_driver.ts
@@ -17,14 +17,14 @@
* 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.
+// 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.
import test = require("tape");
import ttypes = require("./gen-nodejs/ThriftTest_types");
@@ -35,107 +35,118 @@
var Int64 = require("node-int64");
import testCases = require("./test-cases");
-export function ThriftTestDriver(client: ThriftTest.Client, callback: (status: string) => void) {
-
- test("NodeJS Style Callback Client Tests", function(assert) {
-
+export function ThriftTestDriver(
+ client: ThriftTest.Client,
+ callback: (status: string) => void,
+) {
+ test("NodeJS Style Callback Client Tests", function (assert) {
var checkRecursively = makeRecursiveCheck(assert);
function makeAsserter(assertionFn: (a: any, b: any, msg?: string) => void) {
- return function(c: (string | any)[]) {
+ return function (c: (string | any)[]) {
var fnName = c[0];
var expected = c[1];
- (<any>client)[fnName](expected, function(err: any, actual: any) {
+ (<any>client)[fnName](expected, function (err: any, actual: any) {
assert.error(err, fnName + ": no callback error");
assertionFn(actual, expected, fnName);
- })
+ });
};
}
testCases.simple.forEach(makeAsserter(assert.equal));
- testCases.simpleLoose.forEach(makeAsserter(function(a, e, m){
- assert.ok(a == e, m);
- }));
+ testCases.simpleLoose.forEach(
+ makeAsserter(function (a, e, m) {
+ assert.ok(a == e, m);
+ }),
+ );
testCases.deep.forEach(makeAsserter(assert.deepEqual));
- client.testMapMap(42, function(err, response) {
+ client.testMapMap(42, function (err, response) {
var expected: typeof response = {
- "4": {"1":1, "2":2, "3":3, "4":4},
- "-4": {"-4":-4, "-3":-3, "-2":-2, "-1":-1}
+ "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.error(err, "testMapMap: no callback error");
assert.deepEqual(expected, response, "testMapMap");
});
- client.testStruct(testCases.out, function(err, response) {
+ 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) {
+ 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) {
+ client.testInsanity(testCases.crazy, function (err, response) {
assert.error(err, "testInsanity: no callback error");
checkRecursively(testCases.insanity, response, "testInsanity");
});
- client.testException("TException", function(err, response) {
- assert.ok(err instanceof TException, 'testException: correct error type');
- assert.ok(!Boolean(response), 'testException: no response');
+ client.testException("TException", function (err, response) {
+ assert.ok(err instanceof TException, "testException: correct error type");
+ assert.ok(!Boolean(response), "testException: no response");
});
- client.testException("Xception", function(err, response) {
- assert.ok(err instanceof ttypes.Xception, 'testException: correct error type');
- assert.ok(!Boolean(response), 'testException: no response');
- assert.equal(err.errorCode, 1001, 'testException: correct error code');
- assert.equal('Xception', err.message, 'testException: correct error message');
+ client.testException("Xception", function (err, response) {
+ assert.ok(
+ err instanceof ttypes.Xception,
+ "testException: correct error type",
+ );
+ assert.ok(!Boolean(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(!Boolean(response), 'testException: no response');
+ client.testException("no Exception", function (err, response) {
+ assert.error(err, "testException: no callback error");
+ assert.ok(!Boolean(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.testOneway(0, function (err, response) {
+ assert.error(err, "testOneway: no callback error");
+ assert.strictEqual(response, undefined, "testOneway: void response");
});
- checkOffByOne(function(done) {
- client.testI32(-1, function(err, response) {
+ checkOffByOne(function (done) {
+ client.testI32(-1, function (err, response) {
assert.error(err, "checkOffByOne: no callback error");
assert.equal(-1, response);
assert.end();
done();
});
}, callback);
-
});
-};
+}
-export function ThriftTestDriverPromise(client: ThriftTest.Client, callback: (status: string) => void) {
-
- test("Q Promise Client Tests", function(assert) {
-
+export function ThriftTestDriverPromise(
+ client: ThriftTest.Client,
+ callback: (status: string) => void,
+) {
+ test("Q Promise Client Tests", function (assert) {
var checkRecursively = makeRecursiveCheck(assert);
function fail(msg: string) {
- return function(error, response) {
+ return function (error, response) {
if (error !== null) {
assert.fail(msg);
}
- }
+ };
}
function makeAsserter(assertionFn: (a: any, b: any, msg?: string) => void) {
- return function(c: (string | any)[]) {
+ return function (c: (string | any)[]) {
var fnName = c[0];
var expected = c[1];
- (<any>client)[fnName](expected)
- .then(function(actual: any) {
+ (<any>client)
+ [fnName](expected)
+ .then(function (actual: any) {
assertionFn(actual, expected, fnName);
})
.fail(fail("fnName"));
@@ -143,73 +154,73 @@
}
testCases.simple.forEach(makeAsserter(assert.equal));
- testCases.simpleLoose.forEach(makeAsserter(function(a, e, m){
- assert.ok(a == e, m);
- }));
+ testCases.simpleLoose.forEach(
+ makeAsserter(function (a, e, m) {
+ assert.ok(a == e, m);
+ }),
+ );
testCases.deep.forEach(makeAsserter(assert.deepEqual));
Q.resolve(client.testStruct(testCases.out))
- .then(function(response) {
+ .then(function (response) {
checkRecursively(testCases.out, response, "testStruct");
})
.fail(fail("testStruct"));
Q.resolve(client.testNest(testCases.out2))
- .then(function(response) {
+ .then(function (response) {
checkRecursively(testCases.out2, response, "testNest");
})
.fail(fail("testNest"));
Q.resolve(client.testInsanity(testCases.crazy))
- .then(function(response) {
+ .then(function (response) {
checkRecursively(testCases.insanity, response, "testInsanity");
})
.fail(fail("testInsanity"));
Q.resolve(client.testException("TException"))
- .then(function(response) {
+ .then(function (response) {
fail("testException: TException");
})
- .fail(function(err) {
+ .fail(function (err) {
assert.ok(err instanceof TException);
});
Q.resolve(client.testException("Xception"))
- .then(function(response) {
+ .then(function (response) {
fail("testException: Xception");
})
- .fail(function(err) {
+ .fail(function (err) {
assert.ok(err instanceof ttypes.Xception);
assert.equal(err.errorCode, 1001);
assert.equal("Xception", err.message);
});
Q.resolve(client.testException("no Exception"))
- .then(function(response) {
+ .then(function (response) {
assert.equal(undefined, response); //void
})
.fail(fail("testException"));
client.testOneway(0, fail("testOneway: should not answer"));
- checkOffByOne(function(done) {
+ checkOffByOne(function (done) {
Q.resolve(client.testI32(-1))
- .then(function(response) {
- assert.equal(-1, response);
- assert.end();
- done();
+ .then(function (response) {
+ assert.equal(-1, response);
+ assert.end();
+ done();
})
.fail(fail("checkOffByOne"));
}, callback);
});
-};
-
+}
// Helper Functions
// =========================================================
function makeRecursiveCheck(assert: test.Test) {
-
return function (map1: any, map2: any, msg: string) {
var equal = true;
@@ -218,30 +229,37 @@
assert.ok(equal, msg);
// deepEqual doesn't work with fields using node-int64
- function checkRecursively(map1: any, map2: any) : boolean {
+ function checkRecursively(map1: any, map2: any): boolean {
if (!(typeof map1 !== "function" && typeof map2 !== "function")) {
return false;
}
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)) {
+ if (
+ typeof map1 === "number" &&
+ typeof map2 === "object" &&
+ map2.buffer &&
+ map2.buffer instanceof Buffer &&
+ map2.buffer.length === 8
+ ) {
var n = new Int64(map2.buffer);
return map1 === n.toNumber();
} else {
return map1 == map2;
}
} else {
- return Object.keys(map1).every(function(key) {
+ return Object.keys(map1).every(function (key) {
return checkRecursively(map1[key], map2[key]);
});
}
}
- }
+ };
}
-function checkOffByOne(done: (callback: () => void) => void, callback: (message: string) => void) {
-
+function checkOffByOne(
+ done: (callback: () => void) => void,
+ callback: (message: string) => void,
+) {
var retry_limit = 30;
var retry_interval = 100;
var test_complete = false;
@@ -256,20 +274,23 @@
* Because this is the last test against the server, when it completes
* the entire suite is complete by definition (the tests run serially).
*/
- done(function() {
+ done(function () {
test_complete = true;
});
//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",
+ );
}
}
}
diff --git a/lib/nodets/test/test_handler.ts b/lib/nodets/test/test_handler.ts
index 996c32a..823b4e7 100644
--- a/lib/nodets/test/test_handler.ts
+++ b/lib/nodets/test/test_handler.ts
@@ -26,7 +26,6 @@
import Q = require("q");
import Int64 = require("node-int64");
-
export class SyncThriftTestHandler {
testVoid(): Q.IPromise<void> {
//console.log('testVoid()');
@@ -35,9 +34,9 @@
testMapMap(hello: number) {
//console.log('testMapMap(' + hello + ')');
- var mapmap: {[key: number]: {[key: number]: number; }} = [];
- var pos: {[key: number]: number; } = [];
- var neg: {[key: number]: number; } = [];
+ var mapmap: { [key: number]: { [key: number]: number } } = [];
+ var pos: { [key: number]: number } = [];
+ var neg: { [key: number]: number } = [];
for (var i = 1; i < 5; i++) {
pos[i] = i;
neg[-i] = -i;
@@ -47,53 +46,60 @@
return Q.resolve(mapmap);
}
- testInsanity(argument: ttypes.Insanity): Q.IPromise<{ [k: number]: any; }> {
- const first_map: { [k: number]: any; } = [];
- const second_map: { [k: number]: any; } = [];
-
+ testInsanity(argument: ttypes.Insanity): Q.IPromise<{ [k: number]: any }> {
+ const first_map: { [k: number]: any } = [];
+ const second_map: { [k: number]: any } = [];
+
first_map[ttypes.Numberz.TWO] = argument;
first_map[ttypes.Numberz.THREE] = argument;
-
+
const looney = new ttypes.Insanity();
second_map[ttypes.Numberz.SIX] = looney;
-
- const insane: { [k: number]: any; } = [];
+
+ const insane: { [k: number]: any } = [];
insane[1] = first_map;
insane[2] = second_map;
return Q.resolve(insane);
}
- testMulti(arg0: any, arg1: number, arg2: Int64, arg3: { [k: number]: string; }, arg4: ttypes.Numberz, arg5: number) {
+ testMulti(
+ arg0: any,
+ arg1: number,
+ arg2: Int64,
+ arg3: { [k: number]: string },
+ arg4: ttypes.Numberz,
+ arg5: number,
+ ) {
var hello = new ttypes.Xtruct();
- hello.string_thing = 'Hello2';
+ hello.string_thing = "Hello2";
hello.byte_thing = arg0;
hello.i32_thing = arg1;
hello.i64_thing = arg2;
return Q.resolve(hello);
}
testException(arg: string): Q.IPromise<void> {
- if (arg === 'Xception') {
+ if (arg === "Xception") {
var x = new ttypes.Xception();
x.errorCode = 1001;
x.message = arg;
throw x;
- } else if (arg === 'TException') {
+ } else if (arg === "TException") {
throw new Thrift.TException(arg);
} else {
return Q.resolve();
}
}
testMultiException(arg0: string, arg1: string) {
- if (arg0 === ('Xception')) {
+ if (arg0 === "Xception") {
var 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')) {
+ } else if (arg0 === "Xception2") {
var 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;
}
@@ -101,8 +107,7 @@
res.string_thing = arg1;
return Q.resolve(res);
}
- testOneway(sleepFor: number) {
- }
+ testOneway(sleepFor: number) {}
testString(thing: string) {
return Q.resolve(thing);
@@ -131,10 +136,10 @@
testNest(thing: ttypes.Xtruct2) {
return Q.resolve(thing);
}
- testMap(thing: { [k: number]: number; }) {
+ testMap(thing: { [k: number]: number }) {
return Q.resolve(thing);
}
- testStringMap(thing: { [k: string]: string; }) {
+ testStringMap(thing: { [k: string]: string }) {
return Q.resolve(thing);
}
testSet(thing: number[]) {
@@ -161,13 +166,16 @@
callback(undefined);
return Q.resolve();
}
- testMapMap(hello: number,
- callback: (err: any, result: { [k: number]: { [k: number]: number; }; }) => void):
- Q.IPromise<{ [k: number]: { [k: number]: number; }; }> {
-
- var mapmap: {[key: number]: {[key: number]: number; }} = [];
- var pos: {[key: number]: number; } = [];
- var neg: {[key: number]: number; } = [];
+ testMapMap(
+ hello: number,
+ callback: (
+ err: any,
+ result: { [k: number]: { [k: number]: number } },
+ ) => void,
+ ): Q.IPromise<{ [k: number]: { [k: number]: number } }> {
+ var mapmap: { [key: number]: { [key: number]: number } } = [];
+ var pos: { [key: number]: number } = [];
+ var neg: { [key: number]: number } = [];
for (var i = 1; i < 5; i++) {
pos[i] = i;
neg[-i] = -i;
@@ -178,54 +186,69 @@
callback(null, mapmap);
return Q.resolve();
}
- testInsanity(argument: ttypes.Insanity, callback?: (err: any, result: { [k: number]: any; }) => void): Q.IPromise<{ [k: number]: any; }> {
- const first_map: { [k: number]: any; } = [];
- const second_map: { [k: number]: any; } = [];
-
+ testInsanity(
+ argument: ttypes.Insanity,
+ callback?: (err: any, result: { [k: number]: any }) => void,
+ ): Q.IPromise<{ [k: number]: any }> {
+ const first_map: { [k: number]: any } = [];
+ const second_map: { [k: number]: any } = [];
+
first_map[ttypes.Numberz.TWO] = argument;
first_map[ttypes.Numberz.THREE] = argument;
-
+
const looney = new ttypes.Insanity();
second_map[ttypes.Numberz.SIX] = looney;
-
- const insane: { [k: number]: any; } = [];
+
+ const insane: { [k: number]: any } = [];
insane[1] = first_map;
insane[2] = second_map;
- if (callback !== undefined){
+ if (callback !== undefined) {
callback(null, insane);
}
return Q.resolve();
}
- testMulti(arg0: any, arg1: number, arg2: Int64, arg3: { [k: number]: string; }, arg4: ttypes.Numberz, arg5: number, result: Function): Q.IPromise<ttypes.Xtruct> {
+ testMulti(
+ arg0: any,
+ arg1: number,
+ arg2: Int64,
+ arg3: { [k: number]: string },
+ arg4: ttypes.Numberz,
+ arg5: number,
+ result: Function,
+ ): Q.IPromise<ttypes.Xtruct> {
var hello = this.syncHandler.testMulti(arg0, arg1, arg2, arg3, arg4, arg5);
- hello.then(hello => result(null, hello));
+ hello.then((hello) => result(null, hello));
return Q.resolve();
}
testException(arg: string, result: (err: any) => void): Q.IPromise<void> {
- if (arg === 'Xception') {
+ if (arg === "Xception") {
var x = new ttypes.Xception();
x.errorCode = 1001;
x.message = arg;
result(x);
- } else if (arg === 'TException') {
+ } else if (arg === "TException") {
result(new Thrift.TException(arg));
} else {
result(null);
}
return Q.resolve();
}
- testMultiException(arg0: string, arg1: string, result: (err: any, res?: ttypes.Xtruct) => void): Q.IPromise<ttypes.Xtruct> {
- if (arg0 === ('Xception')) {
+ testMultiException(
+ arg0: string,
+ arg1: string,
+ result: (err: any, res?: ttypes.Xtruct) => void,
+ ): Q.IPromise<ttypes.Xtruct> {
+ if (arg0 === "Xception") {
var 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')) {
+ } else if (arg0 === "Xception2") {
var 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();
@@ -237,63 +260,108 @@
testOneway(sleepFor: number, result: Function) {
this.syncHandler.testOneway(sleepFor);
}
- testString(thing: string, callback: (err: any, result: string) => void): Q.IPromise<string> {
+ testString(
+ thing: string,
+ callback: (err: any, result: string) => void,
+ ): Q.IPromise<string> {
callback(null, thing);
return Q.resolve();
}
- testByte(thing: number, callback: (err: any, result: number) => void): Q.IPromise<number> {
+ testByte(
+ thing: number,
+ callback: (err: any, result: number) => void,
+ ): Q.IPromise<number> {
callback(null, thing);
return Q.resolve();
}
- testBool(thing: boolean, callback: (err: any, result: boolean) => void ): Q.IPromise<boolean> {
+ testBool(
+ thing: boolean,
+ callback: (err: any, result: boolean) => void,
+ ): Q.IPromise<boolean> {
callback(null, thing);
return Q.resolve();
}
- testI32(thing: number, callback: (err: any, result: number) => void): Q.IPromise<number> {
+ testI32(
+ thing: number,
+ callback: (err: any, result: number) => void,
+ ): Q.IPromise<number> {
callback(null, thing);
return Q.resolve();
}
- testI64(thing: number, callback: (err: any, result: number) => void): Q.IPromise<number> {
+ testI64(
+ thing: number,
+ callback: (err: any, result: number) => void,
+ ): Q.IPromise<number> {
callback(null, thing);
return Q.resolve();
}
- testDouble(thing: number, callback: (err: any, result: number) => void): Q.IPromise<number> {
+ testDouble(
+ thing: number,
+ callback: (err: any, result: number) => void,
+ ): Q.IPromise<number> {
callback(null, thing);
return Q.resolve();
}
- testBinary(thing: Buffer, callback: (err: any, result: Buffer) => void): Q.IPromise<Buffer> {
+ testBinary(
+ thing: Buffer,
+ callback: (err: any, result: Buffer) => void,
+ ): Q.IPromise<Buffer> {
callback(null, thing);
return Q.resolve();
}
- testStruct(thing: ttypes.Xtruct, callback: (err: any, result: ttypes.Xtruct) => void): Q.IPromise<ttypes.Xtruct> {
+ testStruct(
+ thing: ttypes.Xtruct,
+ callback: (err: any, result: ttypes.Xtruct) => void,
+ ): Q.IPromise<ttypes.Xtruct> {
callback(null, thing);
return Q.resolve();
}
- testNest(thing: ttypes.Xtruct2, callback: (err: any, result: ttypes.Xtruct2) => void): Q.IPromise<ttypes.Xtruct2> {
+ testNest(
+ thing: ttypes.Xtruct2,
+ callback: (err: any, result: ttypes.Xtruct2) => void,
+ ): Q.IPromise<ttypes.Xtruct2> {
callback(null, thing);
return Q.resolve();
}
- testMap(thing: { [k: number]: number; }, callback: (err: any, result: { [k: number]: number; }) => void): Q.IPromise<{ [k: number]: number; }> {
+ testMap(
+ thing: { [k: number]: number },
+ callback: (err: any, result: { [k: number]: number }) => void,
+ ): Q.IPromise<{ [k: number]: number }> {
callback(null, thing);
return Q.resolve();
}
- testStringMap(thing: { [k: string]: string; }, callback: (err: any, result: { [k: string]: string; }) => void): Q.IPromise<{ [k: string]: string; }> {
+ testStringMap(
+ thing: { [k: string]: string },
+ callback: (err: any, result: { [k: string]: string }) => void,
+ ): Q.IPromise<{ [k: string]: string }> {
callback(null, thing);
return Q.resolve();
}
- testSet(thing: number[], callback: (err: any, result: number[]) => void): Q.IPromise<number[]> {
+ testSet(
+ thing: number[],
+ callback: (err: any, result: number[]) => void,
+ ): Q.IPromise<number[]> {
callback(null, thing);
return Q.resolve();
}
- testList(thing: number[], callback: (err: any, result: number[]) => void): Q.IPromise<number[]> {
+ testList(
+ thing: number[],
+ callback: (err: any, result: number[]) => void,
+ ): Q.IPromise<number[]> {
callback(null, thing);
return Q.resolve();
}
- testEnum(thing: ttypes.Numberz, callback: (err: any, result: ttypes.Numberz) => void): Q.IPromise<ttypes.Numberz> {
+ testEnum(
+ thing: ttypes.Numberz,
+ callback: (err: any, result: ttypes.Numberz) => void,
+ ): Q.IPromise<ttypes.Numberz> {
callback(null, thing);
return Q.resolve();
}
- testTypedef(thing: number, callback: (err: any, result: number) => void): Q.IPromise<number> {
+ testTypedef(
+ thing: number,
+ callback: (err: any, result: number) => void,
+ ): Q.IPromise<number> {
callback(null, thing);
return Q.resolve();
}