From e1dac618a8b8929f601c7ec8aca3842c5ebf9d03 Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Mon, 13 Apr 2020 20:37:36 +0900 Subject: Use plugin:prettier/recommended --- e2e/navigate.test.ts | 206 ++++++++++++++++++++++++++++----------------------- 1 file changed, 113 insertions(+), 93 deletions(-) (limited to 'e2e/navigate.test.ts') diff --git a/e2e/navigate.test.ts b/e2e/navigate.test.ts index 37f0520..d0942b6 100644 --- a/e2e/navigate.test.ts +++ b/e2e/navigate.test.ts @@ -1,16 +1,16 @@ -import * as path from 'path'; -import * as assert from 'assert'; +import * as path from "path"; +import * as assert from "assert"; -import TestServer from './lib/TestServer'; -import eventually from './eventually'; -import { Builder, Lanthan } from 'lanthan'; -import { WebDriver, Key } from 'selenium-webdriver'; -import { Options as FirefoxOptions } from 'selenium-webdriver/firefox'; -import Page from './lib/Page'; +import TestServer from "./lib/TestServer"; +import eventually from "./eventually"; +import { Builder, Lanthan } from "lanthan"; +import { WebDriver, Key } from "selenium-webdriver"; +import { Options as FirefoxOptions } from "selenium-webdriver/firefox"; +import Page from "./lib/Page"; const newApp = () => { const server = new TestServer(); - server.handle('/pagenation-a/:page', (req, res) => { + server.handle("/pagenation-a/:page", (req, res) => { res.status(200).send(` @@ -19,26 +19,33 @@ const newApp = () => { `); }); - server.handle('/pagenation-link/:page', (req, res) => { + server.handle("/pagenation-link/:page", (req, res) => { res.status(200).send(` - - + + `); }); - server.receiveContent('/reload', ` + server.receiveContent( + "/reload", + ` - `); + ` + ); - server.receiveContent('/*', `ok`); + server.receiveContent("/*", `ok`); return server; }; @@ -49,204 +56,217 @@ describe("navigate test", () => { let webdriver: WebDriver; let browser: any; - before(async() => { + before(async () => { await server.start(); - const opts = (new FirefoxOptions() as any) - .setPreference('browser.startup.homepage', server.url('/#home')); - lanthan = await Builder - .forBrowser('firefox') + const opts = (new FirefoxOptions() as any).setPreference( + "browser.startup.homepage", + server.url("/#home") + ); + lanthan = await Builder.forBrowser("firefox") .setOptions(opts) - .spyAddon(path.join(__dirname, '..')) + .spyAddon(path.join(__dirname, "..")) .build(); webdriver = lanthan.getWebDriver(); browser = lanthan.getWebExtBrowser(); }); - after(async() => { + after(async () => { await server.stop(); if (lanthan) { await lanthan.quit(); } }); - beforeEach(async() => { + beforeEach(async () => { const tabs = await browser.tabs.query({}); for (const tab of tabs.slice(1)) { await browser.tabs.remove(tab.id); } }); - it('should go to parent path without hash by gu', async () => { - const page = await Page.navigateTo(webdriver, server.url('/a/b/c')); - await page.sendKeys('g', 'u'); + it("should go to parent path without hash by gu", async () => { + const page = await Page.navigateTo(webdriver, server.url("/a/b/c")); + await page.sendKeys("g", "u"); - await eventually(async() => { + await eventually(async () => { const tab = (await browser.tabs.query({}))[0]; const url = new URL(tab.url); - assert.strictEqual(url.pathname, `/a/b/`) + assert.strictEqual(url.pathname, `/a/b/`); }); }); - it('should remove hash by gu', async () => { - const page = await Page.navigateTo(webdriver, server.url('/a/b/c#hash')); - await page.sendKeys('g', 'u'); + it("should remove hash by gu", async () => { + const page = await Page.navigateTo(webdriver, server.url("/a/b/c#hash")); + await page.sendKeys("g", "u"); - await eventually(async() => { + await eventually(async () => { const tab = (await browser.tabs.query({}))[0]; const url = new URL(tab.url); - assert.strictEqual(url.hash, ''); - assert.strictEqual(url.pathname, `/a/b/c`) + assert.strictEqual(url.hash, ""); + assert.strictEqual(url.pathname, `/a/b/c`); }); }); - it('should go to root path by gU', async () => { - const page = await Page.navigateTo(webdriver, server.url('/a/b/c#hash')); - await page.sendKeys('g', Key.SHIFT, 'u'); + it("should go to root path by gU", async () => { + const page = await Page.navigateTo(webdriver, server.url("/a/b/c#hash")); + await page.sendKeys("g", Key.SHIFT, "u"); - await eventually(async() => { + await eventually(async () => { const tab = (await browser.tabs.query({}))[0]; const url = new URL(tab.url); - assert.strictEqual(url.pathname, `/`) + assert.strictEqual(url.pathname, `/`); }); }); - it('should go back and forward in history by H and L', async () => { - let page = await Page.navigateTo(webdriver, server.url('/first')); - await page.navigateTo(server.url('/second')); - await page.sendKeys(Key.SHIFT, 'h'); + it("should go back and forward in history by H and L", async () => { + let page = await Page.navigateTo(webdriver, server.url("/first")); + await page.navigateTo(server.url("/second")); + await page.sendKeys(Key.SHIFT, "h"); - await eventually(async() => { + await eventually(async () => { const tab = (await browser.tabs.query({}))[0]; const url = new URL(tab.url); - assert.strictEqual(url.pathname, `/first`) + assert.strictEqual(url.pathname, `/first`); }); page = await Page.currentContext(webdriver); - page.sendKeys(Key.SHIFT, 'l'); + page.sendKeys(Key.SHIFT, "l"); - await eventually(async() => { + await eventually(async () => { const tab = (await browser.tabs.query({}))[0]; const url = new URL(tab.url); - assert.strictEqual(url.pathname, `/second`) + assert.strictEqual(url.pathname, `/second`); }); }); - it('should go previous and next page in by [[ and ]]', async () => { - const page = await Page.navigateTo(webdriver, server.url('/pagenation-a/10')); - await page.sendKeys('[', '['); + it("should go previous and next page in by [[ and ]]", async () => { + const page = await Page.navigateTo( + webdriver, + server.url("/pagenation-a/10") + ); + await page.sendKeys("[", "["); - await eventually(async() => { + await eventually(async () => { const tab = (await browser.tabs.query({}))[0]; const url = new URL(tab.url); - assert.strictEqual(url.pathname, '/pagenation-a/9'); + assert.strictEqual(url.pathname, "/pagenation-a/9"); }); }); - it('should go next page in by ]]', async () => { - const page = await Page.navigateTo(webdriver, server.url('/pagenation-a/10')); - await page.sendKeys(']', ']'); + it("should go next page in by ]]", async () => { + const page = await Page.navigateTo( + webdriver, + server.url("/pagenation-a/10") + ); + await page.sendKeys("]", "]"); - await eventually(async() => { + await eventually(async () => { const tab = (await browser.tabs.query({}))[0]; const url = new URL(tab.url); - assert.strictEqual(url.pathname, '/pagenation-a/11'); + assert.strictEqual(url.pathname, "/pagenation-a/11"); }); }); - it('should go previous page in by ]]', async () => { - const page = await Page.navigateTo(webdriver, server.url('/pagenation-link/10')); - await page.sendKeys('[', '['); + it("should go previous page in by ]]", async () => { + const page = await Page.navigateTo( + webdriver, + server.url("/pagenation-link/10") + ); + await page.sendKeys("[", "["); - await eventually(async() => { + await eventually(async () => { const tab = (await browser.tabs.query({}))[0]; const url = new URL(tab.url); - assert.strictEqual(url.pathname, '/pagenation-link/9'); + assert.strictEqual(url.pathname, "/pagenation-link/9"); }); }); - it('should go next page by in by [[', async () => { - const page = await Page.navigateTo(webdriver, server.url('/pagenation-link/10')); - await page.sendKeys(']', ']'); + it("should go next page by in by [[", async () => { + const page = await Page.navigateTo( + webdriver, + server.url("/pagenation-link/10") + ); + await page.sendKeys("]", "]"); - await eventually(async() => { + await eventually(async () => { const tab = (await browser.tabs.query({}))[0]; const url = new URL(tab.url); - assert.strictEqual(url.pathname, '/pagenation-link/11'); + assert.strictEqual(url.pathname, "/pagenation-link/11"); }); }); - it('should go to home page into current tab by gh', async () => { + it("should go to home page into current tab by gh", async () => { const page = await Page.navigateTo(webdriver, server.url()); - await page.sendKeys('g', 'h'); + await page.sendKeys("g", "h"); - await eventually(async() => { + await eventually(async () => { const tab = (await browser.tabs.query({}))[0]; const url = new URL(tab.url); - assert.strictEqual(url.hash, '#home'); + assert.strictEqual(url.hash, "#home"); }); }); - it('should go to home page into current tab by gH', async () => { + it("should go to home page into current tab by gH", async () => { const page = await Page.navigateTo(webdriver, server.url()); - await page.sendKeys('g', Key.SHIFT, 'H'); + await page.sendKeys("g", Key.SHIFT, "H"); - await eventually(async() => { + await eventually(async () => { const tabs = await browser.tabs.query({}); assert.strictEqual(tabs.length, 2); - assert.strictEqual(new URL(tabs[0].url).hash, ''); - assert.strictEqual(new URL(tabs[1].url).hash, '#home'); + assert.strictEqual(new URL(tabs[0].url).hash, ""); + assert.strictEqual(new URL(tabs[1].url).hash, "#home"); assert.strictEqual(tabs[1].active, true); }); }); - it('should reload current tab by r', async () => { - const page = await Page.navigateTo(webdriver, server.url('/reload')); + it("should reload current tab by r", async () => { + const page = await Page.navigateTo(webdriver, server.url("/reload")); await page.scrollTo(500, 500); let before: number; - await eventually(async() => { + await eventually(async () => { const tab = (await browser.tabs.query({}))[0]; - before = Number(new URL(tab.url).hash.split('#')[1]); + before = Number(new URL(tab.url).hash.split("#")[1]); assert.ok(before > 0); }); - await page.sendKeys('r'); + await page.sendKeys("r"); let after; - await eventually(async() => { + await eventually(async () => { const tab = (await browser.tabs.query({}))[0]; - after = Number(new URL(tab.url).hash.split('#')[1]); + after = Number(new URL(tab.url).hash.split("#")[1]); assert.ok(after > before); }); - await eventually(async() => { + await eventually(async () => { const page = await Page.currentContext(webdriver); assert.strictEqual(await page.getScrollX(), 500); }); }); - it('should reload current tab without cache by R', async () => { - const page = await Page.navigateTo(webdriver, server.url('/reload')); + it("should reload current tab without cache by R", async () => { + const page = await Page.navigateTo(webdriver, server.url("/reload")); await page.scrollTo(500, 500); let before: number; - await eventually(async() => { + await eventually(async () => { const tab = (await browser.tabs.query({}))[0]; - before = Number(new URL(tab.url).hash.split('#')[1]); + before = Number(new URL(tab.url).hash.split("#")[1]); assert.ok(before > 0); }); - await page.sendKeys(Key.SHIFT, 'R'); + await page.sendKeys(Key.SHIFT, "R"); let after; - await eventually(async() => { + await eventually(async () => { const tab = (await browser.tabs.query({}))[0]; - after = Number(new URL(tab.url).hash.split('#')[1]); + after = Number(new URL(tab.url).hash.split("#")[1]); assert.ok(after > before); }); - await eventually(async() => { + await eventually(async () => { const page = await Page.currentContext(webdriver); assert.strictEqual(await page.getScrollY(), 0); }); -- cgit v1.2.3