aboutsummaryrefslogtreecommitdiff
path: root/e2e/command_winopen.test.ts
diff options
context:
space:
mode:
authorShin'ya UEOKA <ueokande@i-beam.org>2019-09-27 10:02:12 +0000
committerShin'ya UEOKA <ueokande@i-beam.org>2019-09-29 00:13:04 +0000
commit1b92be636008e9211f460479e246331ba4a1f8f1 (patch)
tree8dbba51444f5f52ad91f0357d2d7035298394452 /e2e/command_winopen.test.ts
parent4a4b5e13031898440421cef7230c2742e6cd226a (diff)
Use TestServer on e2e
Diffstat (limited to 'e2e/command_winopen.test.ts')
-rw-r--r--e2e/command_winopen.test.ts43
1 files changed, 12 insertions, 31 deletions
diff --git a/e2e/command_winopen.test.ts b/e2e/command_winopen.test.ts
index 6ebeca2..fa52672 100644
--- a/e2e/command_winopen.test.ts
+++ b/e2e/command_winopen.test.ts
@@ -1,44 +1,23 @@
-import express from 'express';
import * as path from 'path';
import * as assert from 'assert';
-import * as http from 'http';
+import TestServer from './lib/TestServer';
import settings from './settings';
import eventually from './eventually';
import { Builder, Lanthan } from 'lanthan';
import { WebDriver } from 'selenium-webdriver';
import Page from './lib/Page';
-const newApp = () => {
-
- let app = express();
- for (let name of ['google', 'yahoo', 'bing', 'duckduckgo', 'twitter', 'wikipedia']) {
- app.get('/' + name, (_req, res) => {
- res.send(`<!DOCTYPEhtml>
-<html lang="en">
- <body><h1>${name.charAt(0).toUpperCase() + name.slice(1)}</h1></body>
-</html">`);
- });
- }
- app.get('/', (_req, res) => {
- res.send(`<!DOCTYPEhtml>
-<html lang="en">
- <body><h1>home</h1></body>
-</html">`);
- });
- return app;
-};
-
describe("winopen command test", () => {
- const port = 12321;
- let http: http.Server;
+ let server = new TestServer(12321)
+ .receiveContent('/google', 'google')
+ .receiveContent('/yahoo', 'yahoo');
let lanthan: Lanthan;
let webdriver: WebDriver;
let browser: any;
let page: Page;
before(async() => {
- http = newApp().listen(port);
lanthan = await Builder
.forBrowser('firefox')
.spyAddon(path.join(__dirname, '..'))
@@ -48,10 +27,12 @@ describe("winopen command test", () => {
await browser.storage.local.set({
settings,
});
+
+ await server.start();
});
after(async() => {
- http.close();
+ await server.stop();
if (lanthan) {
await lanthan.quit();
}
@@ -63,7 +44,7 @@ describe("winopen command test", () => {
await browser.windows.remove(win.id);
}
- page = await Page.navigateTo(webdriver, `http://127.0.0.1:${port}/area`);
+ page = await Page.navigateTo(webdriver, server.url());
})
it('should open default search for keywords by winopen command ', async() => {
@@ -76,7 +57,7 @@ describe("winopen command test", () => {
let tabs = await browser.tabs.query({ windowId: wins[1].id });
let url = new URL(tabs[0].url);
- assert.equal(url.href, `http://127.0.0.1:${port}/google?q=an%20apple`)
+ assert.equal(url.href, server.url('/google?q=an%20apple'))
});
});
@@ -90,7 +71,7 @@ describe("winopen command test", () => {
let tabs = await browser.tabs.query({ windowId: wins[1].id });
let url = new URL(tabs[0].url);
- assert.equal(url.href, `http://127.0.0.1:${port}/yahoo?q=an%20apple`)
+ assert.equal(url.href, server.url('/yahoo?q=an%20apple'))
});
});
@@ -104,7 +85,7 @@ describe("winopen command test", () => {
let tabs = await browser.tabs.query({ windowId: wins[1].id });
let url = new URL(tabs[0].url);
- assert.equal(url.href, `http://127.0.0.1:${port}/google?q=`)
+ assert.equal(url.href, server.url('/google?q='))
});
});
@@ -118,7 +99,7 @@ describe("winopen command test", () => {
let tabs = await browser.tabs.query({ windowId: wins[1].id });
let url = new URL(tabs[0].url);
- assert.equal(url.href, `http://127.0.0.1:${port}/yahoo?q=`)
+ assert.equal(url.href, server.url('/yahoo?q='))
});
});