test/mock/server.ts   A
last analyzed

Complexity

Total Complexity 2
Complexity/F 2

Size

Lines of Code 17
Function Count 1

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 14
mnd 1
bc 1
fnc 1
dl 0
loc 17
rs 10
bpm 1
cpm 2
noi 0
c 0
b 0
f 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A server.ts ➔ isRunning 0 1 2
1
2
import { WebSocketServer } from 'ws'
3
import { createServer, killServer } from './WS'
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
    isRunning() {return Boolean(server)},
16
    shutDown: async () => { await killServer(); server=null }
17
  }
18
}