diff options
author | Shin'ya Ueoka <ueokande@i-beam.org> | 2019-04-06 21:48:16 +0900 |
---|---|---|
committer | Shin'ya Ueoka <ueokande@i-beam.org> | 2019-04-06 22:39:40 +0900 |
commit | b04eecce7fea8b262411a5817924dc730cbe127a (patch) | |
tree | 024c14ce52319af899938ce81ee7107540ccbf7b /e2e-lanthan/server/MockServer.js | |
parent | c9a0bf87d0ba81beb1b958c374a40c4b69f4192b (diff) |
Replace e2e with lanthan
Diffstat (limited to 'e2e-lanthan/server/MockServer.js')
-rw-r--r-- | e2e-lanthan/server/MockServer.js | 58 |
1 files changed, 0 insertions, 58 deletions
diff --git a/e2e-lanthan/server/MockServer.js b/e2e-lanthan/server/MockServer.js deleted file mode 100644 index 131c177..0000000 --- a/e2e-lanthan/server/MockServer.js +++ /dev/null @@ -1,58 +0,0 @@ -var http = require('http'); -var url = require('url'); -var handlers = require('./handlers'); - -class MockServer { - constructor() { - this.handlers = []; - this.server = undefined; - } - - start() { - if (this.server) { - throw new Error('Server is already started'); - } - - let listener = (req, res) => { - if (req.method !== 'GET') { - res.writeHead(404, {'Content-Type': 'text/plain'}); - res.end('not found') - return - } - - let u = url.parse(req.url); - let handler = this.handlers.find(h => u.pathname == h.pathname); - if (!handler) { - res.writeHead(404, {'Content-Type': 'text/plain'}); - res.end('not found') - return - } - - handler.handler(req, res); - } - - this.server = http.createServer(listener); - this.server.listen(); - } - - stop() { - if (!this.server) { - throw new Error('Server is not started'); - } - this.server.close(); - this.server = undefined; - } - - port() { - if (!this.server) { - throw new Error('Server is not started'); - } - return this.server.address().port - } - - on(pathname, handler) { - this.handlers.push({ pathname, handler }); - } -} - -module.exports = MockServer |