From d844440a30a2ae6ddce0ff59af6c7572041f9bb4 Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Sun, 13 May 2018 12:17:09 +0900 Subject: [PATCH] Fix debug web-server on e2e testing --- e2e/contents/navigate.test.js | 23 +++++++------- e2e/contents/scroll.test.js | 5 ++- e2e/contents/tab.test.js | 59 +++++++++++++++++------------------ e2e/contents/zoom.test.js | 7 ++--- e2e/web-server/index.js | 28 +++++++++++------ e2e/web-server/url.js | 5 +++ 6 files changed, 69 insertions(+), 58 deletions(-) create mode 100644 e2e/web-server/url.js diff --git a/e2e/contents/navigate.test.js b/e2e/contents/navigate.test.js index 3b34785..590a4b3 100644 --- a/e2e/contents/navigate.test.js +++ b/e2e/contents/navigate.test.js @@ -2,8 +2,7 @@ import * as windows from "../ambassador/src/client/windows"; import * as tabs from "../ambassador/src/client/tabs"; import * as keys from "../ambassador/src/client/keys"; import * as scrolls from "../ambassador/src/client/scrolls"; - -const SERVER_URL = "http://localhost:11111"; +import { CLIENT_URL } from '../web-server/url'; describe("navigate test", () => { let targetWindow; @@ -11,7 +10,7 @@ describe("navigate test", () => { before(() => { return windows.create().then((win) => { targetWindow = win; - return tabs.create(targetWindow.id, SERVER_URL); + return tabs.create(targetWindow.id, CLIENT_URL); }); }); @@ -21,7 +20,7 @@ describe("navigate test", () => { it('goes to parent', () => { let targetTab; - return tabs.create(targetWindow.id, SERVER_URL + '/a/b/c').then((tab) => { + return tabs.create(targetWindow.id, CLIENT_URL + '/a/b/c').then((tab) => { targetTab = tab; return keys.press(targetTab.id, 'g'); }).then(() => { @@ -29,13 +28,13 @@ describe("navigate test", () => { }).then(() => { return tabs.get(targetTab.id); }).then((tab) => { - expect(tab.url).to.be.equal(SERVER_URL + '/a/b/'); + expect(tab.url).to.be.equal(CLIENT_URL + '/a/b/'); }); }); it('removes hash', () => { let targetTab; - return tabs.create(targetWindow.id, SERVER_URL + '/a/b/c#navigate').then((tab) => { + return tabs.create(targetWindow.id, CLIENT_URL + '/a/b/c#navigate').then((tab) => { targetTab = tab; return keys.press(targetTab.id, 'g'); }).then(() => { @@ -43,13 +42,13 @@ describe("navigate test", () => { }).then(() => { return tabs.get(targetTab.id); }).then((tab) => { - expect(tab.url).to.be.equal(SERVER_URL + '/a/b/c#'); + expect(tab.url).to.be.equal(CLIENT_URL + '/a/b/c#'); }); }); it('goes to root', () => { let targetTab; - return tabs.create(targetWindow.id, SERVER_URL + '/a/b/c').then((tab) => { + return tabs.create(targetWindow.id, CLIENT_URL + '/a/b/c').then((tab) => { targetTab = tab; return keys.press(targetTab.id, 'g'); }).then(() => { @@ -57,13 +56,13 @@ describe("navigate test", () => { }).then(() => { return tabs.get(targetTab.id); }).then((tab) => { - expect(tab.url).to.be.equal(SERVER_URL + '/'); + expect(tab.url).to.be.equal(CLIENT_URL + '/'); }); }); it('goes back and forward in history', () => { let targetTab; - return tabs.create(targetWindow.id, SERVER_URL + '/#navigate').then((tab) => { + return tabs.create(targetWindow.id, CLIENT_URL + '/#navigate').then((tab) => { targetTab = tab; return keys.press(targetTab.id, 'g'); }).then(() => { @@ -75,7 +74,7 @@ describe("navigate test", () => { }).then(() => { return tabs.get(targetTab.id); }).then((tab) => { - expect(tab.url, 'go back in history').to.be.equal(SERVER_URL + '/#navigate'); + expect(tab.url, 'go back in history').to.be.equal(CLIENT_URL + '/#navigate'); }).then(() => { return new Promise(resolve => { setTimeout(() => resolve(), 2000) }); }).then(() => { @@ -83,7 +82,7 @@ describe("navigate test", () => { }).then(() => { return tabs.get(targetTab.id); }).then((tab) => { - expect(tab.url, 'go next in history').to.be.equal(SERVER_URL + '/#'); + expect(tab.url, 'go next in history').to.be.equal(CLIENT_URL + '/#'); }); }); }); diff --git a/e2e/contents/scroll.test.js b/e2e/contents/scroll.test.js index 0a896b3..9410343 100644 --- a/e2e/contents/scroll.test.js +++ b/e2e/contents/scroll.test.js @@ -2,8 +2,7 @@ import * as windows from "../ambassador/src/client/windows"; import * as tabs from "../ambassador/src/client/tabs"; import * as keys from "../ambassador/src/client/keys"; import * as scrolls from "../ambassador/src/client/scrolls"; - -const SERVER_URL = "localhost:11111"; +import { CLIENT_URL } from '../web-server/url'; describe("scroll test", () => { let targetWindow; @@ -12,7 +11,7 @@ describe("scroll test", () => { before(() => { return windows.create().then((win) => { targetWindow = win; - return tabs.create(targetWindow.id, SERVER_URL); + return tabs.create(targetWindow.id, CLIENT_URL + '/scroll'); }).then((tab) => { targetTab = tab; }); diff --git a/e2e/contents/tab.test.js b/e2e/contents/tab.test.js index f0b7449..550d79a 100644 --- a/e2e/contents/tab.test.js +++ b/e2e/contents/tab.test.js @@ -1,14 +1,13 @@ import * as windows from "../ambassador/src/client/windows"; import * as tabs from "../ambassador/src/client/tabs"; import * as keys from "../ambassador/src/client/keys"; - -const SERVER_URL = "localhost:11111/"; +import { CLIENT_URL } from '../web-server/url'; describe("tab test", () => { let targetWindow; beforeEach(() => { - return windows.create(SERVER_URL).then((win) => { + return windows.create(CLIENT_URL).then((win) => { targetWindow = win; }); }); @@ -20,7 +19,7 @@ describe("tab test", () => { it('deletes tab by d', () => { let before; let targetTab; - return tabs.create(targetWindow.id, SERVER_URL).then((tab) => { + return tabs.create(targetWindow.id, CLIENT_URL).then((tab) => { targetTab = tab; return windows.get(targetWindow.id); }).then((win) => { @@ -36,7 +35,7 @@ describe("tab test", () => { it('duplicates tab by zd', () => { let before; let targetTab; - return tabs.create(targetWindow.id, SERVER_URL).then((tab) => { + return tabs.create(targetWindow.id, CLIENT_URL).then((tab) => { targetTab = tab; return windows.get(targetWindow.id) }).then((win) => {; @@ -54,7 +53,7 @@ describe("tab test", () => { it('makes pinned by zp', () => { let before; let targetTab; - return tabs.create(targetWindow.id, SERVER_URL).then((tab) => { + return tabs.create(targetWindow.id, CLIENT_URL).then((tab) => { targetTab = tab; return windows.get(targetWindow.id) }).then((win) => {; @@ -71,11 +70,11 @@ describe("tab test", () => { it('selects previous tab by K', () => { return Promise.resolve().then(() => { - return tabs.create(targetWindow.id, SERVER_URL + '#1') + return tabs.create(targetWindow.id, CLIENT_URL + '#1') }).then(() => { - return tabs.create(targetWindow.id, SERVER_URL + '#2') + return tabs.create(targetWindow.id, CLIENT_URL + '#2') }).then(() => { - return tabs.create(targetWindow.id, SERVER_URL + '#3'); + return tabs.create(targetWindow.id, CLIENT_URL + '#3'); }).then(() => { return tabs.selectAt(targetWindow.id, 2); }).then((tab) => { @@ -89,11 +88,11 @@ describe("tab test", () => { it('selects previous tab by K rotatory', () => { return Promise.resolve().then(() => { - return tabs.create(targetWindow.id, SERVER_URL + '#1') + return tabs.create(targetWindow.id, CLIENT_URL + '#1') }).then(() => { - return tabs.create(targetWindow.id, SERVER_URL + '#2') + return tabs.create(targetWindow.id, CLIENT_URL + '#2') }).then(() => { - return tabs.create(targetWindow.id, SERVER_URL + '#3'); + return tabs.create(targetWindow.id, CLIENT_URL + '#3'); }).then(() => { return tabs.selectAt(targetWindow.id, 0); }).then((tab) => { @@ -107,11 +106,11 @@ describe("tab test", () => { it('selects next tab by J', () => { return Promise.resolve().then(() => { - return tabs.create(targetWindow.id, SERVER_URL + '#1') + return tabs.create(targetWindow.id, CLIENT_URL + '#1') }).then(() => { - return tabs.create(targetWindow.id, SERVER_URL + '#2') + return tabs.create(targetWindow.id, CLIENT_URL + '#2') }).then(() => { - return tabs.create(targetWindow.id, SERVER_URL + '#3'); + return tabs.create(targetWindow.id, CLIENT_URL + '#3'); }).then(() => { return tabs.selectAt(targetWindow.id, 2); }).then((tab) => { @@ -125,11 +124,11 @@ describe("tab test", () => { it('selects previous tab by J rotatory', () => { return Promise.resolve().then(() => { - return tabs.create(targetWindow.id, SERVER_URL + '#1') + return tabs.create(targetWindow.id, CLIENT_URL + '#1') }).then(() => { - return tabs.create(targetWindow.id, SERVER_URL + '#2') + return tabs.create(targetWindow.id, CLIENT_URL + '#2') }).then(() => { - return tabs.create(targetWindow.id, SERVER_URL + '#3'); + return tabs.create(targetWindow.id, CLIENT_URL + '#3'); }).then(() => { return tabs.selectAt(targetWindow.id, 3); }).then((tab) => { @@ -143,11 +142,11 @@ describe("tab test", () => { it('selects first tab by g0', () => { return Promise.resolve().then(() => { - return tabs.create(targetWindow.id, SERVER_URL + '#1') + return tabs.create(targetWindow.id, CLIENT_URL + '#1') }).then(() => { - return tabs.create(targetWindow.id, SERVER_URL + '#2') + return tabs.create(targetWindow.id, CLIENT_URL + '#2') }).then(() => { - return tabs.create(targetWindow.id, SERVER_URL + '#3'); + return tabs.create(targetWindow.id, CLIENT_URL + '#3'); }).then(() => { return tabs.selectAt(targetWindow.id, 2); }).then((tab) => { @@ -163,11 +162,11 @@ describe("tab test", () => { it('selects last tab by g$', () => { return Promise.resolve().then(() => { - return tabs.create(targetWindow.id, SERVER_URL + '#1') + return tabs.create(targetWindow.id, CLIENT_URL + '#1') }).then(() => { - return tabs.create(targetWindow.id, SERVER_URL + '#2') + return tabs.create(targetWindow.id, CLIENT_URL + '#2') }).then(() => { - return tabs.create(targetWindow.id, SERVER_URL + '#3'); + return tabs.create(targetWindow.id, CLIENT_URL + '#3'); }).then(() => { return tabs.selectAt(targetWindow.id, 2); }).then((tab) => { @@ -183,11 +182,11 @@ describe("tab test", () => { it('selects last selected tab by ', () => { return Promise.resolve().then(() => { - return tabs.create(targetWindow.id, SERVER_URL + '#1') + return tabs.create(targetWindow.id, CLIENT_URL + '#1') }).then(() => { - return tabs.create(targetWindow.id, SERVER_URL + '#2') + return tabs.create(targetWindow.id, CLIENT_URL + '#2') }).then(() => { - return tabs.create(targetWindow.id, SERVER_URL + '#3'); + return tabs.create(targetWindow.id, CLIENT_URL + '#3'); }).then(() => { return tabs.selectAt(targetWindow.id, 1); }).then(() => { @@ -203,7 +202,7 @@ describe("tab test", () => { it('deletes tab by d', () => { return Promise.resolve().then(() => { - return tabs.create(targetWindow.id, SERVER_URL + '#1'); + return tabs.create(targetWindow.id, CLIENT_URL + '#1'); }).then((tab) => { return keys.press(tab.id, 'd'); }).then(() => { @@ -215,7 +214,7 @@ describe("tab test", () => { it('does not delete pinned tab by d', () => { return Promise.resolve().then(() => { - return tabs.create(targetWindow.id, SERVER_URL + '#1'); + return tabs.create(targetWindow.id, CLIENT_URL + '#1'); }).then((tab) => { return tabs.update(tab.id, { pinned: true }); }).then((tab) => { @@ -230,7 +229,7 @@ describe("tab test", () => { it('deletes pinned tab by !d', () => { let target; return Promise.resolve().then(() => { - return tabs.create(targetWindow.id, SERVER_URL + '#1'); + return tabs.create(targetWindow.id, CLIENT_URL + '#1'); }).then((tab) => { return tabs.update(tab.id, { pinned: true }); }).then((tab) => { diff --git a/e2e/contents/zoom.test.js b/e2e/contents/zoom.test.js index 10b7cca..c7efc93 100644 --- a/e2e/contents/zoom.test.js +++ b/e2e/contents/zoom.test.js @@ -1,15 +1,14 @@ import * as windows from "../ambassador/src/client/windows"; import * as tabs from "../ambassador/src/client/tabs"; import * as keys from "../ambassador/src/client/keys"; - -const SERVER_URL = "localhost:11111/"; +import { CLIENT_URL } from '../web-server/url'; describe("zoom test", () => { let targetWindow; let targetTab; before(() => { - return windows.create(SERVER_URL).then((win) => { + return windows.create(CLIENT_URL).then((win) => { targetWindow = win; }); }); @@ -19,7 +18,7 @@ describe("zoom test", () => { }); beforeEach(() => { - return tabs.create(targetWindow.id, SERVER_URL).then((tab) => { + return tabs.create(targetWindow.id, CLIENT_URL).then((tab) => { targetTab = tab; }); }); diff --git a/e2e/web-server/index.js b/e2e/web-server/index.js index 81e11c1..8710bf9 100644 --- a/e2e/web-server/index.js +++ b/e2e/web-server/index.js @@ -1,14 +1,24 @@ +var serverUrl = require('./url'); var http = require('http'); +var url = require('url'); -const content = -'' + -'' + - '' + - '' + -'' ; +const handleScroll = (req, res) => { + res.writeHead(200, {'Content-Type': 'text/html'}); + res.end(''); +}; +const handle404 = (req, res) => { + res.writeHead(404, {'Content-Type': 'text/plain'}); + res.end('not found') +}; http.createServer(function (req, res) { - res.writeHead(200, {'Content-Type': 'text/html'}); - res.end(content); -}).listen(11111, '127.0.0.1'); + let u = url.parse(req.url); + if (req.method === 'GET' && u.pathname === '/scroll') { + handleScroll(req, res); + } else { + handle404(req, res); + } + + console.log(`"${req.method} ${req.url}"`, res.statusCode) +}).listen(serverUrl.PORT, serverUrl.HOST); diff --git a/e2e/web-server/url.js b/e2e/web-server/url.js new file mode 100644 index 0000000..37f3d84 --- /dev/null +++ b/e2e/web-server/url.js @@ -0,0 +1,5 @@ +module.exports = { + PORT: 11111, + HOST: '127.0.0.1', + CLIENT_URL: 'http://127.0.0.1:11111', +}