test/specs/echo.ts   A
last analyzed

Complexity

Total Complexity 1
Complexity/F 0

Size

Lines of Code 24
Function Count 0

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 1
eloc 21
mnd 1
bc 1
fnc 0
dl 0
loc 24
rs 10
bpm 0
cpm 0
noi 0
c 0
b 0
f 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
))