UNPKG

wspromisify

Version:

Wraps your WebSockets into Promise-based class with full d.ts typings on client & server

29 lines (26 loc) 710 B
import { createNew } from '../utils' import mockServer from '../mock/server' import { test } from '../suite' import { wait } from 'pepka' /** Rejects messages by timout */ test('drops', () => new Promise(async (ff, rj) => { const {port, shutDown} = await mockServer() const ws = await createNew({timeout: 500}, port) await shutDown() await wait(200) const msg = {echo: true, msg: 'hello!'} let to: NodeJS.Timeout try { to = setTimeout(() => { return rj() }, 600) await ws.send(msg) if(to) clearTimeout(to) await mockServer(port) return rj() } catch(e) { if(to!) clearTimeout(to) await mockServer(port) return ff() } }))