aboutsummaryrefslogtreecommitdiff
path: root/e2e/lib/TestServer.ts
diff options
context:
space:
mode:
authorShin'ya Ueoka <ueokande@i-beam.org>2020-05-02 17:25:56 +0900
committerGitHub <noreply@github.com>2020-05-02 17:25:56 +0900
commit5df0537bcf65a341e79852b1b30379c73318529c (patch)
treeaee5efe52412855f620cb514a13a2c14373f27b7 /e2e/lib/TestServer.ts
parent685f2b7b69218b06b5bb676069e35f79c5048c9b (diff)
parent75abd90ecb8201ad845b266f96220d8adfe19b2d (diff)
Merge pull request #749 from ueokande/qa-0.28
QA 0.28
Diffstat (limited to 'e2e/lib/TestServer.ts')
-rw-r--r--e2e/lib/TestServer.ts31
1 files changed, 14 insertions, 17 deletions
diff --git a/e2e/lib/TestServer.ts b/e2e/lib/TestServer.ts
index 5b9eee3..e0c711b 100644
--- a/e2e/lib/TestServer.ts
+++ b/e2e/lib/TestServer.ts
@@ -1,6 +1,6 @@
-import * as http from 'http';
-import * as net from 'net'
-import express from 'express';
+import * as http from "http";
+import * as net from "net";
+import express from "express";
type HandlerFunc = (req: express.Request, res: express.Response) => void;
@@ -9,10 +9,7 @@ export default class TestServer {
private app: express.Application;
- constructor(
- private port = 0,
- private address = '127.0.0.1',
- ){
+ constructor(private port = 0, private address = "127.0.0.1") {
this.app = express();
}
@@ -23,30 +20,30 @@ export default class TestServer {
receiveContent(path: string, content: string): TestServer {
this.app.get(path, (_req: express.Request, res: express.Response) => {
- res.status(200).send(content)
+ res.status(200).send(content);
});
return this;
}
-
- url(path = '/'): string {
+
+ url(path = "/"): string {
if (!this.http) {
- throw new Error('http server not started');
+ throw new Error("http server not started");
}
const addr = this.http.address() as net.AddressInfo;
- return `http://${addr.address}:${addr.port}${path}`
+ return `http://${addr.address}:${addr.port}${path}`;
}
- start(): Promise<void> {
+ start(): Promise<void> {
if (this.http) {
- throw new Error('http server already started');
+ throw new Error("http server already started");
}
- this.http = http.createServer(this.app)
+ this.http = http.createServer(this.app);
return new Promise((resolve) => {
this.http!!.listen(this.port, this.address, () => {
resolve();
- })
+ });
});
}
@@ -59,6 +56,6 @@ export default class TestServer {
this.http = undefined;
resolve();
});
- })
+ });
}
}