FoundKey/test/streaming.ts
syuilo 99276028ae
Typed stream (#13)
* Update streaming.ts

* Update streaming.ts

* wip
2021-05-17 19:50:31 +09:00

35 lines
922 B
TypeScript

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('meUpdated', 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: 'meUpdated',
body: {
id: 'foo'
}
}
}));
expect(mainChannelReceived[0]).toEqual({
id: 'foo'
});
});
});