Skip to content

Commit

Permalink
feat(test-utils): mockedServer.open()
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Mar 7, 2020
1 parent 5a3cee4 commit ccda1bc
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions packages/test-utils/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ export class HttpServer extends MockedServer {

constructor (public cqhttpPort: number, public koishiPort: number, public token?: string) {
super()
this.open()
}

open () {
this.server = http.createServer((req, res) => {
let body = ''
req.on('data', chunk => body += chunk)
Expand Down Expand Up @@ -49,7 +53,7 @@ export class HttpServer extends MockedServer {
res.write(JSON.stringify(this.receive(path, params)))
res.end()
})
}).listen(cqhttpPort)
}).listen(this.cqhttpPort)
}

post (meta: Meta, port = this.koishiPort, secret?: string) {
Expand Down Expand Up @@ -91,7 +95,11 @@ export class WsServer extends MockedServer {

constructor (public cqhttpPort: number, public token?: string) {
super()
this.server = new ws.Server({ port: cqhttpPort })
this.open()
}

open () {
this.server = new ws.Server({ port: this.cqhttpPort })
this.server.on('connection', (socket, req) => {
if (this.token) {
const signature = req.headers.authorization
Expand Down

0 comments on commit ccda1bc

Please sign in to comment.