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

test/mock/server.ts   A

Complexity

Total Complexity 1
Complexity/F 0

Size

Lines of Code 16
Function Count 0

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 1
eloc 13
mnd 1
bc 1
fnc 0
dl 0
loc 16
rs 10
bpm 0
cpm 0
noi 0
c 0
b 0
f 0
1
2
import { WebSocketServer } from 'ws'
3
import { createServer, killServer } from './WS.js'
4
5
let port: number,
6
    server: WebSocketServer|null
7
8
export default async (new_port?: number) => {
9
  if(!server) {
10
    port = new_port || 8000 + Math.ceil(Math.random()*500)
11
    server = await createServer(port)
12
  }
13
  return {
14
    server, port,
15
    shutDown: async () => { await killServer(); server=null }
16
  }
17
}