diff options
Diffstat (limited to 'e2e/navigate.test.ts')
-rw-r--r-- | e2e/navigate.test.ts | 100 |
1 files changed, 48 insertions, 52 deletions
diff --git a/e2e/navigate.test.ts b/e2e/navigate.test.ts index 87155fd..6f27ebd 100644 --- a/e2e/navigate.test.ts +++ b/e2e/navigate.test.ts @@ -1,8 +1,7 @@ -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 eventually from './eventually'; import { Builder, Lanthan } from 'lanthan'; import { WebDriver, Key } from 'selenium-webdriver'; @@ -10,54 +9,51 @@ import { Options as FirefoxOptions } from 'selenium-webdriver/firefox'; import Page from './lib/Page'; const newApp = () => { - let app = express(); - app.get('/pagenation-a/:page', (req, res) => { + let server = new TestServer(); + server.handle('/pagenation-a/:page', (req, res) => { res.status(200).send(` -<html lang="en"> - <a href="/pagenation-a/${Number(req.params.page) - 1}">prev</a> - <a href="/pagenation-a/${Number(req.params.page) + 1}">next</a> -</html">`); - }); - app.get('/pagenation-link/:page', (req, res) => { - res.status(200).send(` -<html lang="en"> - <head> - <link rel="prev" href="/pagenation-link/${Number(req.params.page) - 1}"></link> - <link rel="next" href="/pagenation-link/${Number(req.params.page) + 1}"></link> - </head> -</html">`); - }); - app.get('/reload', (_req, res) => { - res.status(200).send(` -<html lang="en"> - <head> - <script>window.location.hash = Date.now()</script> - </head> - <body style="width:10000px; height:10000px"></body> -</html">`); + <!DOCTYPE html> + <html lang="en"> + <a href="/pagenation-a/${Number(req.params.page) - 1}">prev</a> + <a href="/pagenation-a/${Number(req.params.page) + 1}">next</a> + </html">`); }); - app.get('/*', (req, res) => { - res.send(`<!DOCTYPEhtml> -<html lang="en"> - ${req.path} -</html">`); - }); - return app; + server.handle('/pagenation-link/:page', (req, res) => { + res.status(200).send(` + <!DOCTYPE html> + <html lang="en"> + <head> + <link rel="prev" href="/pagenation-link/${Number(req.params.page) - 1}"></link> + <link rel="next" href="/pagenation-link/${Number(req.params.page) + 1}"></link> + </head> + </html">`); + }); + server.receiveContent('/reload', ` + <!DOCTYPE html> + <html lang="en"> + <head> + <script>window.location.hash = Date.now()</script> + </head> + <body style="width:10000px; height:10000px"></body> + </html">`); + + server.receiveContent('/*', `ok`); + + return server; }; describe("navigate test", () => { - - const port = 12321; - let http: http.Server; + let server = newApp(); let lanthan: Lanthan; let webdriver: WebDriver; let browser: any; before(async() => { + await server.start(); + let opts = (new FirefoxOptions() as any) - .setPreference('browser.startup.homepage', `http://127.0.0.1:${port}#home`); - http = newApp().listen(port); + .setPreference('browser.startup.homepage', server.url('/#home')); lanthan = await Builder .forBrowser('firefox') .setOptions(opts) @@ -68,10 +64,10 @@ describe("navigate test", () => { }); after(async() => { + await server.stop(); if (lanthan) { await lanthan.quit(); } - http.close(); }); beforeEach(async() => { @@ -82,7 +78,7 @@ describe("navigate test", () => { }) it('should go to parent path without hash by gu', async () => { - let page = await Page.navigateTo(webdriver, `http://127.0.0.1:${port}/a/b/c`); + let page = await Page.navigateTo(webdriver, server.url('/a/b/c')); await page.sendKeys('g', 'u'); await eventually(async() => { @@ -93,7 +89,7 @@ describe("navigate test", () => { }); it('should remove hash by gu', async () => { - let page = await Page.navigateTo(webdriver, `http://127.0.0.1:${port}/a/b/c#hash`); + let page = await Page.navigateTo(webdriver, server.url('/a/b/c#hash')); await page.sendKeys('g', 'u'); await eventually(async() => { @@ -105,7 +101,7 @@ describe("navigate test", () => { }); it('should go to root path by gU', async () => { - let page = await Page.navigateTo(webdriver, `http://127.0.0.1:${port}/a/b/c#hash`); + let page = await Page.navigateTo(webdriver, server.url('/a/b/c#hash')); await page.sendKeys('g', Key.SHIFT, 'u'); await eventually(async() => { @@ -116,8 +112,8 @@ describe("navigate test", () => { }); it('should go back and forward in history by H and L', async () => { - let page = await Page.navigateTo(webdriver, `http://127.0.0.1:${port}/first`); - await page.navigateTo(`http://127.0.0.1:${port}/second`); + let page = await Page.navigateTo(webdriver, server.url('/first')); + await page.navigateTo(server.url('/second')); await page.sendKeys(Key.SHIFT, 'h'); await eventually(async() => { @@ -137,7 +133,7 @@ describe("navigate test", () => { }); it('should go previous and next page in <a> by [[ and ]]', async () => { - let page = await Page.navigateTo(webdriver, `http://127.0.0.1:${port}/pagenation-a/10`); + let page = await Page.navigateTo(webdriver, server.url('/pagenation-a/10')); await page.sendKeys('[', '['); await eventually(async() => { @@ -148,7 +144,7 @@ describe("navigate test", () => { }); it('should go next page in <a> by ]]', async () => { - let page = await Page.navigateTo(webdriver, `http://127.0.0.1:${port}/pagenation-a/10`); + let page = await Page.navigateTo(webdriver, server.url('/pagenation-a/10')); await page.sendKeys(']', ']'); await eventually(async() => { @@ -159,7 +155,7 @@ describe("navigate test", () => { }); it('should go previous page in <link> by ]]', async () => { - let page = await Page.navigateTo(webdriver, `http://127.0.0.1:${port}/pagenation-link/10`); + let page = await Page.navigateTo(webdriver, server.url('/pagenation-link/10')); await page.sendKeys('[', '['); await eventually(async() => { @@ -170,7 +166,7 @@ describe("navigate test", () => { }); it('should go next page by in <link> by [[', async () => { - let page = await Page.navigateTo(webdriver, `http://127.0.0.1:${port}/pagenation-link/10`); + let page = await Page.navigateTo(webdriver, server.url('/pagenation-link/10')); await page.sendKeys(']', ']'); await eventually(async() => { @@ -181,7 +177,7 @@ describe("navigate test", () => { }); it('should go to home page into current tab by gh', async () => { - let page = await Page.navigateTo(webdriver, `http://127.0.0.1:${port}`); + let page = await Page.navigateTo(webdriver, server.url()); await page.sendKeys('g', 'h'); await eventually(async() => { @@ -192,7 +188,7 @@ describe("navigate test", () => { }); it('should go to home page into current tab by gH', async () => { - let page = await Page.navigateTo(webdriver, `http://127.0.0.1:${port}`); + let page = await Page.navigateTo(webdriver, server.url()); await page.sendKeys('g', Key.SHIFT, 'H'); await eventually(async() => { @@ -205,7 +201,7 @@ describe("navigate test", () => { }); it('should reload current tab by r', async () => { - let page = await Page.navigateTo(webdriver, `http://127.0.0.1:${port}/reload`); + let page = await Page.navigateTo(webdriver, server.url('/reload')); await page.scrollTo(500, 500); let before: number; @@ -231,7 +227,7 @@ describe("navigate test", () => { }); it('should reload current tab without cache by R', async () => { - let page = await Page.navigateTo(webdriver, `http://127.0.0.1:${port}/reload`); + let page = await Page.navigateTo(webdriver, server.url('/reload')); await page.scrollTo(500, 500); let before: number; |