• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript mock-socket.Server类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中mock-socket.Server的典型用法代码示例。如果您正苦于以下问题:TypeScript Server类的具体用法?TypeScript Server怎么用?TypeScript Server使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Server类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: before

        before(function () {
            const fakeURL = 'ws://localhost:8080/peerjs?key=peerjs&id=1&token=testToken';
            mockServer = new Server(fakeURL);

            mockServer.on('connection', socket => {
                //@ts-ignore
                socket.on('message', data => {
                    socket.send('test message from mock server');
                });

                socket.send(ServerMessageType.Open);
            });
        });
开发者ID:peers,项目名称:peerjs,代码行数:13,代码来源:peer.ts


示例2: it

        it('should connect', (done) => {
            mockwebSocketServer.on('connection', () => {
                done();
            });

            dotEventsSocket.connect().subscribe(() => {});
        });
开发者ID:dotCMS,项目名称:core-web,代码行数:7,代码来源:dot-event-socket.spec.ts


示例3: it

        it('should send a request', done => {
            const brayns = new Client(host);

            mockServer.on('connection', socket => {
                // TODO: (socket as any) is due to https://github.com/thoov/mock-socket/issues/224,
                // remove when fixed
                (socket as any).on('message', (data: any) => {
                    const json = fromJson<JsonRpcRequest>(data);
                    expect(isJsonRpcRequest(json)).toBe(true);
                    expect(json.id).toBeDefined();
                    expect(json.method).toBe(INSPECT);
                    expect(json.params).toEqual({
                        ping: true
                    });

                    const response = toResponseJson(json, true);
                    socket.send(response);
                });
            });

            brayns.request(INSPECT, {ping: true} as any)
                .then(() => {
                    done();
                });
        });
开发者ID:chevtche,项目名称:Brayns,代码行数:25,代码来源:client.spec.ts


示例4: callback

  const addServerHandler = (
    method: string, 
    path: string, 
    responseData: Omit<RequestSuccessResponse, 'callback_id'> | Omit<RequestErrorResponse, 'callback_id'>, 
    callback: Callback
  ) => {
    const handler = (jsonRequest: string) => {
      const requestObj: OutgoingRequest = JSON.parse(jsonRequest);

      if (requestObj.path !== path || requestObj.method !== method) {
        //console.log(requestObj, requestObj.path, path);
        return;
      }

      if (callback) {
        callback(requestObj);
      }

      const response: RequestSuccessResponse | RequestErrorResponse = {
        callback_id: requestObj.callback_id,
        ...responseData,
      };

      mockServer.send(JSON.stringify(response));
    };

    mockServer.addEventListener('message', handler);
  };
开发者ID:airdcpp-web,项目名称:airdcpp-apisocket-js,代码行数:28,代码来源:helpers.ts


示例5:

 mockServer.on('connection', socket => {
     mockServer.close({
         code: 1005,
         reason: 'Why not?',
         wasClean: false
     });
 });
开发者ID:chevtche,项目名称:Brayns,代码行数:7,代码来源:client.spec.ts


示例6: describe

    describe('{ready}', () => {
        let mockServer: Server;
        beforeEach(() => {
            mockServer = new Server(wsHost);
        });
        afterEach(done => {
            mockServer.stop(done);
        });

        it('should emit false by default', done => {
            const brayns = new Client(host);
            brayns.ready.pipe(take(1))
                .subscribe(ready => {
                    expect(ready).toBe(false);
                    done();
                });
        });

        it('should emit true when the socket establishes a connection with the ws server', done => {
            const brayns = new Client(host);
            brayns.ready.pipe(skip(1), take(1))
                .subscribe(ready => {
                    expect(ready).toBe(true);
                    done();
                });
        });

        it('should emit false when the socket connection with the ws server is closed', done => {
            const brayns = new Client(host);

            brayns.ready.pipe(skip(2), take(1))
                .subscribe(ready => {
                    expect(ready).toBe(false);
                    done();
                });

            mockServer.on('connection', socket => {
                socket.close(0, 'Why not?');
            });
        });

        it('should emit false when the socket connection with the ws server errored', done => {
            const brayns = new Client(host);

            brayns.ready.pipe(skip(2), take(1))
                .subscribe(ready => {
                    expect(ready).toBe(false);
                    done();
                });

            mockServer.on('connection', socket => {
                mockServer.close({
                    code: 1005,
                    reason: 'Why not?',
                    wasClean: false
                });
            });
        });
    });
开发者ID:chevtche,项目名称:Brayns,代码行数:59,代码来源:client.spec.ts


示例7: beforeEach

 beforeEach(async () => {
   mockServer = new Server("ws://localhost:6868");
   p = new Promise((resolve, reject) => { res = resolve; rej = reject; });
   const serverInfo = (jsonmsg: string) => {
     const msg: Messages.ButtplugMessage = FromJSON(jsonmsg)[0] as Messages.ButtplugMessage;
     if (msg.Type === Messages.RequestServerInfo) {
       delaySend(new Messages.ServerInfo(0, 0, 0, 1, 0, "Test Server", msg.Id));
     }
     if (msg.Type === Messages.RequestDeviceList) {
       delaySend(new Messages.DeviceList([], msg.Id));
       // (socket as any).removeListener("message", serverInfo);
     }
   };
   mockServer.on("connection", (aSocket: WebSocket) => {
     socket = aSocket;
     // TODO Bug in typescript defs for mock-socket 8 means we can't use the
     // socket type as it was meant. See
     // https://github.com/thoov/mock-socket/issues/224
     (socket as any).on("message", (data: string) => serverInfo(data));
   });
   bp = new ButtplugClient("Test Buttplug Client");
   await bp.Connect(new ButtplugBrowserWebsocketClientConnector("ws://localhost:6868"));
 });
开发者ID:metafetish,项目名称:buttplug-js,代码行数:23,代码来源:test-websocketclient.ts



注:本文中的mock-socket.Server类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript mockdate.reset函数代码示例发布时间:2022-05-25
下一篇:
TypeScript mock-promises.tickAllTheWay函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap