Passed
Branch master (5df6c0)
by Michael
02:01
created

test/specs/lazy.ts   A

Complexity

Total Complexity 2
Complexity/F 0

Size

Lines of Code 22
Function Count 0

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 17
mnd 2
bc 2
fnc 0
dl 0
loc 22
rs 10
bpm 0
cpm 0
noi 0
c 0
b 0
f 0
1
import { createNew, timeout } from '../utils'
2
import mockServer from '../mock/server'
3
import { equals } from 'pepka'
4
import { test } from '../suite'
5
6
/** Lazy connect */
7
test('lazy', timeout(2e3, () => {
8
  return new Promise<void>(async (ff, rj) => {
9
    const {port} = await mockServer()
10
    const ws = createNew({ lazy: true }, port)
11
12
    setTimeout(async () => {
13
      if(ws.socket !== null) {
14
        rj()
15
      } else {
16
        const msg = {echo: true, msg: 'hello!'}
17
        const response = await ws.send(msg)
18
        if(equals(response, msg)) ff(); else rj()
19
      }
20
    }, 500)
21
  })
22
}))