diff options
Diffstat (limited to 'e2e/command_open.test.ts')
-rw-r--r-- | e2e/command_open.test.ts | 43 |
1 files changed, 12 insertions, 31 deletions
diff --git a/e2e/command_open.test.ts b/e2e/command_open.test.ts index 0a713af..d45fa65 100644 --- a/e2e/command_open.test.ts +++ b/e2e/command_open.test.ts @@ -1,37 +1,17 @@ -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("open 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; @@ -44,15 +24,16 @@ describe("open command test", () => { .build(); webdriver = lanthan.getWebDriver(); browser = lanthan.getWebExtBrowser(); - http = newApp().listen(port); await browser.storage.local.set({ settings, }); + + await server.start(); }); after(async() => { - http.close(); + await server.stop(); if (lanthan) { await lanthan.quit(); } @@ -60,7 +41,7 @@ describe("open command test", () => { beforeEach(async() => { await webdriver.switchTo().defaultContent(); - page = await Page.navigateTo(webdriver, `http://127.0.0.1:${port}`); + page = await Page.navigateTo(webdriver, server.url()); }) it('should open default search for keywords by open command ', async() => { @@ -70,7 +51,7 @@ describe("open command test", () => { await eventually(async() => { let tabs = await browser.tabs.query({ active: true }); 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')) }); }); @@ -81,7 +62,7 @@ describe("open command test", () => { await eventually(async() => { let tabs = await browser.tabs.query({ active: true }) 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')) }); }); @@ -92,7 +73,7 @@ describe("open command test", () => { await eventually(async() => { let tabs = await browser.tabs.query({ active: true }) 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=')) }); }); @@ -103,7 +84,7 @@ describe("open command test", () => { await eventually(async() => { let tabs = await browser.tabs.query({ active: true }) 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=')) }); }); |