ソースを参照

some extra test

master
peter 5年前
コミット
bc71257416
1個のファイルの変更29行の追加0行の削除
  1. 29
    0
      test/Test.ts

+ 29
- 0
test/Test.ts ファイルの表示

@@ -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, [{

読み込み中…
キャンセル
保存