diff options
Diffstat (limited to 'e2e/command_winopen.test.ts')
-rw-r--r-- | e2e/command_winopen.test.ts | 43 |
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=')) }); }); |