Add integration tests for scroll
This commit is contained in:
parent
af9662f86c
commit
6e6cd4c01e
3 changed files with 225 additions and 0 deletions
58
e2e-lanthan/server/MockServer.js
Normal file
58
e2e-lanthan/server/MockServer.js
Normal file
|
@ -0,0 +1,58 @@
|
|||
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
|
17
e2e-lanthan/server/handlers.js
Normal file
17
e2e-lanthan/server/handlers.js
Normal file
|
@ -0,0 +1,17 @@
|
|||
const handleText = (body) => {
|
||||
return (req, res) => {
|
||||
res.writeHead(200, {'Content-Type': 'text/plane'});
|
||||
res.end(body);
|
||||
}
|
||||
}
|
||||
|
||||
const handleHtml = (body) => {
|
||||
return (req, res) => {
|
||||
res.writeHead(200, {'Content-Type': 'text/html'});
|
||||
res.end(body);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
handleText, handleHtml
|
||||
}
|
Reference in a new issue