From aace7a190042b8f5fa1070071ea0acef39aafb0f Mon Sep 17 00:00:00 2001 From: syuilo Date: Sun, 16 May 2021 18:12:18 +0900 Subject: [PATCH] add streaming test --- test/streaming.ts | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 test/streaming.ts diff --git a/test/streaming.ts b/test/streaming.ts new file mode 100644 index 0000000000..65ab449b69 --- /dev/null +++ b/test/streaming.ts @@ -0,0 +1,35 @@ +import WS from 'jest-websocket-mock'; +import Stream from '../src/streaming'; + +describe('Streaming', () => { + test('success', async () => { + const server = new WS('wss://misskey.test/streaming'); + const stream = new Stream('https://misskey.test', { token: 'TOKEN' }); + const mainChannelReceived: any[] = []; + const main = stream.useSharedConnection('main'); + main.on('foo', payload => { + mainChannelReceived.push(payload); + }); + await server.connected; + const msg = JSON.parse(await server.nextMessage as string); + const mainChannelId = msg.body.id; + expect(msg.type).toEqual('connect'); + expect(msg.body.channel).toEqual('main'); + expect(mainChannelId != null).toEqual(true); + + server.send(JSON.stringify({ + type: 'channel', + body: { + id: mainChannelId, + type: 'foo', + body: { + bar: 'buzz' + } + } + })); + + expect(mainChannelReceived[0]).toEqual({ + bar: 'buzz' + }); + }); +});