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

test/specs/reconnect.ts   A

Complexity

Total Complexity 1
Complexity/F 0

Size

Lines of Code 23
Function Count 0

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 1
eloc 17
mnd 1
bc 1
fnc 0
dl 0
loc 23
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
/** Reconnects if connection is broken. */
7
test('reconnect', timeout(1e4, () => new Promise<void>(async (ff, rj) => {
8
    const {port, shutDown} = await mockServer()
9
    const ws = createNew({ reconnect: 1 }, port)
10
11
    setTimeout(async () => {
12
      await shutDown()
13
      setTimeout(async () => {
14
        await mockServer(port)
15
        setTimeout(async () => {
16
          const msg = {echo: true, msg: 'hello!'}
17
          const response = await ws.send(msg)
18
          if(equals(response, msg)) ff(); else rj('not equals.')
19
        }, 1500)
20
      }, 1100)
21
    }, 500)
22
  })
23
))