From bc71257416fe2eb5bad5351da25947caeb6d0925 Mon Sep 17 00:00:00 2001 From: peter Date: Wed, 25 Sep 2019 21:08:55 +0200 Subject: [PATCH] some extra test --- test/Test.ts | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/test/Test.ts b/test/Test.ts index 64f620c..6526251 100644 --- a/test/Test.ts +++ b/test/Test.ts @@ -65,6 +65,35 @@ describe('RPCServer', () => { await server.destroy() }) + it('should be able to use all kinds of RPC definitions', (done) => { + const echo = (x) => x + const server = new RPCServer(20003, [{ + name: 'HelloWorldRPCGroup', + exportRPCs: () => [ + echo, //named function variable + function echof(x){ return x }, //named function + { + name: 'echoExplicit', //describing object + call: async (x) => x + } + ] + }]) + + const client = new RPCSocket(20003, 'localhost') + + client.connect().then(async () => { + const r0 = await client['HelloWorldRPCGroup'].echo('Hello') + const r1 = await client['HelloWorldRPCGroup'].echof('World') + const r2 = await client['HelloWorldRPCGroup'].echoExplicit('RPC!') + + if(r0 === 'Hello' && r1 === 'World' && r2 ==='RPC!'){ + client.destroy() + server.destroy() + done() + } + }) + }) + it('new RPCServer() should fail on bad RPC', (done) => { try{ new RPCServer(20001, [{