Workspaces refactor #86
1 changed files with 35 additions and 0 deletions
35
test/streaming.ts
Normal file
35
test/streaming.ts
Normal file
|
@ -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'
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Reference in a new issue