diff options
author | Shin'ya UEOKA <ueokande@i-beam.org> | 2019-09-27 10:36:49 +0000 |
---|---|---|
committer | Shin'ya UEOKA <ueokande@i-beam.org> | 2019-09-28 00:02:57 +0000 |
commit | 4a4b5e13031898440421cef7230c2742e6cd226a (patch) | |
tree | 6d64d1527f01f7c2eec417620d8b3db59b62037a /e2e | |
parent | 9c40914bbacbc6eb0aaac3e6548d03fd7d071d4e (diff) |
Add graceful shutdown to TestServer
Diffstat (limited to 'e2e')
-rw-r--r-- | e2e/lib/TestServer.ts | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/e2e/lib/TestServer.ts b/e2e/lib/TestServer.ts index ba9845b..c010e37 100644 --- a/e2e/lib/TestServer.ts +++ b/e2e/lib/TestServer.ts @@ -37,16 +37,28 @@ export default class TestServer { return `http://${addr.address}:${addr.port}${path}` } - listen() { + start(): Promise<void> { + if (this.http) { + throw new Error('http server already started'); + } + this.http = http.createServer(this.app) - this.http.listen(this.port, this.address); + return new Promise((resolve) => { + this.http!!.listen(this.port, this.address, () => { + resolve(); + }) + }); } - close(): void { + stop(): Promise<void> { if (!this.http) { - return; + return Promise.resolve(); } - this.http.close(); - this.http = undefined; + return new Promise((resolve) => { + this.http!!.close(() => { + this.http = undefined; + resolve(); + }); + }) } } |