From 1b92be636008e9211f460479e246331ba4a1f8f1 Mon Sep 17 00:00:00 2001 From: Shin'ya UEOKA Date: Fri, 27 Sep 2019 10:02:12 +0000 Subject: Use TestServer on e2e --- e2e/command_winopen.test.ts | 43 ++++++++++++------------------------------- 1 file changed, 12 insertions(+), 31 deletions(-) (limited to 'e2e/command_winopen.test.ts') 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(` - -

${name.charAt(0).toUpperCase() + name.slice(1)}

-`); - }); - } - app.get('/', (_req, res) => { - res.send(` - -

home

-`); - }); - 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=')) }); }); -- cgit v1.2.3