Total Complexity | 1 |
Complexity/F | 0 |
Lines of Code | 24 |
Function Count | 0 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | import { equals } from 'pepka' |
||
2 | import { createNew, timeout } from '../utils' |
||
3 | import mockServer from '../mock/server' |
||
4 | import { test } from '../suite' |
||
5 | |||
6 | /** Proof of work. */ |
||
7 | test('echo', timeout(5e3, () => new Promise<void>(async (ff, rj) => { |
||
8 | const {port} = await mockServer() |
||
9 | let to = setTimeout(() => rj('cannot create'), 2e2) |
||
10 | const ws = createNew({}, port) |
||
11 | clearTimeout(to) |
||
12 | |||
13 | to = setTimeout(() => rj('cannot ready'), 2e2) |
||
14 | await ws.ready() |
||
15 | clearTimeout(to) |
||
16 | |||
17 | const msg = {echo: true, msg: 'hello!'} |
||
18 | to = setTimeout(() => rj('cannot send'), 2e2) |
||
19 | const response = await ws.send(msg) |
||
20 | clearTimeout(to) |
||
21 | |||
22 | if(equals(response, msg)) ff(); else rj('echo msg is not equal.') |
||
23 | }) |
||
24 | )) |