Browse Source

some extra test

master
peter 4 years ago
parent
commit
bc71257416
1 changed files with 29 additions and 0 deletions
  1. 29
    0
      test/Test.ts

+ 29
- 0
test/Test.ts View File

@@ -65,6 +65,35 @@ describe('RPCServer', () => {
65 65
         await server.destroy()
66 66
     })
67 67
 
68
+    it('should be able to use all kinds of RPC definitions', (done) => {
69
+        const echo = (x) => x
70
+        const server = new RPCServer(20003, [{
71
+            name: 'HelloWorldRPCGroup',
72
+            exportRPCs: ()  => [
73
+                echo, //named function variable
74
+                function echof(x){ return x }, //named function
75
+                {
76
+                    name: 'echoExplicit', //describing object
77
+                    call: async (x) => x
78
+                }
79
+            ]
80
+        }])
81
+
82
+        const client = new RPCSocket(20003, 'localhost')
83
+
84
+        client.connect().then(async () => {
85
+            const r0 = await client['HelloWorldRPCGroup'].echo('Hello')
86
+            const r1 = await client['HelloWorldRPCGroup'].echof('World')
87
+            const r2 = await client['HelloWorldRPCGroup'].echoExplicit('RPC!')
88
+
89
+            if(r0 === 'Hello' && r1 === 'World' && r2 ==='RPC!'){
90
+                client.destroy()
91
+                server.destroy()
92
+                done()
93
+            }
94
+        })
95
+    })
96
+
68 97
     it('new RPCServer() should fail on bad RPC', (done) => {
69 98
         try{
70 99
             new RPCServer(20001, [{

Loading…
Cancel
Save