diff options
author | Shin'ya Ueoka <ueokande@i-beam.org> | 2020-04-13 20:37:36 +0900 |
---|---|---|
committer | Shin'ya Ueoka <ueokande@i-beam.org> | 2020-04-13 20:37:36 +0900 |
commit | e1dac618a8b8929f601c7ec8aca3842c5ebf9d03 (patch) | |
tree | 6a914a8243c8c02e7752a83667a54d3fa832955c /e2e | |
parent | 685f2b7b69218b06b5bb676069e35f79c5048c9b (diff) |
Use plugin:prettier/recommended
Diffstat (limited to 'e2e')
37 files changed, 1630 insertions, 1403 deletions
diff --git a/e2e/blacklist.test.ts b/e2e/blacklist.test.ts index 79cdb47..db82726 100644 --- a/e2e/blacklist.test.ts +++ b/e2e/blacklist.test.ts @@ -1,57 +1,59 @@ -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 { Builder, Lanthan } from 'lanthan'; -import { WebDriver } from 'selenium-webdriver'; -import Page from './lib/Page'; +import TestServer from "./lib/TestServer"; +import { Builder, Lanthan } from "lanthan"; +import { WebDriver } from "selenium-webdriver"; +import Page from "./lib/Page"; import SettingRepository from "./lib/SettingRepository"; import Settings from "../src/shared/settings/Settings"; describe("blacklist test", () => { - const server = new TestServer().receiveContent('/*', - `<!DOCTYPE html><html lang="en"><body style="width:10000px; height:10000px"></body></html>`, + const server = new TestServer().receiveContent( + "/*", + `<!DOCTYPE html><html lang="en"><body style="width:10000px; height:10000px"></body></html>` ); let lanthan: Lanthan; let webdriver: WebDriver; let browser: any; - before(async() => { - lanthan = await Builder - .forBrowser('firefox') - .spyAddon(path.join(__dirname, '..')) + before(async () => { + lanthan = await Builder.forBrowser("firefox") + .spyAddon(path.join(__dirname, "..")) .build(); webdriver = lanthan.getWebDriver(); browser = lanthan.getWebExtBrowser(); await server.start(); - const url = server.url('/a').replace('http://', ''); - await new SettingRepository(browser).saveJSON(Settings.fromJSON({ - keymaps: { - j: { type: "scroll.vertically", count: 1 }, - }, - blacklist: [ url ], - })); + const url = server.url("/a").replace("http://", ""); + await new SettingRepository(browser).saveJSON( + Settings.fromJSON({ + keymaps: { + j: { type: "scroll.vertically", count: 1 }, + }, + blacklist: [url], + }) + ); }); - after(async() => { + after(async () => { await server.stop(); if (lanthan) { await lanthan.quit(); } }); - it('should disable add-on if the URL is in the blacklist', async () => { - const page = await Page.navigateTo(webdriver, server.url('/a')); - await page.sendKeys('j'); + it("should disable add-on if the URL is in the blacklist", async () => { + const page = await Page.navigateTo(webdriver, server.url("/a")); + await page.sendKeys("j"); const scrollY = await page.getScrollY(); assert.strictEqual(scrollY, 0); }); - it('should enabled add-on if the URL is not in the blacklist', async () => { - const page = await Page.navigateTo(webdriver, server.url('/ab')); - await page.sendKeys('j'); + it("should enabled add-on if the URL is not in the blacklist", async () => { + const page = await Page.navigateTo(webdriver, server.url("/ab")); + await page.sendKeys("j"); const scrollY = await page.getScrollY(); assert.strictEqual(scrollY, 64); diff --git a/e2e/clipboard.test.ts b/e2e/clipboard.test.ts index 0a09c77..63a20a8 100644 --- a/e2e/clipboard.test.ts +++ b/e2e/clipboard.test.ts @@ -1,116 +1,120 @@ -import * as assert from 'assert'; -import * as path from 'path'; - -import TestServer from './lib/TestServer'; -import eventually from './eventually'; -import * as clipboard from './lib/clipboard'; -import { Builder, Lanthan } from 'lanthan'; -import { WebDriver, Key } from 'selenium-webdriver'; -import Page from './lib/Page'; +import * as assert from "assert"; +import * as path from "path"; + +import TestServer from "./lib/TestServer"; +import eventually from "./eventually"; +import * as clipboard from "./lib/clipboard"; +import { Builder, Lanthan } from "lanthan"; +import { WebDriver, Key } from "selenium-webdriver"; +import Page from "./lib/Page"; import SettingRepository from "./lib/SettingRepository"; import Settings from "../src/shared/settings/Settings"; describe("clipboard test", () => { - const server = new TestServer(12321).receiveContent('/happy', 'ok'); + const server = new TestServer(12321).receiveContent("/happy", "ok"); let lanthan: Lanthan; let webdriver: WebDriver; let browser: any; - before(async() => { - lanthan = await Builder - .forBrowser('firefox') - .spyAddon(path.join(__dirname, '..')) + before(async () => { + lanthan = await Builder.forBrowser("firefox") + .spyAddon(path.join(__dirname, "..")) .build(); webdriver = lanthan.getWebDriver(); browser = lanthan.getWebExtBrowser(); - await new SettingRepository(browser).saveJSON(Settings.fromJSON({ - search: { - default: "google", - engines: { - "google": "http://127.0.0.1:12321/google?q={}", + await new SettingRepository(browser).saveJSON( + Settings.fromJSON({ + search: { + default: "google", + engines: { + google: "http://127.0.0.1:12321/google?q={}", + }, }, - }, - })); + }) + ); await server.start(); }); - 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 copy current URL by y', async () => { - const page = await Page.navigateTo(webdriver, server.url('/#should_copy_url')); - await page.sendKeys('y'); + it("should copy current URL by y", async () => { + const page = await Page.navigateTo( + webdriver, + server.url("/#should_copy_url") + ); + await page.sendKeys("y"); - await eventually(async() => { + await eventually(async () => { const data = await clipboard.read(); - assert.strictEqual(data, server.url('/#should_copy_url')); + assert.strictEqual(data, server.url("/#should_copy_url")); }); }); - it('should open an URL from clipboard by p', async () => { - await clipboard.write(server.url('/#open_from_clipboard')); + it("should open an URL from clipboard by p", async () => { + await clipboard.write(server.url("/#open_from_clipboard")); const page = await Page.navigateTo(webdriver, server.url()); - await page.sendKeys('p'); + await page.sendKeys("p"); - await eventually(async() => { + await eventually(async () => { const tabs = await browser.tabs.query({ active: true }); - assert.strictEqual(tabs[0].url, server.url('/#open_from_clipboard')); + assert.strictEqual(tabs[0].url, server.url("/#open_from_clipboard")); }); }); - it('should open an URL from clipboard to new tab by P', async () => { - await clipboard.write(server.url('/#open_to_new_tab')); + it("should open an URL from clipboard to new tab by P", async () => { + await clipboard.write(server.url("/#open_to_new_tab")); const page = await Page.navigateTo(webdriver, server.url()); - await page.sendKeys(Key.SHIFT, 'p'); + await page.sendKeys(Key.SHIFT, "p"); - await eventually(async() => { + await eventually(async () => { const tabs = await browser.tabs.query({}); - assert.deepStrictEqual(tabs.map((t: any) => t.url), [ - server.url(), - server.url('/#open_to_new_tab'), - ]); + assert.deepStrictEqual( + tabs.map((t: any) => t.url), + [server.url(), server.url("/#open_to_new_tab")] + ); }); }); - it('should open search result with keywords in clipboard by p', async () => { + it("should open search result with keywords in clipboard by p", async () => { await clipboard.write(`an apple`); const page = await Page.navigateTo(webdriver, server.url()); - await page.sendKeys(Key.SHIFT, 'p'); + await page.sendKeys(Key.SHIFT, "p"); - await eventually(async() => { + await eventually(async () => { const tabs = await browser.tabs.query({ active: true }); - assert.strictEqual(tabs[0].url, server.url('/google?q=an%20apple')); + assert.strictEqual(tabs[0].url, server.url("/google?q=an%20apple")); }); }); - it('should open search result with keywords in clipboard to new tabby P', async () => { + it("should open search result with keywords in clipboard to new tabby P", async () => { await clipboard.write(`an apple`); const page = await Page.navigateTo(webdriver, server.url()); - await page.sendKeys(Key.SHIFT, 'p'); + await page.sendKeys(Key.SHIFT, "p"); - await eventually(async() => { + await eventually(async () => { const tabs = await browser.tabs.query({}); - assert.deepStrictEqual(tabs.map((t: any) => t.url), [ - server.url(), - server.url('/google?q=an%20apple'), - ]); + assert.deepStrictEqual( + tabs.map((t: any) => t.url), + [server.url(), server.url("/google?q=an%20apple")] + ); }); }); }); diff --git a/e2e/command_addbookmark.test.ts b/e2e/command_addbookmark.test.ts index a54c103..4142e68 100644 --- a/e2e/command_addbookmark.test.ts +++ b/e2e/command_addbookmark.test.ts @@ -1,51 +1,54 @@ -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 } from 'selenium-webdriver'; -import Page from './lib/Page'; +import TestServer from "./lib/TestServer"; +import eventually from "./eventually"; +import { Builder, Lanthan } from "lanthan"; +import { WebDriver } from "selenium-webdriver"; +import Page from "./lib/Page"; -describe('addbookmark command test', () => { - const server = new TestServer().receiveContent('/happy', ` +describe("addbookmark command test", () => { + const server = new TestServer().receiveContent( + "/happy", + ` <!DOCTYPE html> - <html lang="en"><head><title>how to be happy</title></head></html>`, + <html lang="en"><head><title>how to be happy</title></head></html>` ); let lanthan: Lanthan; let webdriver: WebDriver; let browser: any; - before(async() => { - lanthan = await Builder - .forBrowser('firefox') - .spyAddon(path.join(__dirname, '..')) + before(async () => { + lanthan = await Builder.forBrowser("firefox") + .spyAddon(path.join(__dirname, "..")) .build(); webdriver = lanthan.getWebDriver(); browser = lanthan.getWebExtBrowser(); await server.start(); }); - after(async() => { + after(async () => { await server.stop(); if (lanthan) { await lanthan.quit(); } }); - beforeEach(async() => { - await webdriver.navigate().to(server.url('/happy')); + beforeEach(async () => { + await webdriver.navigate().to(server.url("/happy")); }); - it('should add a bookmark from the current page', async() => { + it("should add a bookmark from the current page", async () => { const page = await Page.currentContext(webdriver); const console = await page.showConsole(); - await console.execCommand('addbookmark how to be happy'); + await console.execCommand("addbookmark how to be happy"); - await eventually(async() => { - const bookmarks = await browser.bookmarks.search({ title: 'how to be happy' }); + await eventually(async () => { + const bookmarks = await browser.bookmarks.search({ + title: "how to be happy", + }); assert.strictEqual(bookmarks.length, 1); - assert.strictEqual(bookmarks[0].url, server.url('/happy')); + assert.strictEqual(bookmarks[0].url, server.url("/happy")); }); }); }); diff --git a/e2e/command_bdelete.test.ts b/e2e/command_bdelete.test.ts index c1f27ae..a85ce50 100644 --- a/e2e/command_bdelete.test.ts +++ b/e2e/command_bdelete.test.ts @@ -1,155 +1,165 @@ -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 } from 'selenium-webdriver'; -import Page from './lib/Page'; +import TestServer from "./lib/TestServer"; +import eventually from "./eventually"; +import { Builder, Lanthan } from "lanthan"; +import { WebDriver } from "selenium-webdriver"; +import Page from "./lib/Page"; -describe('bdelete/bdeletes command test', () => { - const server = new TestServer().receiveContent('/*', 'ok'); +describe("bdelete/bdeletes command test", () => { + const server = new TestServer().receiveContent("/*", "ok"); let lanthan: Lanthan; let webdriver: WebDriver; let browser: any; - before(async() => { - lanthan = await Builder - .forBrowser('firefox') - .spyAddon(path.join(__dirname, '..')) + before(async () => { + lanthan = await Builder.forBrowser("firefox") + .spyAddon(path.join(__dirname, "..")) .build(); webdriver = lanthan.getWebDriver(); browser = lanthan.getWebExtBrowser(); await server.start(); }); - 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); } - await browser.tabs.update(tabs[0].id, { url: server.url('/site1'), pinned: true }); - await browser.tabs.create({ url: server.url('/site2'), pinned: true }); - await browser.tabs.create({ url: server.url('/site3'), pinned: true }); - await browser.tabs.create({ url: server.url('/site4'), }); - await browser.tabs.create({ url: server.url('/site5'), }); + await browser.tabs.update(tabs[0].id, { + url: server.url("/site1"), + pinned: true, + }); + await browser.tabs.create({ url: server.url("/site2"), pinned: true }); + await browser.tabs.create({ url: server.url("/site3"), pinned: true }); + await browser.tabs.create({ url: server.url("/site4") }); + await browser.tabs.create({ url: server.url("/site5") }); - await eventually(async() => { + await eventually(async () => { const handles = await webdriver.getAllWindowHandles(); assert.strictEqual(handles.length, 5); await webdriver.switchTo().window(handles[2]); }); }); - it('should delete an unpinned tab by bdelete command', async() => { + it("should delete an unpinned tab by bdelete command", async () => { const page = await Page.currentContext(webdriver); const console = await page.showConsole(); - await console.execCommand('bdelete site5'); + await console.execCommand("bdelete site5"); - await eventually(async() => { + await eventually(async () => { const tabs = await browser.tabs.query({}); - assert.deepStrictEqual(tabs.map((t: any) => t.url), [ - server.url('/site1'), - server.url('/site2'), - server.url('/site3'), - server.url('/site4'), - ]) + assert.deepStrictEqual( + tabs.map((t: any) => t.url), + [ + server.url("/site1"), + server.url("/site2"), + server.url("/site3"), + server.url("/site4"), + ] + ); }); }); - it('should not delete an pinned tab by bdelete command by bdelete command', async() => { + it("should not delete an pinned tab by bdelete command by bdelete command", async () => { const page = await Page.currentContext(webdriver); const console = await page.showConsole(); - await console.execCommand('bdelete site1'); + await console.execCommand("bdelete site1"); - await eventually(async() => { + await eventually(async () => { const tabs = await browser.tabs.query({}); assert.strictEqual(tabs.length, 5); }); }); - it('should show an error when no tabs are matched by bdelete command', async() => { + it("should show an error when no tabs are matched by bdelete command", async () => { const page = await Page.currentContext(webdriver); const console = await page.showConsole(); - await console.execCommand('bdelete xyz'); + await console.execCommand("bdelete xyz"); - await eventually(async() => { + await eventually(async () => { const text = await console.getErrorMessage(); - assert.strictEqual(text, 'No matching buffer for xyz'); + assert.strictEqual(text, "No matching buffer for xyz"); }); }); - it('should show an error when more than one tabs are matched by bdelete command', async() => { + it("should show an error when more than one tabs are matched by bdelete command", async () => { const page = await Page.currentContext(webdriver); const console = await page.showConsole(); - await console.execCommand('bdelete site'); + await console.execCommand("bdelete site"); - await eventually(async() => { + await eventually(async () => { const text = await console.getErrorMessage(); - assert.strictEqual(text, 'More than one match for site'); + assert.strictEqual(text, "More than one match for site"); }); }); - it('should delete an unpinned tab by bdelete! command', async() => { + it("should delete an unpinned tab by bdelete! command", async () => { const page = await Page.currentContext(webdriver); const console = await page.showConsole(); - await console.execCommand('bdelete! site5'); + await console.execCommand("bdelete! site5"); - await eventually(async() => { + await eventually(async () => { const tabs = await browser.tabs.query({}); - assert.deepStrictEqual(tabs.map((t: any) => t.url), [ - server.url('/site1'), - server.url('/site2'), - server.url('/site3'), - server.url('/site4'), - ]) + assert.deepStrictEqual( + tabs.map((t: any) => t.url), + [ + server.url("/site1"), + server.url("/site2"), + server.url("/site3"), + server.url("/site4"), + ] + ); }); }); - it('should delete an pinned tab by bdelete! command', async() => { + it("should delete an pinned tab by bdelete! command", async () => { const page = await Page.currentContext(webdriver); const console = await page.showConsole(); - await console.execCommand('bdelete! site1'); + await console.execCommand("bdelete! site1"); - await eventually(async() => { + await eventually(async () => { const tabs = await browser.tabs.query({}); - assert.deepStrictEqual(tabs.map((t: any) => t.url), [ - server.url('/site2'), - server.url('/site3'), - server.url('/site4'), - server.url('/site5'), - ]) + assert.deepStrictEqual( + tabs.map((t: any) => t.url), + [ + server.url("/site2"), + server.url("/site3"), + server.url("/site4"), + server.url("/site5"), + ] + ); }); }); - it('should delete unpinned tabs by bdeletes command', async() => { + it("should delete unpinned tabs by bdeletes command", async () => { const page = await Page.currentContext(webdriver); const console = await page.showConsole(); - await console.execCommand('bdeletes site'); + await console.execCommand("bdeletes site"); - await eventually(async() => { + await eventually(async () => { const tabs = await browser.tabs.query({}); - assert.deepStrictEqual(tabs.map((t: any) => t.url), [ - server.url('/site1'), - server.url('/site2'), - server.url('/site3'), - ]) + assert.deepStrictEqual( + tabs.map((t: any) => t.url), + [server.url("/site1"), server.url("/site2"), server.url("/site3")] + ); }); }); - it('should delete both pinned and unpinned tabs by bdeletes! command', async() => { + it("should delete both pinned and unpinned tabs by bdeletes! command", async () => { const page = await Page.currentContext(webdriver); const console = await page.showConsole(); - await console.execCommand('bdeletes! site'); + await console.execCommand("bdeletes! site"); - await eventually(async() => { + await eventually(async () => { const tabs = await browser.tabs.query({}); assert.strictEqual(tabs.length, 1); }); diff --git a/e2e/command_buffer.test.ts b/e2e/command_buffer.test.ts index 3fa67ba..114f4b4 100644 --- a/e2e/command_buffer.test.ts +++ b/e2e/command_buffer.test.ts @@ -1,160 +1,162 @@ -import * as path from 'path'; -import * as assert from 'assert'; -import { Request, Response } from 'express'; - -import TestServer from './lib/TestServer'; -import eventually from './eventually'; -import { Builder, Lanthan } from 'lanthan'; -import { WebDriver } from 'selenium-webdriver'; -import Page from './lib/Page'; - -describe('buffer command test', () => { - const server = new TestServer().handle('/*', (req: Request, res: Response) => { - res.send(` +import * as path from "path"; +import * as assert from "assert"; +import { Request, Response } from "express"; + +import TestServer from "./lib/TestServer"; +import eventually from "./eventually"; +import { Builder, Lanthan } from "lanthan"; +import { WebDriver } from "selenium-webdriver"; +import Page from "./lib/Page"; + +describe("buffer command test", () => { + const server = new TestServer().handle( + "/*", + (req: Request, res: Response) => { + res.send(` <!DOCTYPE html> <html lang="en"> <head> <title>my_${req.path.slice(1)}</title> </head> </html>`); - }); + } + ); let lanthan: Lanthan; let webdriver: WebDriver; let browser: any; - before(async() => { - lanthan = await Builder - .forBrowser('firefox') - .spyAddon(path.join(__dirname, '..')) + before(async () => { + lanthan = await Builder.forBrowser("firefox") + .spyAddon(path.join(__dirname, "..")) .build(); webdriver = lanthan.getWebDriver(); browser = lanthan.getWebExtBrowser(); await server.start(); }); - 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); } - await browser.tabs.update(tabs[0].id, { url: server.url('/site1') }); + await browser.tabs.update(tabs[0].id, { url: server.url("/site1") }); for (let i = 2; i <= 5; ++i) { - await browser.tabs.create({ url: server.url('/site' + i) }); + await browser.tabs.create({ url: server.url("/site" + i) }); } - await eventually(async() => { + await eventually(async () => { const handles = await webdriver.getAllWindowHandles(); assert.strictEqual(handles.length, 5); await webdriver.switchTo().window(handles[2]); }); }); - it('should do nothing by buffer command with no parameters', async() => { + it("should do nothing by buffer command with no parameters", async () => { const page = await Page.currentContext(webdriver); const console = await page.showConsole(); - await console.execCommand('buffer'); + await console.execCommand("buffer"); - await eventually(async() => { + await eventually(async () => { const tabs = await browser.tabs.query({ active: true }); assert.strictEqual(tabs[0].index, 2); }); }); - it('should select a tab by buffer command with a number', async() => { + it("should select a tab by buffer command with a number", async () => { const page = await Page.currentContext(webdriver); const console = await page.showConsole(); - await console.execCommand('buffer 1'); + await console.execCommand("buffer 1"); - await eventually(async() => { + await eventually(async () => { const tabs = await browser.tabs.query({ active: true }); assert.strictEqual(tabs[0].index, 0); }); }); - it('should should an out of range error by buffer commands', async() => { + it("should should an out of range error by buffer commands", async () => { const page = await Page.currentContext(webdriver); let console = await page.showConsole(); - await console.execCommand('buffer 0'); + await console.execCommand("buffer 0"); - await eventually(async() => { + await eventually(async () => { const text = await console.getErrorMessage(); - assert.strictEqual(text, 'tab 0 does not exist'); + assert.strictEqual(text, "tab 0 does not exist"); }); await (webdriver.switchTo() as any).parentFrame(); console = await page.showConsole(); - await console.execCommand('buffer 9'); + await console.execCommand("buffer 9"); - await eventually(async() => { + await eventually(async () => { const text = await console.getErrorMessage(); - assert.strictEqual(text, 'tab 9 does not exist'); + assert.strictEqual(text, "tab 9 does not exist"); }); }); - it('should select a tab by buffer command with a title', async() => { + it("should select a tab by buffer command with a title", async () => { const page = await Page.currentContext(webdriver); const console = await page.showConsole(); - await console.execCommand('buffer my_site1'); + await console.execCommand("buffer my_site1"); - await eventually(async() => { + await eventually(async () => { const tabs = await browser.tabs.query({ active: true }); assert.strictEqual(tabs[0].index, 0); }); }); - it('should select a tab by buffer command with an URL', async() => { + it("should select a tab by buffer command with an URL", async () => { const page = await Page.currentContext(webdriver); const console = await page.showConsole(); - await console.execCommand('buffer /site1'); + await console.execCommand("buffer /site1"); - await eventually(async() => { + await eventually(async () => { const tabs = await browser.tabs.query({ active: true }); assert.strictEqual(tabs[0].index, 0); }); }); - it('should select tabs rotately', async() => { + it("should select tabs rotately", async () => { const handles = await webdriver.getAllWindowHandles(); await webdriver.switchTo().window(handles[4]); const page = await Page.currentContext(webdriver); const console = await page.showConsole(); - await console.execCommand('buffer site'); + await console.execCommand("buffer site"); - await eventually(async() => { + await eventually(async () => { const tabs = await browser.tabs.query({ active: true }); assert.strictEqual(tabs[0].index, 0); }); }); - it('should do nothing by ":buffer %"', async() => { + it('should do nothing by ":buffer %"', async () => { const page = await Page.currentContext(webdriver); const console = await page.showConsole(); - await console.execCommand('buffer %'); + await console.execCommand("buffer %"); - await eventually(async() => { + await eventually(async () => { const tabs = await browser.tabs.query({ active: true }); assert.strictEqual(tabs[0].index, 2); }); }); - it('should selects last selected tab by ":buffer #"', async() => { + it('should selects last selected tab by ":buffer #"', async () => { const handles = await webdriver.getAllWindowHandles(); await webdriver.switchTo().window(handles[1]); const page = await Page.currentContext(webdriver); const console = await page.showConsole(); - await console.execCommand('buffer #'); + await console.execCommand("buffer #"); - await eventually(async() => { + await eventually(async () => { const tabs = await browser.tabs.query({ active: true }); assert.strictEqual(tabs[0].index, 2); }); diff --git a/e2e/command_help.test.ts b/e2e/command_help.test.ts index 9f8a459..40d4dde 100644 --- a/e2e/command_help.test.ts +++ b/e2e/command_help.test.ts @@ -1,11 +1,11 @@ -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 } from 'selenium-webdriver'; -import Page from './lib/Page'; +import TestServer from "./lib/TestServer"; +import eventually from "./eventually"; +import { Builder, Lanthan } from "lanthan"; +import { WebDriver } from "selenium-webdriver"; +import Page from "./lib/Page"; describe("help command test", () => { const server = new TestServer(); @@ -14,10 +14,9 @@ describe("help command test", () => { let browser: any; let page: Page; - before(async() => { - lanthan = await Builder - .forBrowser('firefox') - .spyAddon(path.join(__dirname, '..')) + before(async () => { + lanthan = await Builder.forBrowser("firefox") + .spyAddon(path.join(__dirname, "..")) .build(); webdriver = lanthan.getWebDriver(); browser = lanthan.getWebExtBrowser(); @@ -25,25 +24,24 @@ describe("help command test", () => { await server.start(); }); - after(async() => { + after(async () => { await server.stop(); if (lanthan) { await lanthan.quit(); } }); - beforeEach(async() => { + beforeEach(async () => { page = await Page.navigateTo(webdriver, server.url()); }); - it('should open help page by help command ', async() => { + it("should open help page by help command ", async () => { const console = await page.showConsole(); - await console.execCommand('help'); + await console.execCommand("help"); - await eventually(async() => { + await eventually(async () => { const tabs = await browser.tabs.query({ active: true }); - assert.strictEqual(tabs[0].url, 'https://ueokande.github.io/vim-vixen/') + assert.strictEqual(tabs[0].url, "https://ueokande.github.io/vim-vixen/"); }); }); }); - diff --git a/e2e/command_open.test.ts b/e2e/command_open.test.ts index f4d2aa1..2db522a 100644 --- a/e2e/command_open.test.ts +++ b/e2e/command_open.test.ts @@ -1,118 +1,119 @@ -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 } from 'selenium-webdriver'; -import Page from './lib/Page'; +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 } from "selenium-webdriver"; +import Page from "./lib/Page"; import SettingRepository from "./lib/SettingRepository"; import Settings from "../src/shared/settings/Settings"; describe("open command test", () => { const server = new TestServer() - .receiveContent('/google', 'google') - .receiveContent('/yahoo', 'yahoo'); + .receiveContent("/google", "google") + .receiveContent("/yahoo", "yahoo"); let lanthan: Lanthan; let webdriver: WebDriver; let browser: any; let page: Page; - before(async() => { - lanthan = await Builder - .forBrowser('firefox') - .spyAddon(path.join(__dirname, '..')) + before(async () => { + lanthan = await Builder.forBrowser("firefox") + .spyAddon(path.join(__dirname, "..")) .build(); webdriver = lanthan.getWebDriver(); browser = lanthan.getWebExtBrowser(); await server.start(); - await new SettingRepository(browser).saveJSON(Settings.fromJSON({ - search: { - default: "google", - engines: { - "google": server.url('/google?q={}'), - "yahoo": server.url('/yahoo?q={}'), + await new SettingRepository(browser).saveJSON( + Settings.fromJSON({ + search: { + default: "google", + engines: { + google: server.url("/google?q={}"), + yahoo: server.url("/yahoo?q={}"), + }, }, - }, - })); + }) + ); }); - after(async() => { + after(async () => { await server.stop(); if (lanthan) { await lanthan.quit(); } }); - beforeEach(async() => { + beforeEach(async () => { await webdriver.switchTo().defaultContent(); page = await Page.navigateTo(webdriver, server.url()); }); - it('should open default search for keywords by open command ', async() => { + it("should open default search for keywords by open command ", async () => { const console = await page.showConsole(); - await console.execCommand('open an apple'); + await console.execCommand("open an apple"); - await eventually(async() => { + await eventually(async () => { const tabs = await browser.tabs.query({ active: true }); const url = new URL(tabs[0].url); - assert.strictEqual(url.href, server.url('/google?q=an%20apple')) + assert.strictEqual(url.href, server.url("/google?q=an%20apple")); }); }); - it('should open certain search page for keywords by open command ', async() => { + it("should open certain search page for keywords by open command ", async () => { const console = await page.showConsole(); - await console.execCommand('open yahoo an apple'); + await console.execCommand("open yahoo an apple"); - await eventually(async() => { + await eventually(async () => { const tabs = await browser.tabs.query({ active: true }); const url = new URL(tabs[0].url); - assert.strictEqual(url.href, server.url('/yahoo?q=an%20apple')) + assert.strictEqual(url.href, server.url("/yahoo?q=an%20apple")); }); }); - it('should open default engine with empty keywords by open command ', async() => { + it("should open default engine with empty keywords by open command ", async () => { const console = await page.showConsole(); - await console.execCommand('open'); + await console.execCommand("open"); - await eventually(async() => { + await eventually(async () => { const tabs = await browser.tabs.query({ active: true }); const url = new URL(tabs[0].url); - assert.strictEqual(url.href, server.url('/google?q=')) + assert.strictEqual(url.href, server.url("/google?q=")); }); }); - it('should open certain search page for empty keywords by open command ', async() => { + it("should open certain search page for empty keywords by open command ", async () => { const console = await page.showConsole(); - await console.execCommand('open yahoo'); + await console.execCommand("open yahoo"); - await eventually(async() => { + await eventually(async () => { const tabs = await browser.tabs.query({ active: true }); const url = new URL(tabs[0].url); - assert.strictEqual(url.href, server.url('/yahoo?q=')) + assert.strictEqual(url.href, server.url("/yahoo?q=")); }); }); - it('should open a site with domain by open command ', async() => { + it("should open a site with domain by open command ", async () => { const console = await page.showConsole(); - await console.execCommand('open example.com'); + await console.execCommand("open example.com"); - await eventually(async() => { + await eventually(async () => { const tabs = await browser.tabs.query({ active: true }); const url = new URL(tabs[0].url); - assert.strictEqual(url.href, 'http://example.com/') + assert.strictEqual(url.href, "http://example.com/"); }); }); - it('should open a site with URL by open command ', async() => { + it("should open a site with URL by open command ", async () => { const console = await page.showConsole(); - await console.execCommand('open https://example.com/'); + await console.execCommand("open https://example.com/"); - await eventually(async() => { + await eventually(async () => { const tabs = await browser.tabs.query({ active: true }); const url = new URL(tabs[0].url); - assert.strictEqual(url.href, 'https://example.com/') + assert.strictEqual(url.href, "https://example.com/"); }); }); }); diff --git a/e2e/command_quit.test.ts b/e2e/command_quit.test.ts index 037ad09..d59abfc 100644 --- a/e2e/command_quit.test.ts +++ b/e2e/command_quit.test.ts @@ -1,93 +1,92 @@ -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 } from 'selenium-webdriver'; -import Page from './lib/Page'; +import TestServer from "./lib/TestServer"; +import eventually from "./eventually"; +import { Builder, Lanthan } from "lanthan"; +import { WebDriver } from "selenium-webdriver"; +import Page from "./lib/Page"; -describe('quit/quitall command test', () => { - const server = new TestServer().receiveContent('/*', 'ok'); +describe("quit/quitall command test", () => { + const server = new TestServer().receiveContent("/*", "ok"); let lanthan: Lanthan; let webdriver: WebDriver; let browser: any; - before(async() => { - lanthan = await Builder - .forBrowser('firefox') - .spyAddon(path.join(__dirname, '..')) + before(async () => { + lanthan = await Builder.forBrowser("firefox") + .spyAddon(path.join(__dirname, "..")) .build(); webdriver = lanthan.getWebDriver(); browser = lanthan.getWebExtBrowser(); await server.start(); }); - 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); } - await browser.tabs.update(tabs[0].id, { url: server.url('/site1') }); + await browser.tabs.update(tabs[0].id, { url: server.url("/site1") }); for (let i = 2; i <= 5; ++i) { - await browser.tabs.create({ url: server.url('/site' + i) }) + await browser.tabs.create({ url: server.url("/site" + i) }); } - await eventually(async() => { + await eventually(async () => { const handles = await webdriver.getAllWindowHandles(); assert.strictEqual(handles.length, 5); await webdriver.switchTo().window(handles[2]); }); }); - it('should current tab by q command', async() => { + it("should current tab by q command", async () => { const page = await Page.currentContext(webdriver); const console = await page.showConsole(); - await console.execCommand('q'); + await console.execCommand("q"); - await eventually(async() => { + await eventually(async () => { const tabs = await browser.tabs.query({}); - assert.strictEqual(tabs.length, 4) + assert.strictEqual(tabs.length, 4); }); }); - it('should current tab by quit command', async() => { + it("should current tab by quit command", async () => { const page = await Page.currentContext(webdriver); const console = await page.showConsole(); - await console.execCommand('quit'); + await console.execCommand("quit"); - await eventually(async() => { + await eventually(async () => { const tabs = await browser.tabs.query({}); - assert.strictEqual(tabs.length, 4) + assert.strictEqual(tabs.length, 4); }); }); - it('should current tab by qa command', async() => { + it("should current tab by qa command", async () => { const page = await Page.currentContext(webdriver); const console = await page.showConsole(); - await console.execCommand('qa'); + await console.execCommand("qa"); - await eventually(async() => { + await eventually(async () => { const tabs = await browser.tabs.query({}); - assert.strictEqual(tabs.length, 1) + assert.strictEqual(tabs.length, 1); }); }); - it('should current tab by quitall command', async() => { + it("should current tab by quitall command", async () => { const page = await Page.currentContext(webdriver); const console = await page.showConsole(); - await console.execCommand('quitall'); + await console.execCommand("quitall"); - await eventually(async() => { + await eventually(async () => { const tabs = await browser.tabs.query({}); - assert.strictEqual(tabs.length, 1) + assert.strictEqual(tabs.length, 1); }); }); }); diff --git a/e2e/command_tabopen.test.ts b/e2e/command_tabopen.test.ts index e96c29e..9807a03 100644 --- a/e2e/command_tabopen.test.ts +++ b/e2e/command_tabopen.test.ts @@ -1,51 +1,52 @@ -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 } from 'selenium-webdriver'; -import Page from './lib/Page'; +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 } from "selenium-webdriver"; +import Page from "./lib/Page"; import SettingRepository from "./lib/SettingRepository"; import Settings from "../src/shared/settings/Settings"; describe("tabopen command test", () => { const server = new TestServer() - .receiveContent('/google', 'google') - .receiveContent('/yahoo', 'yahoo'); + .receiveContent("/google", "google") + .receiveContent("/yahoo", "yahoo"); let lanthan: Lanthan; let webdriver: WebDriver; let browser: any; let page: Page; - before(async() => { - lanthan = await Builder - .forBrowser('firefox') - .spyAddon(path.join(__dirname, '..')) + before(async () => { + lanthan = await Builder.forBrowser("firefox") + .spyAddon(path.join(__dirname, "..")) .build(); webdriver = lanthan.getWebDriver(); browser = lanthan.getWebExtBrowser(); await server.start(); - await new SettingRepository(browser).saveJSON(Settings.fromJSON({ - search: { - default: "google", - engines: { - "google": server.url('/google?q={}'), - "yahoo": server.url('/yahoo?q={}'), + await new SettingRepository(browser).saveJSON( + Settings.fromJSON({ + search: { + default: "google", + engines: { + google: server.url("/google?q={}"), + yahoo: server.url("/yahoo?q={}"), + }, }, - }, - })); + }) + ); }); - 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); @@ -54,75 +55,75 @@ describe("tabopen command test", () => { page = await Page.navigateTo(webdriver, server.url()); }); - it('should open default search for keywords by tabopen command ', async() => { + it("should open default search for keywords by tabopen command ", async () => { const console = await page.showConsole(); - await console.execCommand('tabopen an apple'); + await console.execCommand("tabopen an apple"); - await eventually(async() => { + await eventually(async () => { const tabs = await browser.tabs.query({}); assert.strictEqual(tabs.length, 2); const url = new URL(tabs[1].url); - assert.strictEqual(url.href, server.url('/google?q=an%20apple') ) + assert.strictEqual(url.href, server.url("/google?q=an%20apple")); }); }); - it('should open certain search page for keywords by tabopen command ', async() => { + it("should open certain search page for keywords by tabopen command ", async () => { const console = await page.showConsole(); - await console.execCommand('tabopen yahoo an apple'); + await console.execCommand("tabopen yahoo an apple"); - await eventually(async() => { + await eventually(async () => { const tabs = await browser.tabs.query({}); assert.strictEqual(tabs.length, 2); const url = new URL(tabs[1].url); - assert.strictEqual(url.href, server.url('/yahoo?q=an%20apple')) + assert.strictEqual(url.href, server.url("/yahoo?q=an%20apple")); }); }); - it('should open default engine with empty keywords by tabopen command ', async() => { + it("should open default engine with empty keywords by tabopen command ", async () => { const console = await page.showConsole(); - await console.execCommand('tabopen'); + await console.execCommand("tabopen"); - await eventually(async() => { + await eventually(async () => { const tabs = await browser.tabs.query({}); assert.strictEqual(tabs.length, 2); const url = new URL(tabs[1].url); - assert.strictEqual(url.href, server.url('/google?q=')) + assert.strictEqual(url.href, server.url("/google?q=")); }); }); - it('should open certain search page for empty keywords by tabopen command ', async() => { + it("should open certain search page for empty keywords by tabopen command ", async () => { const console = await page.showConsole(); - await console.execCommand('tabopen yahoo'); + await console.execCommand("tabopen yahoo"); - await eventually(async() => { + await eventually(async () => { const tabs = await browser.tabs.query({}); assert.strictEqual(tabs.length, 2); const url = new URL(tabs[1].url); - assert.strictEqual(url.href, server.url('/yahoo?q=')) + assert.strictEqual(url.href, server.url("/yahoo?q=")); }); }); - it('should open a site with domain by tabopen command ', async() => { + it("should open a site with domain by tabopen command ", async () => { const console = await page.showConsole(); - await console.execCommand('tabopen example.com'); + await console.execCommand("tabopen example.com"); - await eventually(async() => { + await eventually(async () => { const tabs = await browser.tabs.query({}); assert.strictEqual(tabs.length, 2); const url = new URL(tabs[1].url); - assert.strictEqual(url.href, 'http://example.com/') + assert.strictEqual(url.href, "http://example.com/"); }); }); - it('should open a site with URL by tabopen command ', async() => { + it("should open a site with URL by tabopen command ", async () => { const console = await page.showConsole(); - await console.execCommand('tabopen https://example.com/'); + await console.execCommand("tabopen https://example.com/"); - await eventually(async() => { + await eventually(async () => { const tabs = await browser.tabs.query({}); assert.strictEqual(tabs.length, 2); const url = new URL(tabs[1].url); - assert.strictEqual(url.href, 'https://example.com/') + assert.strictEqual(url.href, "https://example.com/"); }); }); }); diff --git a/e2e/command_winopen.test.ts b/e2e/command_winopen.test.ts index c9ff8d2..1d13edd 100644 --- a/e2e/command_winopen.test.ts +++ b/e2e/command_winopen.test.ts @@ -1,51 +1,52 @@ -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 } from 'selenium-webdriver'; -import Page from './lib/Page'; +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 } from "selenium-webdriver"; +import Page from "./lib/Page"; import SettingRepository from "./lib/SettingRepository"; import Settings from "../src/shared/settings/Settings"; describe("winopen command test", () => { const server = new TestServer() - .receiveContent('/google', 'google') - .receiveContent('/yahoo', 'yahoo'); + .receiveContent("/google", "google") + .receiveContent("/yahoo", "yahoo"); let lanthan: Lanthan; let webdriver: WebDriver; let browser: any; let page: Page; - before(async() => { - lanthan = await Builder - .forBrowser('firefox') - .spyAddon(path.join(__dirname, '..')) + before(async () => { + lanthan = await Builder.forBrowser("firefox") + .spyAddon(path.join(__dirname, "..")) .build(); webdriver = lanthan.getWebDriver(); browser = lanthan.getWebExtBrowser(); await server.start(); - await new SettingRepository(browser).saveJSON(Settings.fromJSON({ - search: { - default: "google", - engines: { - "google": server.url('/google?q={}'), - "yahoo": server.url('/yahoo?q={}'), + await new SettingRepository(browser).saveJSON( + Settings.fromJSON({ + search: { + default: "google", + engines: { + google: server.url("/google?q={}"), + yahoo: server.url("/yahoo?q={}"), + }, }, - }, - })); + }) + ); }); - after(async() => { + after(async () => { await server.stop(); if (lanthan) { await lanthan.quit(); } }); - beforeEach(async() => { + beforeEach(async () => { const wins = await browser.windows.getAll(); for (const win of wins.slice(1)) { await browser.windows.remove(win.id); @@ -54,87 +55,87 @@ describe("winopen command test", () => { page = await Page.navigateTo(webdriver, server.url()); }); - it('should open default search for keywords by winopen command ', async() => { + it("should open default search for keywords by winopen command ", async () => { const console = await page.showConsole(); - await console.execCommand('winopen an apple'); + await console.execCommand("winopen an apple"); - await eventually(async() => { + await eventually(async () => { const wins = await browser.windows.getAll(); assert.strictEqual(wins.length, 2); const tabs = await browser.tabs.query({ windowId: wins[1].id }); const url = new URL(tabs[0].url); - assert.strictEqual(url.href, server.url('/google?q=an%20apple')) + assert.strictEqual(url.href, server.url("/google?q=an%20apple")); }); }); - it('should open certain search page for keywords by winopen command ', async() => { + it("should open certain search page for keywords by winopen command ", async () => { const console = await page.showConsole(); - await console.execCommand('winopen yahoo an apple'); + await console.execCommand("winopen yahoo an apple"); - await eventually(async() => { + await eventually(async () => { const wins = await browser.windows.getAll(); assert.strictEqual(wins.length, 2); const tabs = await browser.tabs.query({ windowId: wins[1].id }); const url = new URL(tabs[0].url); - assert.strictEqual(url.href, server.url('/yahoo?q=an%20apple')) + assert.strictEqual(url.href, server.url("/yahoo?q=an%20apple")); }); }); - it('should open default engine with empty keywords by winopen command ', async() => { + it("should open default engine with empty keywords by winopen command ", async () => { const console = await page.showConsole(); - await console.execCommand('winopen'); + await console.execCommand("winopen"); - await eventually(async() => { + await eventually(async () => { const wins = await browser.windows.getAll(); assert.strictEqual(wins.length, 2); const tabs = await browser.tabs.query({ windowId: wins[1].id }); const url = new URL(tabs[0].url); - assert.strictEqual(url.href, server.url('/google?q=')) + assert.strictEqual(url.href, server.url("/google?q=")); }); }); - it('should open certain search page for empty keywords by winopen command ', async() => { + it("should open certain search page for empty keywords by winopen command ", async () => { const console = await page.showConsole(); - await console.execCommand('winopen yahoo'); + await console.execCommand("winopen yahoo"); - await eventually(async() => { + await eventually(async () => { const wins = await browser.windows.getAll(); assert.strictEqual(wins.length, 2); const tabs = await browser.tabs.query({ windowId: wins[1].id }); const url = new URL(tabs[0].url); - assert.strictEqual(url.href, server.url('/yahoo?q=')) + assert.strictEqual(url.href, server.url("/yahoo?q=")); }); }); - it('should open a site with domain by winopen command ', async() => { + it("should open a site with domain by winopen command ", async () => { const console = await page.showConsole(); - await console.execCommand('winopen example.com'); + await console.execCommand("winopen example.com"); - await eventually(async() => { + await eventually(async () => { const wins = await browser.windows.getAll(); assert.strictEqual(wins.length, 2); const tabs = await browser.tabs.query({ windowId: wins[1].id }); const url = new URL(tabs[0].url); - assert.strictEqual(url.href, 'http://example.com/') + assert.strictEqual(url.href, "http://example.com/"); }); }); - it('should open a site with URL by winopen command ', async() => { + it("should open a site with URL by winopen command ", async () => { const console = await page.showConsole(); - await console.execCommand('winopen https://example.com/'); + await console.execCommand("winopen https://example.com/"); - await eventually(async() => { + await eventually(async () => { const wins = await browser.windows.getAll(); assert.strictEqual(wins.length, 2); const tabs = await browser.tabs.query({ windowId: wins[1].id }); const url = new URL(tabs[0].url); - assert.strictEqual(url.href, 'https://example.com/') + assert.strictEqual(url.href, "https://example.com/"); }); }); }); diff --git a/e2e/completion.test.ts b/e2e/completion.test.ts index 1ce430e..bc065d3 100644 --- a/e2e/completion.test.ts +++ b/e2e/completion.test.ts @@ -1,93 +1,98 @@ -import * as path from 'path'; -import * as assert from 'assert'; +import * as path from "path"; +import * as assert from "assert"; -import eventually from './eventually'; -import { Builder, Lanthan } from 'lanthan'; -import { WebDriver, Key } from 'selenium-webdriver'; -import Page from './lib/Page'; +import eventually from "./eventually"; +import { Builder, Lanthan } from "lanthan"; +import { WebDriver, Key } from "selenium-webdriver"; +import Page from "./lib/Page"; describe("general completion test", () => { let lanthan: Lanthan; let webdriver: WebDriver; let page: Page; - before(async() => { - lanthan = await Builder - .forBrowser('firefox') - .spyAddon(path.join(__dirname, '..')) + before(async () => { + lanthan = await Builder.forBrowser("firefox") + .spyAddon(path.join(__dirname, "..")) .build(); webdriver = lanthan.getWebDriver(); }); - after(async() => { + after(async () => { if (lanthan) { await lanthan.quit(); } }); - beforeEach(async() => { - page = await Page.navigateTo(webdriver, 'about:blank'); + beforeEach(async () => { + page = await Page.navigateTo(webdriver, "about:blank"); }); - it('should all commands on empty line', async() => { + it("should all commands on empty line", async () => { const console = await page.showConsole(); const items = await console.getCompletions(); assert.strictEqual(items.length, 12); - assert.deepStrictEqual(items[0], { type: 'title', text: 'Console Command' }); - assert.ok(items[1].text.startsWith('set')); - assert.ok(items[2].text.startsWith('open')); - assert.ok(items[3].text.startsWith('tabopen')) + assert.deepStrictEqual(items[0], { + type: "title", + text: "Console Command", + }); + assert.ok(items[1].text.startsWith("set")); + assert.ok(items[2].text.startsWith("open")); + assert.ok(items[3].text.startsWith("tabopen")); }); - it('should only commands filtered by prefix', async() => { + it("should only commands filtered by prefix", async () => { const console = await page.showConsole(); - await console.inputKeys('b'); + await console.inputKeys("b"); const items = await console.getCompletions(); assert.strictEqual(items.length, 4); - assert.deepStrictEqual(items[0], { type: 'title', text: 'Console Command' }); - assert.ok(items[1].text.startsWith('buffer')); - assert.ok(items[2].text.startsWith('bdelete')); - assert.ok(items[3].text.startsWith('bdeletes')) + assert.deepStrictEqual(items[0], { + type: "title", + text: "Console Command", + }); + assert.ok(items[1].text.startsWith("buffer")); + assert.ok(items[2].text.startsWith("bdelete")); + assert.ok(items[3].text.startsWith("bdeletes")); }); // > byffer // > bdelete // > bdeletes // : b - it('selects completion items by <Tab>/<S-Tab> keys', async() => { + it("selects completion items by <Tab>/<S-Tab> keys", async () => { const console = await page.showConsole(); - await console.inputKeys('b'); - await eventually(async() => { + await console.inputKeys("b"); + await eventually(async () => { const items = await console.getCompletions(); assert.strictEqual(items.length, 4); }); await console.sendKeys(Key.TAB); - await eventually(async() => { + await eventually(async () => { const items = await console.getCompletions(); assert.ok(items[1].highlight); - assert.strictEqual(await console.currentValue(), 'buffer'); + assert.strictEqual(await console.currentValue(), "buffer"); }); await console.sendKeys(Key.TAB, Key.TAB); - await eventually(async() => { + await eventually(async () => { const items = await console.getCompletions(); assert.ok(items[3].highlight); - assert.strictEqual(await console.currentValue(), 'bdeletes'); + assert.strictEqual(await console.currentValue(), "bdeletes"); }); await console.sendKeys(Key.TAB); - await eventually(async() => { - assert.strictEqual(await console.currentValue(), 'b'); + await eventually(async () => { + assert.strictEqual(await console.currentValue(), "b"); }); await console.sendKeys(Key.SHIFT, Key.TAB); - await eventually(async() => { + await eventually(async () => { const items = await console.getCompletions(); assert.ok(items[3].highlight); - assert.strictEqual(await console.currentValue(), 'bdeletes'); + assert.strictEqual(await console.currentValue(), "bdeletes"); }); }); }); diff --git a/e2e/completion_buffers.test.ts b/e2e/completion_buffers.test.ts index ac24753..57603f6 100644 --- a/e2e/completion_buffers.test.ts +++ b/e2e/completion_buffers.test.ts @@ -1,32 +1,34 @@ -import * as assert from 'assert'; -import * as path from 'path'; +import * as assert from "assert"; +import * as path from "path"; -import { Request, Response } from 'express' -import TestServer from './lib/TestServer'; -import eventually from './eventually'; -import { Builder, Lanthan } from 'lanthan'; -import { WebDriver } from 'selenium-webdriver'; -import Page from './lib/Page'; +import { Request, Response } from "express"; +import TestServer from "./lib/TestServer"; +import eventually from "./eventually"; +import { Builder, Lanthan } from "lanthan"; +import { WebDriver } from "selenium-webdriver"; +import Page from "./lib/Page"; describe("completion on buffer/bdelete/bdeletes", () => { - const server = new TestServer().handle('/*', (req: Request, res: Response) => { - res.send(` + const server = new TestServer().handle( + "/*", + (req: Request, res: Response) => { + res.send(` <!DOCTYPE html> <html lang="en"> <head> <title>title_${req.path.slice(1)}</title> </head> </html>`); - }); + } + ); let lanthan: Lanthan; let webdriver: WebDriver; let browser: any; let page: Page; - before(async() => { - lanthan = await Builder - .forBrowser('firefox') - .spyAddon(path.join(__dirname, '..')) + before(async () => { + lanthan = await Builder.forBrowser("firefox") + .spyAddon(path.join(__dirname, "..")) .build(); webdriver = lanthan.getWebDriver(); browser = lanthan.getWebExtBrowser(); @@ -34,26 +36,29 @@ describe("completion on buffer/bdelete/bdeletes", () => { await server.start(); }); - 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); } - await browser.tabs.update(tabs[0].id, { url: server.url('/site1'), pinned: true }); - await browser.tabs.create({ url:server.url('/site2'), pinned: true }); + await browser.tabs.update(tabs[0].id, { + url: server.url("/site1"), + pinned: true, + }); + await browser.tabs.create({ url: server.url("/site2"), pinned: true }); for (let i = 3; i <= 5; ++i) { - await browser.tabs.create({ url: server.url('/site' + i) }); + await browser.tabs.create({ url: server.url("/site" + i) }); } - await eventually(async() => { + await eventually(async () => { const handles = await webdriver.getAllWindowHandles(); assert.strictEqual(handles.length, 5); await webdriver.switchTo().window(handles[2]); @@ -62,114 +67,114 @@ describe("completion on buffer/bdelete/bdeletes", () => { page = await Page.currentContext(webdriver); }); - it('should all tabs by "buffer" command with empty params', async() => { + it('should all tabs by "buffer" command with empty params', async () => { const console = await page.showConsole(); - await console.inputKeys('buffer '); + await console.inputKeys("buffer "); - await eventually(async() => { + await eventually(async () => { const items = await console.getCompletions(); assert.strictEqual(items.length, 6); - assert.deepStrictEqual(items[0], { type: 'title', text: 'Buffers' }); - assert.ok(items[1].text.startsWith('1:')); - assert.ok(items[2].text.startsWith('2:')); - assert.ok(items[3].text.startsWith('3:')); - assert.ok(items[4].text.startsWith('4:')); - assert.ok(items[5].text.startsWith('5:')); - - assert.ok(items[3].text.includes('%')); - assert.ok(items[5].text.includes('#')); + assert.deepStrictEqual(items[0], { type: "title", text: "Buffers" }); + assert.ok(items[1].text.startsWith("1:")); + assert.ok(items[2].text.startsWith("2:")); + assert.ok(items[3].text.startsWith("3:")); + assert.ok(items[4].text.startsWith("4:")); + assert.ok(items[5].text.startsWith("5:")); + + assert.ok(items[3].text.includes("%")); + assert.ok(items[5].text.includes("#")); }); }); - it('should filter items with URLs by keywords on "buffer" command', async() => { + it('should filter items with URLs by keywords on "buffer" command', async () => { const console = await page.showConsole(); - await console.inputKeys('buffer title_site2'); + await console.inputKeys("buffer title_site2"); - await eventually(async() => { + await eventually(async () => { const items = await console.getCompletions(); - assert.deepStrictEqual(items[0], { type: 'title', text: 'Buffers' }); - assert.ok(items[1].text.startsWith('2:')); - assert.ok(items[1].text.includes('title_site2')); - assert.ok(items[1].text.includes(server.url('/site2'))); + assert.deepStrictEqual(items[0], { type: "title", text: "Buffers" }); + assert.ok(items[1].text.startsWith("2:")); + assert.ok(items[1].text.includes("title_site2")); + assert.ok(items[1].text.includes(server.url("/site2"))); }); }); - it('should filter items with titles by keywords on "buffer" command', async() => { + it('should filter items with titles by keywords on "buffer" command', async () => { const console = await page.showConsole(); - await console.inputKeys('buffer /site2'); + await console.inputKeys("buffer /site2"); - await eventually(async() => { + await eventually(async () => { const items = await console.getCompletions(); - assert.deepStrictEqual(items[0], { type: 'title', text: 'Buffers' }); - assert.ok(items[1].text.startsWith('2:')); + assert.deepStrictEqual(items[0], { type: "title", text: "Buffers" }); + assert.ok(items[1].text.startsWith("2:")); }); }); - it('should show one item by number on "buffer" command', async() => { + it('should show one item by number on "buffer" command', async () => { const console = await page.showConsole(); - await console.inputKeys('buffer 2'); + await console.inputKeys("buffer 2"); - await eventually(async() => { + await eventually(async () => { const items = await console.getCompletions(); assert.strictEqual(items.length, 2); - assert.deepStrictEqual(items[0], { type: 'title', text: 'Buffers' }); - assert.ok(items[1].text.startsWith('2:')); + assert.deepStrictEqual(items[0], { type: "title", text: "Buffers" }); + assert.ok(items[1].text.startsWith("2:")); }); }); - it('should show unpinned tabs "bdelete" command', async() => { + it('should show unpinned tabs "bdelete" command', async () => { const console = await page.showConsole(); - await console.inputKeys('bdelete site'); + await console.inputKeys("bdelete site"); - await eventually(async() => { + await eventually(async () => { const items = await console.getCompletions(); assert.strictEqual(items.length, 4); - assert.ok(items[1].text.includes('site3')); - assert.ok(items[2].text.includes('site4')); - assert.ok(items[3].text.includes('site5')); + assert.ok(items[1].text.includes("site3")); + assert.ok(items[2].text.includes("site4")); + assert.ok(items[3].text.includes("site5")); }); }); - it('should show unpinned tabs "bdeletes" command', async() => { + it('should show unpinned tabs "bdeletes" command', async () => { const console = await page.showConsole(); - await console.inputKeys('bdeletes site'); + await console.inputKeys("bdeletes site"); - await eventually(async() => { + await eventually(async () => { const items = await console.getCompletions(); assert.strictEqual(items.length, 4); - assert.ok(items[1].text.includes('site3')); - assert.ok(items[2].text.includes('site4')); - assert.ok(items[3].text.includes('site5')); + assert.ok(items[1].text.includes("site3")); + assert.ok(items[2].text.includes("site4")); + assert.ok(items[3].text.includes("site5")); }); }); - it('should show both pinned and unpinned tabs "bdelete!" command', async() => { + it('should show both pinned and unpinned tabs "bdelete!" command', async () => { const console = await page.showConsole(); - await console.inputKeys('bdelete! site'); + await console.inputKeys("bdelete! site"); - await eventually(async() => { + await eventually(async () => { const items = await console.getCompletions(); assert.strictEqual(items.length, 6); - assert.ok(items[1].text.includes('site1')); - assert.ok(items[2].text.includes('site2')); - assert.ok(items[3].text.includes('site3')); - assert.ok(items[4].text.includes('site4')); - assert.ok(items[5].text.includes('site5')); + assert.ok(items[1].text.includes("site1")); + assert.ok(items[2].text.includes("site2")); + assert.ok(items[3].text.includes("site3")); + assert.ok(items[4].text.includes("site4")); + assert.ok(items[5].text.includes("site5")); }); }); - it('should show both pinned and unpinned tabs "bdeletes!" command', async() => { + it('should show both pinned and unpinned tabs "bdeletes!" command', async () => { const console = await page.showConsole(); - await console.inputKeys('bdeletes! site'); + await console.inputKeys("bdeletes! site"); - await eventually(async() => { + await eventually(async () => { const items = await console.getCompletions(); assert.strictEqual(items.length, 6); - assert.ok(items[1].text.includes('site1')); - assert.ok(items[2].text.includes('site2')); - assert.ok(items[3].text.includes('site3')); - assert.ok(items[4].text.includes('site4')); - assert.ok(items[5].text.includes('site5')); + assert.ok(items[1].text.includes("site1")); + assert.ok(items[2].text.includes("site2")); + assert.ok(items[3].text.includes("site3")); + assert.ok(items[4].text.includes("site4")); + assert.ok(items[5].text.includes("site5")); }); }); }); diff --git a/e2e/completion_open.test.ts b/e2e/completion_open.test.ts index 95d4175..cefb44f 100644 --- a/e2e/completion_open.test.ts +++ b/e2e/completion_open.test.ts @@ -1,159 +1,202 @@ -import * as path from 'path'; -import * as assert from 'assert'; +import * as path from "path"; +import * as assert from "assert"; import Settings from "../src/shared/settings/Settings"; -import TestServer from './lib/TestServer'; -import eventually from './eventually'; -import { Builder, Lanthan } from 'lanthan'; -import { WebDriver } from 'selenium-webdriver'; -import Page from './lib/Page'; +import TestServer from "./lib/TestServer"; +import eventually from "./eventually"; +import { Builder, Lanthan } from "lanthan"; +import { WebDriver } from "selenium-webdriver"; +import Page from "./lib/Page"; import SettingRepository from "./lib/SettingRepository"; describe("completion on open/tabopen/winopen commands", () => { - const server = new TestServer().receiveContent('/*', 'ok'); + const server = new TestServer().receiveContent("/*", "ok"); let lanthan: Lanthan; let webdriver: WebDriver; let browser: any; let page: Page; - before(async() => { + before(async () => { await server.start(); - lanthan = await Builder - .forBrowser('firefox') - .spyAddon(path.join(__dirname, '..')) + lanthan = await Builder.forBrowser("firefox") + .spyAddon(path.join(__dirname, "..")) .build(); webdriver = lanthan.getWebDriver(); browser = lanthan.getWebExtBrowser(); // Add item into hitories - await webdriver.navigate().to(('https://example.com/')); + await webdriver.navigate().to("https://example.com/"); }); - after(async() => { + after(async () => { await server.stop(); if (lanthan) { await lanthan.quit(); } }); - beforeEach(async() => { + beforeEach(async () => { page = await Page.navigateTo(webdriver, server.url()); }); - it('should show completions from search engines, bookmarks, and histories by "open" command', async() => { + it('should show completions from search engines, bookmarks, and histories by "open" command', async () => { const console = await page.showConsole(); - await console.inputKeys('open '); + await console.inputKeys("open "); - await eventually(async() => { + await eventually(async () => { const completions = await console.getCompletions(); - assert.ok(completions.find(x => x.type === 'title' && x.text === 'Search Engines')); - assert.ok(completions.find(x => x.type === 'title' && x.text === 'Bookmarks')); - assert.ok(completions.find(x => x.type === 'title' && x.text === 'History')); + assert.ok( + completions.find( + (x) => x.type === "title" && x.text === "Search Engines" + ) + ); + assert.ok( + completions.find((x) => x.type === "title" && x.text === "Bookmarks") + ); + assert.ok( + completions.find((x) => x.type === "title" && x.text === "History") + ); }); }); - it('should filter items with URLs by keywords on "open" command', async() => { + it('should filter items with URLs by keywords on "open" command', async () => { const console = await page.showConsole(); - await console.inputKeys('open https://'); + await console.inputKeys("open https://"); - await eventually(async() => { + await eventually(async () => { const completions = await console.getCompletions(); - const items = completions.filter(x => x.type === 'item').map(x => x.text); - assert.ok(items.every(x => x.includes('https://'))); + const items = completions + .filter((x) => x.type === "item") + .map((x) => x.text); + assert.ok(items.every((x) => x.includes("https://"))); }); }); - it('should filter items with titles by keywords on "open" command', async() => { + it('should filter items with titles by keywords on "open" command', async () => { const console = await page.showConsole(); - await console.inputKeys('open getting'); + await console.inputKeys("open getting"); - await eventually(async() => { + await eventually(async () => { const completions = await console.getCompletions(); - const items = completions.filter(x => x.type === 'item').map(x => x.text); - assert.ok(items.every(x => x.toLowerCase().includes('getting'))); + const items = completions + .filter((x) => x.type === "item") + .map((x) => x.text); + assert.ok(items.every((x) => x.toLowerCase().includes("getting"))); }); }); - it('should filter items with titles by keywords on "tabopen" command', async() => { + it('should filter items with titles by keywords on "tabopen" command', async () => { const console = await page.showConsole(); - await console.inputKeys('tabopen getting'); + await console.inputKeys("tabopen getting"); - await eventually(async() => { + await eventually(async () => { const completions = await console.getCompletions(); - const items = completions.filter(x => x.type === 'item').map(x => x.text); - assert.ok(items.every(x => x.includes('https://'))); + const items = completions + .filter((x) => x.type === "item") + .map((x) => x.text); + assert.ok(items.every((x) => x.includes("https://"))); }); }); - it('should filter items with titles by keywords on "winopen" command', async() => { + it('should filter items with titles by keywords on "winopen" command', async () => { const console = await page.showConsole(); - await console.inputKeys('winopen https://'); + await console.inputKeys("winopen https://"); - await eventually(async() => { + await eventually(async () => { const completions = await console.getCompletions(); - const items = completions.filter(x => x.type === 'item').map(x => x.text); - assert.ok(items.every(x => x.includes('https://'))); + const items = completions + .filter((x) => x.type === "item") + .map((x) => x.text); + assert.ok(items.every((x) => x.includes("https://"))); }); }); - it('should display only specified items in "complete" property by set command', async() => { + it('should display only specified items in "complete" property by set command', async () => { let console = await page.showConsole(); - await console.execCommand('set complete=sbh'); + await console.execCommand("set complete=sbh"); await (webdriver.switchTo() as any).parentFrame(); console = await page.showConsole(); - await console.inputKeys('open '); + await console.inputKeys("open "); - await eventually(async() => { + await eventually(async () => { const completions = await console.getCompletions(); - const titles = completions.filter(x => x.type === 'title').map(x => x.text); - assert.deepStrictEqual(titles, ['Search Engines', 'Bookmarks', 'History']) + const titles = completions + .filter((x) => x.type === "title") + .map((x) => x.text); + assert.deepStrictEqual(titles, [ + "Search Engines", + "Bookmarks", + "History", + ]); }); await console.close(); console = await page.showConsole(); - await console.execCommand('set complete=bss'); + await console.execCommand("set complete=bss"); await (webdriver.switchTo() as any).parentFrame(); console = await page.showConsole(); - await console.inputKeys('open '); + await console.inputKeys("open "); - await eventually(async() => { + await eventually(async () => { const completions = await console.getCompletions(); - const titles = completions.filter(x => x.type === 'title').map(x => x.text); - assert.deepStrictEqual(titles, ['Bookmarks', 'Search Engines', 'Search Engines']) + const titles = completions + .filter((x) => x.type === "title") + .map((x) => x.text); + assert.deepStrictEqual(titles, [ + "Bookmarks", + "Search Engines", + "Search Engines", + ]); }); }); - it('should display only specified items in "complete" property by setting', async() => { - new SettingRepository(browser).saveJSON(Settings.fromJSON({ - properties: { complete: "sbh" }, - })); + it('should display only specified items in "complete" property by setting', async () => { + new SettingRepository(browser).saveJSON( + Settings.fromJSON({ + properties: { complete: "sbh" }, + }) + ); let console = await page.showConsole(); - await console.inputKeys('open '); + await console.inputKeys("open "); - await eventually(async() => { + await eventually(async () => { const completions = await console.getCompletions(); - const titles = completions.filter(x => x.type === 'title').map(x => x.text); - assert.deepStrictEqual(titles, ['Search Engines', 'Bookmarks', 'History']) + const titles = completions + .filter((x) => x.type === "title") + .map((x) => x.text); + assert.deepStrictEqual(titles, [ + "Search Engines", + "Bookmarks", + "History", + ]); }); await console.close(); await (webdriver.switchTo() as any).parentFrame(); - new SettingRepository(browser).saveJSON(Settings.fromJSON({ - properties: { complete: "bss" }, - })); + new SettingRepository(browser).saveJSON( + Settings.fromJSON({ + properties: { complete: "bss" }, + }) + ); console = await page.showConsole(); - await console.inputKeys('open '); + await console.inputKeys("open "); - await eventually(async() => { + await eventually(async () => { const completions = await console.getCompletions(); - const titles = completions.filter(x => x.type === 'title').map(x => x.text); - assert.deepStrictEqual(titles, ['Bookmarks', 'Search Engines', 'Search Engines']) + const titles = completions + .filter((x) => x.type === "title") + .map((x) => x.text); + assert.deepStrictEqual(titles, [ + "Bookmarks", + "Search Engines", + "Search Engines", + ]); }); }); }); diff --git a/e2e/completion_set.test.ts b/e2e/completion_set.test.ts index 7e9714c..3a139fe 100644 --- a/e2e/completion_set.test.ts +++ b/e2e/completion_set.test.ts @@ -1,57 +1,56 @@ -import * as path from 'path'; -import * as assert from 'assert'; +import * as path from "path"; +import * as assert from "assert"; -import eventually from './eventually'; -import { Builder, Lanthan } from 'lanthan'; -import { WebDriver } from 'selenium-webdriver'; -import Page from './lib/Page'; +import eventually from "./eventually"; +import { Builder, Lanthan } from "lanthan"; +import { WebDriver } from "selenium-webdriver"; +import Page from "./lib/Page"; describe("completion on set commands", () => { let lanthan: Lanthan; let webdriver: WebDriver; let page: Page; - before(async() => { - lanthan = await Builder - .forBrowser('firefox') - .spyAddon(path.join(__dirname, '..')) + before(async () => { + lanthan = await Builder.forBrowser("firefox") + .spyAddon(path.join(__dirname, "..")) .build(); webdriver = lanthan.getWebDriver(); }); - after(async() => { + after(async () => { if (lanthan) { await lanthan.quit(); } }); - beforeEach(async() => { + beforeEach(async () => { page = await Page.navigateTo(webdriver, `about:blank`); }); - it('should show all property names by "set" command with empty params', async() => { + it('should show all property names by "set" command with empty params', async () => { const console = await page.showConsole(); - await console.inputKeys('set '); + await console.inputKeys("set "); - await eventually(async() => { + await eventually(async () => { const items = await console.getCompletions(); assert.strictEqual(items.length, 5); - assert.deepStrictEqual(items[0], { type: 'title', text: 'Properties' }); - assert.ok(items[1].text.startsWith('hintchars')); - assert.ok(items[2].text.startsWith('smoothscroll')); - assert.ok(items[3].text.startsWith('nosmoothscroll')); - assert.ok(items[4].text.startsWith('complete')) + assert.deepStrictEqual(items[0], { type: "title", text: "Properties" }); + assert.ok(items[1].text.startsWith("hintchars")); + assert.ok(items[2].text.startsWith("smoothscroll")); + assert.ok(items[3].text.startsWith("nosmoothscroll")); + assert.ok(items[4].text.startsWith("complete")); }); }); - it('should show filtered property names by "set" command', async() => { + it('should show filtered property names by "set" command', async () => { const console = await page.showConsole(); - await console.inputKeys('set no'); + await console.inputKeys("set no"); - await eventually(async() => { + await eventually(async () => { const items = await console.getCompletions(); assert.strictEqual(items.length, 2); - assert.ok(items[1].text.includes('nosmoothscroll')) + assert.ok(items[1].text.includes("nosmoothscroll")); }); }); }); diff --git a/e2e/console.test.ts b/e2e/console.test.ts index 1d441f9..18b717f 100644 --- a/e2e/console.test.ts +++ b/e2e/console.test.ts @@ -1,90 +1,93 @@ -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 { Builder, Lanthan } from 'lanthan'; -import { WebDriver, Key } from 'selenium-webdriver'; -import Page from './lib/Page'; +import TestServer from "./lib/TestServer"; +import { Builder, Lanthan } from "lanthan"; +import { WebDriver, Key } from "selenium-webdriver"; +import Page from "./lib/Page"; describe("console test", () => { - const server = new TestServer().receiveContent('/', - `<!DOCTYPE html><html lang="en"><head><title>Hello, world!</title></head></html>`, + const server = new TestServer().receiveContent( + "/", + `<!DOCTYPE html><html lang="en"><head><title>Hello, world!</title></head></html>` ); let lanthan: Lanthan; let webdriver: WebDriver; let page: Page; - before(async() => { - lanthan = await Builder - .forBrowser('firefox') - .spyAddon(path.join(__dirname, '..')) + before(async () => { + lanthan = await Builder.forBrowser("firefox") + .spyAddon(path.join(__dirname, "..")) .build(); webdriver = lanthan.getWebDriver(); await server.start(); }); - after(async() => { + after(async () => { await server.stop(); if (lanthan) { await lanthan.quit(); } }); - beforeEach(async() => { + beforeEach(async () => { page = await Page.navigateTo(webdriver, server.url()); }); - it('open console with :', async() => { - await page.sendKeys(':'); + it("open console with :", async () => { + await page.sendKeys(":"); const console = await page.getConsole(); - assert.strictEqual(await console.currentValue(), ''); + assert.strictEqual(await console.currentValue(), ""); }); - it('open console with open command by o', async() => { - await page.sendKeys('o'); + it("open console with open command by o", async () => { + await page.sendKeys("o"); const console = await page.getConsole(); - assert.strictEqual(await console.currentValue(), 'open '); + assert.strictEqual(await console.currentValue(), "open "); }); - it('open console with open command and current URL by O', async() => { - await page.sendKeys(Key.SHIFT, 'o'); + it("open console with open command and current URL by O", async () => { + await page.sendKeys(Key.SHIFT, "o"); const console = await page.getConsole(); assert.strictEqual(await console.currentValue(), `open ${server.url()}`); }); - it('open console with tabopen command by t', async() => { - await page.sendKeys('t'); + it("open console with tabopen command by t", async () => { + await page.sendKeys("t"); const console = await page.getConsole(); - assert.strictEqual(await console.currentValue(), 'tabopen '); + assert.strictEqual(await console.currentValue(), "tabopen "); }); - it('open console with tabopen command and current URL by T', async() => { - await page.sendKeys(Key.SHIFT, 't'); + it("open console with tabopen command and current URL by T", async () => { + await page.sendKeys(Key.SHIFT, "t"); const console = await page.getConsole(); assert.strictEqual(await console.currentValue(), `tabopen ${server.url()}`); }); - it('open console with winopen command by w', async() => { - await page.sendKeys('w'); + it("open console with winopen command by w", async () => { + await page.sendKeys("w"); const console = await page.getConsole(); assert.strictEqual(await console.currentValue(), `winopen `); }); - it('open console with winopen command and current URL by W', async() => { - await page.sendKeys(Key.SHIFT, 'W'); + it("open console with winopen command and current URL by W", async () => { + await page.sendKeys(Key.SHIFT, "W"); const console = await page.getConsole(); assert.strictEqual(await console.currentValue(), `winopen ${server.url()}`); }); - it('open console with buffer command by b', async() => { - await page.sendKeys('b'); + it("open console with buffer command by b", async () => { + await page.sendKeys("b"); const console = await page.getConsole(); assert.strictEqual(await console.currentValue(), `buffer `); }); - it('open console with addbookmark command with title by a', async() => { - await page.sendKeys('a'); + it("open console with addbookmark command with title by a", async () => { + await page.sendKeys("a"); const console = await page.getConsole(); - assert.strictEqual(await console.currentValue(), `addbookmark Hello, world!`); + assert.strictEqual( + await console.currentValue(), + `addbookmark Hello, world!` + ); }); }); diff --git a/e2e/eventually.ts b/e2e/eventually.ts index b0a2dfc..9d21022 100644 --- a/e2e/eventually.ts +++ b/e2e/eventually.ts @@ -1,19 +1,19 @@ const defaultInterval = 100; const defaultTimeout = 2000; -type Handler = () => void +type Handler = () => void; const sleep = (ms: number): Promise<void> => { - return new Promise(resolve => setTimeout(resolve, ms)); -} - + return new Promise((resolve) => setTimeout(resolve, ms)); +}; + const eventually = async ( fn: Handler, timeout = defaultTimeout, - interval = defaultInterval, + interval = defaultInterval ): Promise<void> => { const start = Date.now(); - const loop = async() => { + const loop = async () => { try { await fn(); } catch (err) { diff --git a/e2e/find.test.ts b/e2e/find.test.ts index 74097ab..accf37b 100644 --- a/e2e/find.test.ts +++ b/e2e/find.test.ts @@ -1,42 +1,42 @@ -import * as path from 'path'; -import * as assert from 'assert'; +import * as path from "path"; +import * as assert from "assert"; -import eventually from './eventually'; -import TestServer from './lib/TestServer'; -import { Builder, Lanthan } from 'lanthan'; -import { Key, WebDriver } from 'selenium-webdriver'; -import Page from './lib/Page'; +import eventually from "./eventually"; +import TestServer from "./lib/TestServer"; +import { Builder, Lanthan } from "lanthan"; +import { Key, WebDriver } from "selenium-webdriver"; +import Page from "./lib/Page"; describe("find test", () => { - const server = new TestServer().receiveContent('/', - `<!DOCTYPE html><html lang="en"><body>--hello--hello--hello--</body></html>`, + const server = new TestServer().receiveContent( + "/", + `<!DOCTYPE html><html lang="en"><body>--hello--hello--hello--</body></html>` ); let lanthan: Lanthan; let webdriver: WebDriver; let page: Page; - before(async() => { - lanthan = await Builder - .forBrowser('firefox') - .spyAddon(path.join(__dirname, '..')) + before(async () => { + lanthan = await Builder.forBrowser("firefox") + .spyAddon(path.join(__dirname, "..")) .build(); webdriver = lanthan.getWebDriver(); await server.start(); }); - after(async() => { + after(async () => { await server.stop(); if (lanthan) { await lanthan.quit(); } }); - beforeEach(async() => { + beforeEach(async () => { page = await Page.navigateTo(webdriver, server.url()); }); - it('starts searching', async() => { - await page.sendKeys('/'); + it("starts searching", async () => { + await page.sendKeys("/"); const console = await page.getConsole(); await console.execCommand("hello"); await page.switchToTop(); @@ -60,53 +60,53 @@ describe("find test", () => { assert.deepStrictEqual(selection, { from: 16, to: 21 }); }); - it('shows error if pattern not found', async() => { - await page.sendKeys('/'); + it("shows error if pattern not found", async () => { + await page.sendKeys("/"); let console = await page.getConsole(); - await console.execCommand('world'); + await console.execCommand("world"); await page.switchToTop(); const selection = await page.getSelection(); assert.deepStrictEqual(selection, { from: 0, to: 0 }); - await eventually(async() => { + await eventually(async () => { console = await page.getConsole(); const message = await console.getErrorMessage(); - assert.strictEqual(message, 'Pattern not found: world'); + assert.strictEqual(message, "Pattern not found: world"); }); }); - it('search with last keyword if keyword is empty', async() => { - await page.sendKeys('/'); + it("search with last keyword if keyword is empty", async () => { + await page.sendKeys("/"); let console = await page.getConsole(); - await console.execCommand('hello'); + await console.execCommand("hello"); await page.switchToTop(); await page.clearSelection(); let selection = await page.getSelection(); assert.deepStrictEqual(selection, { from: 0, to: 0 }); - await page.sendKeys('/'); + await page.sendKeys("/"); console = await page.getConsole(); - await console.execCommand(''); + await console.execCommand(""); await page.switchToTop(); selection = await page.getSelection(); assert.deepStrictEqual(selection, { from: 2, to: 7 }); }); - it('search with last keyword on new page', async() => { - await page.sendKeys('/'); + it("search with last keyword on new page", async () => { + await page.sendKeys("/"); const console = await page.getConsole(); - await console.execCommand('hello'); + await console.execCommand("hello"); await page.switchToTop(); - await page.sendKeys('n'); + await page.sendKeys("n"); let selection = await page.getSelection(); assert.deepStrictEqual(selection, { from: 9, to: 14 }); page = await Page.navigateTo(webdriver, server.url()); - await page.sendKeys('n'); + await page.sendKeys("n"); selection = await page.getSelection(); assert.deepStrictEqual(selection, { from: 2, to: 7 }); }); diff --git a/e2e/follow.test.ts b/e2e/follow.test.ts index 62a109f..5fb6c58 100644 --- a/e2e/follow.test.ts +++ b/e2e/follow.test.ts @@ -1,28 +1,36 @@ -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 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 Page from "./lib/Page"; const newApp = () => { const server = new TestServer(); - server.receiveContent('/', ` + server.receiveContent( + "/", + ` <!DOCTYPE html> <html lang="en"><body> <a href="hello">hello</a> - </body></html>`); + </body></html>` + ); - server.receiveContent('/follow-input', ` + server.receiveContent( + "/follow-input", + ` <!DOCTYPE html> <html lang="en"><body> <input> - </body></html>`); + </body></html>` + ); - server.receiveContent('/area', ` + server.receiveContent( + "/area", + ` <!DOCTYPE html> <html lang="en"><body> <img @@ -34,7 +42,8 @@ const newApp = () => { <area shape="rect" coords="64,64,64,64" href="/"> <area shape="rect" coords="128,128,64,64" href="/"> </map> - </body></html>`); + </body></html>` + ); /* * test case: link2 is out of the viewport @@ -46,168 +55,186 @@ const newApp = () => { * | | * +-----------------+ */ - server.receiveContent('/test1', ` + server.receiveContent( + "/test1", + ` <!DOCTYPE html> <html lang="en"><body> <div><a href="link1">link1</a></div> <div style="min-height:3000px"></div> <div><a href="link2">link2</a></div> - </body></html>`); - -/* - * test case 2: link2 and link3 are out of window of the frame - * +-----------------+ - * | +-----------+ | - * | | [link1] | | - * |=================| - * | | [link2] | | - * | +-----------+ | - * | | - * +-----------------+ - */ - server.receiveContent('/test2', ` + </body></html>` + ); + + /* + * test case 2: link2 and link3 are out of window of the frame + * +-----------------+ + * | +-----------+ | + * | | [link1] | | + * |=================| + * | | [link2] | | + * | +-----------+ | + * | | + * +-----------------+ + */ + server.receiveContent( + "/test2", + ` <!DOCTYPE html> <html lang="en"><body> <iframe height="5000" src='/test2-frame'> - </body></html>`); - server.receiveContent('/test2-frame', ` + </body></html>` + ); + server.receiveContent( + "/test2-frame", + ` <!DOCTYPE html> <html lang="en"><body> <div><a href="link1">link1</a></div> <div style="min-height:3000px"></div> <div><a href="link2">link2</a></div> - </body></html>`); - -/* test case 3: link2 is out of window of the frame - * +-----------------+ - * | +-----------+ | - * | | [link1] | | - * | +-----------+ | - * | : [link2] : | - * | + - - - - - + | - * | | - * +-----------------+ - */ - server.receiveContent('/test3', ` + </body></html>` + ); + + /* test case 3: link2 is out of window of the frame + * +-----------------+ + * | +-----------+ | + * | | [link1] | | + * | +-----------+ | + * | : [link2] : | + * | + - - - - - + | + * | | + * +-----------------+ + */ + server.receiveContent( + "/test3", + ` <!DOCTYPE html> <html lang="en"><body> <iframe src='/test3-frame'> - </body></html>`); - server.receiveContent('/test3-frame', ` + </body></html>` + ); + server.receiveContent( + "/test3-frame", + ` <!DOCTYPE html> <html lang="en"><body> <div><a href="link1">link1</a></div> <div style="min-height:3000px"></div> <div><a href="link2">link2</a></div> - </body></html>`); + </body></html>` + ); return server; }; -describe('follow test', () => { +describe("follow test", () => { const server = newApp(); let lanthan: Lanthan; let webdriver: WebDriver; let browser: any; - before(async() => { - lanthan = await Builder - .forBrowser('firefox') - .spyAddon(path.join(__dirname, '..')) + before(async () => { + lanthan = await Builder.forBrowser("firefox") + .spyAddon(path.join(__dirname, "..")) .build(); webdriver = lanthan.getWebDriver(); browser = lanthan.getWebExtBrowser(); await server.start(); }); - after(async() => { + after(async () => { await server.stop(); if (lanthan) { await lanthan.quit(); } }); - afterEach(async() => { + afterEach(async () => { const tabs = await browser.tabs.query({}); for (const tab of tabs.slice(1)) { await browser.tabs.remove(tab.id); } }); - it('should focus an input by f', async () => { - const page = await Page.navigateTo(webdriver, server.url('/follow-input')); - await page.sendKeys('f'); + it("should focus an input by f", async () => { + const page = await Page.navigateTo(webdriver, server.url("/follow-input")); + await page.sendKeys("f"); await page.waitAndGetHints(); - await page.sendKeys('a'); + await page.sendKeys("a"); - const tagName = await webdriver.executeScript(() => document.activeElement!!.tagName) as string; - assert.strictEqual(tagName.toLowerCase(), 'input'); + const tagName = (await webdriver.executeScript( + () => document.activeElement!!.tagName + )) as string; + assert.strictEqual(tagName.toLowerCase(), "input"); }); - it('should open a link by f', async () => { + it("should open a link by f", async () => { const page = await Page.navigateTo(webdriver, server.url()); - await page.sendKeys('f'); + await page.sendKeys("f"); await page.waitAndGetHints(); - await page.sendKeys('a'); + await page.sendKeys("a"); - await eventually(async() => { - const hash = await webdriver.executeScript('return location.pathname'); - assert.strictEqual(hash, '/hello'); + await eventually(async () => { + const hash = await webdriver.executeScript("return location.pathname"); + assert.strictEqual(hash, "/hello"); }); }); - it('should focus an input by F', async () => { - const page = await Page.navigateTo(webdriver, server.url('/follow-input')); - await page.sendKeys(Key.SHIFT, 'f'); + it("should focus an input by F", async () => { + const page = await Page.navigateTo(webdriver, server.url("/follow-input")); + await page.sendKeys(Key.SHIFT, "f"); await page.waitAndGetHints(); - await page.sendKeys('a'); + await page.sendKeys("a"); - const tagName = await webdriver.executeScript(() => document.activeElement!!.tagName) as string; - assert.strictEqual(tagName.toLowerCase(), 'input'); + const tagName = (await webdriver.executeScript( + () => document.activeElement!!.tagName + )) as string; + assert.strictEqual(tagName.toLowerCase(), "input"); }); - it('should open a link to new tab by F', async () => { + it("should open a link to new tab by F", async () => { const page = await Page.navigateTo(webdriver, server.url()); - await page.sendKeys(Key.SHIFT, 'f'); + await page.sendKeys(Key.SHIFT, "f"); await page.waitAndGetHints(); - await page.sendKeys('a'); + await page.sendKeys("a"); - await eventually(async() => { + await eventually(async () => { const tabs = await browser.tabs.query({}); assert.strictEqual(tabs.length, 2); - assert.strictEqual(new URL(tabs[1].url).pathname, '/hello'); + assert.strictEqual(new URL(tabs[1].url).pathname, "/hello"); assert.strictEqual(tabs[1].openerTabId, tabs[0].id); }); }); - it('should show hints of links in area', async () => { - const page = await Page.navigateTo(webdriver, server.url('/area')); - await page.sendKeys(Key.SHIFT, 'f'); + it("should show hints of links in area", async () => { + const page = await Page.navigateTo(webdriver, server.url("/area")); + await page.sendKeys(Key.SHIFT, "f"); const hints = await page.waitAndGetHints(); assert.strictEqual(hints.length, 3); }); - it('should shows hints only in viewport', async () => { - const page = await Page.navigateTo(webdriver, server.url('/test1')); - await page.sendKeys(Key.SHIFT, 'f'); + it("should shows hints only in viewport", async () => { + const page = await Page.navigateTo(webdriver, server.url("/test1")); + await page.sendKeys(Key.SHIFT, "f"); const hints = await page.waitAndGetHints(); assert.strictEqual(hints.length, 1); }); - it('should shows hints only in window of the frame', async () => { - const page = await Page.navigateTo(webdriver, server.url('/test2')); - await page.sendKeys(Key.SHIFT, 'f'); + it("should shows hints only in window of the frame", async () => { + const page = await Page.navigateTo(webdriver, server.url("/test2")); + await page.sendKeys(Key.SHIFT, "f"); await webdriver.switchTo().frame(0); const hints = await page.waitAndGetHints(); assert.strictEqual(hints.length, 1); }); - it('should shows hints only in the frame', async () => { - const page = await Page.navigateTo(webdriver, server.url('/test3')); - await page.sendKeys(Key.SHIFT, 'f'); + it("should shows hints only in the frame", async () => { + const page = await Page.navigateTo(webdriver, server.url("/test3")); + await page.sendKeys(Key.SHIFT, "f"); await webdriver.switchTo().frame(0); const hints = await page.waitAndGetHints(); diff --git a/e2e/follow_properties.test.ts b/e2e/follow_properties.test.ts index 78597a5..4f2a5b8 100644 --- a/e2e/follow_properties.test.ts +++ b/e2e/follow_properties.test.ts @@ -1,16 +1,18 @@ -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 Page from './lib/Page'; +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 Page from "./lib/Page"; import SettingRepository from "./lib/SettingRepository"; import Settings from "../src/shared/settings/Settings"; -describe('follow properties test', () => { - const server = new TestServer().receiveContent('/', ` +describe("follow properties test", () => { + const server = new TestServer().receiveContent( + "/", + ` <!DOCTYPE html> <html lang="en"><body> <a href="/">link1</a> @@ -18,67 +20,69 @@ describe('follow properties test', () => { <a href="/">link3</a> <a href="/">link4</a> <a href="/">link5</a> - </body></html>`); + </body></html>` + ); let lanthan: Lanthan; let webdriver: WebDriver; let browser: any; let page: Page; - before(async() => { - lanthan = await Builder - .forBrowser('firefox') - .spyAddon(path.join(__dirname, '..')) + before(async () => { + lanthan = await Builder.forBrowser("firefox") + .spyAddon(path.join(__dirname, "..")) .build(); webdriver = lanthan.getWebDriver(); browser = lanthan.getWebExtBrowser(); - await new SettingRepository(browser).saveJSON(Settings.fromJSON({ - "keymaps": { - ":": { "type": "command.show" }, - "f": { "type": "follow.start", "newTab": false }, - "F": { "type": "follow.start", "newTab": true, "background": false }, - "<C-F>": { "type": "follow.start", "newTab": true, "background": true } - }, - "properties": { - "hintchars": "jk" - } - })); + await new SettingRepository(browser).saveJSON( + Settings.fromJSON({ + keymaps: { + ":": { type: "command.show" }, + f: { type: "follow.start", newTab: false }, + F: { type: "follow.start", newTab: true, background: false }, + "<C-F>": { type: "follow.start", newTab: true, background: true }, + }, + properties: { + hintchars: "jk", + }, + }) + ); await server.start(); }); - after(async() => { + after(async () => { await server.stop(); if (lanthan) { await lanthan.quit(); } }); - beforeEach(async() => { + beforeEach(async () => { page = await Page.navigateTo(webdriver, server.url()); }); - afterEach(async() => { + afterEach(async () => { const tabs = await browser.tabs.query({}); for (const tab of tabs.slice(1)) { await browser.tabs.remove(tab.id); } }); - it('should show hints with hintchars by settings', async () => { - await page.sendKeys('f'); + it("should show hints with hintchars by settings", async () => { + await page.sendKeys("f"); let hints = await page.waitAndGetHints(); assert.strictEqual(hints.length, 5); - assert.strictEqual(hints[0].text, 'J'); - assert.strictEqual(hints[1].text, 'K'); - assert.strictEqual(hints[2].text, 'JJ'); - assert.strictEqual(hints[3].text, 'JK'); - assert.strictEqual(hints[4].text, 'KJ'); + assert.strictEqual(hints[0].text, "J"); + assert.strictEqual(hints[1].text, "K"); + assert.strictEqual(hints[2].text, "JJ"); + assert.strictEqual(hints[3].text, "JK"); + assert.strictEqual(hints[4].text, "KJ"); - await page.sendKeys('j'); + await page.sendKeys("j"); hints = await page.waitAndGetHints(); assert.strictEqual(hints[0].displayed, true); @@ -88,45 +92,45 @@ describe('follow properties test', () => { assert.strictEqual(hints[4].displayed, false); }); - it('should open tab in background by background:false', async () => { - await page.sendKeys(Key.SHIFT, 'f'); + it("should open tab in background by background:false", async () => { + await page.sendKeys(Key.SHIFT, "f"); await page.waitAndGetHints(); - await page.sendKeys('jj'); + await page.sendKeys("jj"); - await eventually(async() => { + await eventually(async () => { const tabs = await browser.tabs.query({}); assert.strictEqual(tabs[0].active, false); assert.strictEqual(tabs[1].active, true); }); }); - it('should open tab in background by background:true', async () => { - await page.sendKeys(Key.CONTROL, 'f'); + it("should open tab in background by background:true", async () => { + await page.sendKeys(Key.CONTROL, "f"); await page.waitAndGetHints(); - await page.sendKeys('jj'); + await page.sendKeys("jj"); - await eventually(async() => { + await eventually(async () => { const tabs = await browser.tabs.query({}); assert.strictEqual(tabs[0].active, true); assert.strictEqual(tabs[1].active, false); }); }); - it('should show hints with hintchars by settings', async () => { + it("should show hints with hintchars by settings", async () => { const console = await page.showConsole(); - await console.execCommand('set hintchars=abc'); + await console.execCommand("set hintchars=abc"); await (webdriver.switchTo() as any).parentFrame(); - await page.sendKeys('f'); + await page.sendKeys("f"); let hints = await page.waitAndGetHints(); assert.strictEqual(hints.length, 5); - assert.strictEqual(hints[0].text, 'A'); - assert.strictEqual(hints[1].text, 'B'); - assert.strictEqual(hints[2].text, 'C'); - assert.strictEqual(hints[3].text, 'AA'); - assert.strictEqual(hints[4].text, 'AB'); + assert.strictEqual(hints[0].text, "A"); + assert.strictEqual(hints[1].text, "B"); + assert.strictEqual(hints[2].text, "C"); + assert.strictEqual(hints[3].text, "AA"); + assert.strictEqual(hints[4].text, "AB"); - await page.sendKeys('a'); + await page.sendKeys("a"); hints = await page.waitAndGetHints(); assert.strictEqual(hints[0].displayed, true); assert.strictEqual(hints[1].displayed, false); diff --git a/e2e/lib/Console.ts b/e2e/lib/Console.ts index e3bd2d6..68c0e10 100644 --- a/e2e/lib/Console.ts +++ b/e2e/lib/Console.ts @@ -1,64 +1,73 @@ -import { WebDriver, By, Key } from 'selenium-webdriver'; +import { WebDriver, By, Key } from "selenium-webdriver"; export type CompletionItem = { type: string; text: string; highlight: boolean; -} +}; export class Console { - constructor(private webdriver: WebDriver) { - } + constructor(private webdriver: WebDriver) {} async sendKeys(...keys: string[]) { - const input = await this.webdriver.findElement(By.css('input')); + const input = await this.webdriver.findElement(By.css("input")); input.sendKeys(...keys); } async currentValue() { return await this.webdriver.executeScript(() => { - const input = document.querySelector('input'); + const input = document.querySelector("input"); if (input === null) { - throw new Error('could not find input element'); + throw new Error("could not find input element"); } return input.value; }); } async execCommand(command: string): Promise<void> { - const input = await this.webdriver.findElement(By.css('input.vimvixen-console-command-input')); + const input = await this.webdriver.findElement( + By.css("input.vimvixen-console-command-input") + ); await input.sendKeys(command, Key.ENTER); } async getErrorMessage(): Promise<string> { - const p = await this.webdriver.findElement(By.css('.vimvixen-console-error')); + const p = await this.webdriver.findElement( + By.css(".vimvixen-console-error") + ); return p.getText(); } async getInformationMessage(): Promise<string> { - const p = await this.webdriver.findElement(By.css('.vimvixen-console-info')); + const p = await this.webdriver.findElement( + By.css(".vimvixen-console-info") + ); return p.getText(); } async inputKeys(...keys: string[]) { - const input = await this.webdriver.findElement(By.css('input')); + const input = await this.webdriver.findElement(By.css("input")); await input.sendKeys(...keys); } getCompletions(): Promise<CompletionItem[]> { return this.webdriver.executeScript(() => { - const items = document.querySelectorAll('.vimvixen-console-completion > li'); + const items = document.querySelectorAll( + ".vimvixen-console-completion > li" + ); if (items.length === 0) { - throw new Error('completion items not found'); + throw new Error("completion items not found"); } const objs = []; for (const li of Array.from(items)) { - if (li.classList.contains('vimvixen-console-completion-title')) { - objs.push({ type: 'title', text: li.textContent!!.trim() }); - } else if ('vimvixen-console-completion-item') { - const highlight = li.classList.contains('vimvixen-completion-selected'); - objs.push({ type: 'item', text: li.textContent!!.trim(), highlight }); + if (li.classList.contains("vimvixen-console-completion-title")) { + objs.push({ type: "title", text: li.textContent!!.trim() }); + } else if ("vimvixen-console-completion-item") { + const highlight = li.classList.contains( + "vimvixen-completion-selected" + ); + objs.push({ type: "item", text: li.textContent!!.trim(), highlight }); } else { throw new Error(`unexpected class: ${li.className}`); } @@ -68,10 +77,10 @@ export class Console { } async close(): Promise<void> { - const input = await this.webdriver.findElement(By.css('input')); + const input = await this.webdriver.findElement(By.css("input")); await input.sendKeys(Key.ESCAPE); // TODO remove sleep - await new Promise(resolve => setTimeout(resolve, 100)); + await new Promise((resolve) => setTimeout(resolve, 100)); await (this.webdriver.switchTo() as any).parentFrame(); } } diff --git a/e2e/lib/FormOptionPage.ts b/e2e/lib/FormOptionPage.ts index 33ce2a7..5551684 100644 --- a/e2e/lib/FormOptionPage.ts +++ b/e2e/lib/FormOptionPage.ts @@ -1,5 +1,5 @@ -import { Lanthan } from 'lanthan'; -import { WebDriver, By, until } from 'selenium-webdriver'; +import { Lanthan } from "lanthan"; +import { WebDriver, By, until } from "selenium-webdriver"; export default class FormOptionPage { private webdriver: WebDriver; @@ -9,92 +9,136 @@ export default class FormOptionPage { } async setBlacklist(nth: number, url: string): Promise<void> { - const selector = '.form-blacklist-form-row > .column-url'; + const selector = ".form-blacklist-form-row > .column-url"; const inputs = await this.webdriver.findElements(By.css(selector)); if (inputs.length <= nth) { - throw new RangeError('Index out of range to set a blacklist') + throw new RangeError("Index out of range to set a blacklist"); } await inputs[nth].sendKeys(url); - await this.webdriver.executeScript(`document.querySelectorAll('${selector}')[${nth}].blur()`); + await this.webdriver.executeScript( + `document.querySelectorAll('${selector}')[${nth}].blur()` + ); } - async setPartialBlacklist(nth: number, url: string, keys: string): Promise<void> { - let selector = '.form-partial-blacklist-form-row > .column-url'; + async setPartialBlacklist( + nth: number, + url: string, + keys: string + ): Promise<void> { + let selector = ".form-partial-blacklist-form-row > .column-url"; let inputs = await this.webdriver.findElements(By.css(selector)); if (inputs.length <= nth) { - throw new RangeError('Index out of range to set a partial blacklist') + throw new RangeError("Index out of range to set a partial blacklist"); } await inputs[nth].sendKeys(url); - await this.webdriver.executeScript(`document.querySelectorAll('${selector}')[${nth}].blur()`); + await this.webdriver.executeScript( + `document.querySelectorAll('${selector}')[${nth}].blur()` + ); - selector = '.form-partial-blacklist-form-row > .column-keys'; + selector = ".form-partial-blacklist-form-row > .column-keys"; inputs = await this.webdriver.findElements(By.css(selector)); if (inputs.length <= nth) { - throw new RangeError('Index out of range to set a partial blacklist') + throw new RangeError("Index out of range to set a partial blacklist"); } await inputs[nth].sendKeys(keys); - await this.webdriver.executeScript(`document.querySelectorAll('${selector}')[${nth}].blur()`); + await this.webdriver.executeScript( + `document.querySelectorAll('${selector}')[${nth}].blur()` + ); } async setSearchEngine(nth: number, name: string, url: string) { - let selector = '.form-search-form-row > .column-name'; + let selector = ".form-search-form-row > .column-name"; let inputs = await this.webdriver.findElements(By.css(selector)); if (inputs.length <= nth) { - throw new RangeError('Index out of range to set a search engine') + throw new RangeError("Index out of range to set a search engine"); } await inputs[nth].sendKeys(name); - await this.webdriver.executeScript(`document.querySelectorAll('${selector}')[${nth}].blur()`); + await this.webdriver.executeScript( + `document.querySelectorAll('${selector}')[${nth}].blur()` + ); - selector = '.form-search-form-row > .column-url'; + selector = ".form-search-form-row > .column-url"; inputs = await this.webdriver.findElements(By.css(selector)); if (inputs.length <= nth) { - throw new RangeError('Index out of range to set a search engine') + throw new RangeError("Index out of range to set a search engine"); } await inputs[nth].sendKeys(url); - await this.webdriver.executeScript(`document.querySelectorAll('${selector}')[${nth}].blur()`); + await this.webdriver.executeScript( + `document.querySelectorAll('${selector}')[${nth}].blur()` + ); } async addBlacklist(): Promise<void> { - const rows = await this.webdriver.findElements(By.css(`.form-blacklist-form-row`)); - const button = await this.webdriver.findElement(By.css('.form-blacklist-form .ui-add-button')) + const rows = await this.webdriver.findElements( + By.css(`.form-blacklist-form-row`) + ); + const button = await this.webdriver.findElement( + By.css(".form-blacklist-form .ui-add-button") + ); await button.click(); - await this.webdriver.wait(until.elementLocated(By.css(`.form-blacklist-form-row:nth-child(${rows.length + 1})`))); + await this.webdriver.wait( + until.elementLocated( + By.css(`.form-blacklist-form-row:nth-child(${rows.length + 1})`) + ) + ); } async addPartialBlacklist(): Promise<void> { - const rows = await this.webdriver.findElements(By.css(`.form-partial-blacklist-form-row`)); - const button = await this.webdriver.findElement(By.css('.form-partial-blacklist-form .ui-add-button')) + const rows = await this.webdriver.findElements( + By.css(`.form-partial-blacklist-form-row`) + ); + const button = await this.webdriver.findElement( + By.css(".form-partial-blacklist-form .ui-add-button") + ); await button.click(); - await this.webdriver.wait(until.elementLocated(By.css(`.form-partial-blacklist-form-row:nth-child(${rows.length + 2})`))); + await this.webdriver.wait( + until.elementLocated( + By.css(`.form-partial-blacklist-form-row:nth-child(${rows.length + 2})`) + ) + ); } async removeBlackList(nth: number): Promise<void> { - const buttons = await this.webdriver.findElements(By.css('.form-blacklist-form-row .ui-delete-button')); + const buttons = await this.webdriver.findElements( + By.css(".form-blacklist-form-row .ui-delete-button") + ); if (buttons.length <= nth) { - throw new RangeError('Index out of range to remove blacklist') + throw new RangeError("Index out of range to remove blacklist"); } - await buttons[nth].click() + await buttons[nth].click(); } async removePartialBlackList(nth: number): Promise<void> { - const buttons = await this.webdriver.findElements(By.css('.form-partial-blacklist-form-row .ui-delete-button')); + const buttons = await this.webdriver.findElements( + By.css(".form-partial-blacklist-form-row .ui-delete-button") + ); if (buttons.length <= nth) { - throw new RangeError('Index out of range to remove partial blacklist') + throw new RangeError("Index out of range to remove partial blacklist"); } - await buttons[nth].click() + await buttons[nth].click(); } async addSearchEngine(): Promise<void> { - const rows = await this.webdriver.findElements(By.css(`.form-search-form-row > .column-name`)); - const button = await this.webdriver.findElement(By.css('.form-search-form > .ui-add-button')) + const rows = await this.webdriver.findElements( + By.css(`.form-search-form-row > .column-name`) + ); + const button = await this.webdriver.findElement( + By.css(".form-search-form > .ui-add-button") + ); await button.click(); - await this.webdriver.wait(until.elementLocated(By.css(`.form-search-form-row:nth-child(${rows.length + 1})`))); + await this.webdriver.wait( + until.elementLocated( + By.css(`.form-search-form-row:nth-child(${rows.length + 1})`) + ) + ); } async setDefaultSearchEngine(nth: number): Promise<void> { - const radios = await this.webdriver.findElements(By.css('.form-search-form-row input[type=radio]')); + const radios = await this.webdriver.findElements( + By.css(".form-search-form-row input[type=radio]") + ); if (radios.length <= nth) { - throw new RangeError('Index out of range to set a default search engine'); + throw new RangeError("Index out of range to set a default search engine"); } await radios[nth].click(); } diff --git a/e2e/lib/JSONOptionPage.ts b/e2e/lib/JSONOptionPage.ts index d6ed7ee..1c2db5b 100644 --- a/e2e/lib/JSONOptionPage.ts +++ b/e2e/lib/JSONOptionPage.ts @@ -1,5 +1,5 @@ -import { Lanthan } from 'lanthan'; -import { WebDriver, By } from 'selenium-webdriver'; +import { Lanthan } from "lanthan"; +import { WebDriver, By } from "selenium-webdriver"; export default class JSONOptionPage { private webdriver: WebDriver; @@ -9,14 +9,20 @@ export default class JSONOptionPage { } async updateSettings(value: string): Promise<void> { - const textarea = await this.webdriver.findElement(By.css('textarea')); - await this.webdriver.executeScript(`document.querySelector('textarea').value = '${value}'`) - await textarea.sendKeys(' '); - await this.webdriver.executeScript(() => document.querySelector('textarea')!!.blur()); + const textarea = await this.webdriver.findElement(By.css("textarea")); + await this.webdriver.executeScript( + `document.querySelector('textarea').value = '${value}'` + ); + await textarea.sendKeys(" "); + await this.webdriver.executeScript(() => + document.querySelector("textarea")!!.blur() + ); } async getErrorMessage(): Promise<string> { - const error = await this.webdriver.findElement(By.css('.settings-ui-input-error')); + const error = await this.webdriver.findElement( + By.css(".settings-ui-input-error") + ); return error.getText(); } } diff --git a/e2e/lib/OptionPage.ts b/e2e/lib/OptionPage.ts index 9f994a0..e1ea759 100644 --- a/e2e/lib/OptionPage.ts +++ b/e2e/lib/OptionPage.ts @@ -1,7 +1,7 @@ -import { Lanthan } from 'lanthan'; -import { WebDriver, By } from 'selenium-webdriver'; -import JSONOptionPage from './JSONOptionPage'; -import FormOptionPage from './FormOptionPage'; +import { Lanthan } from "lanthan"; +import { WebDriver, By } from "selenium-webdriver"; +import JSONOptionPage from "./JSONOptionPage"; +import FormOptionPage from "./FormOptionPage"; export default class OptionPage { private webdriver: WebDriver; @@ -11,13 +11,17 @@ export default class OptionPage { } static async open(lanthan: Lanthan) { - const url = await lanthan.getWebExtBrowser().runtime.getURL("build/settings.html") + const url = await lanthan + .getWebExtBrowser() + .runtime.getURL("build/settings.html"); await lanthan.getWebDriver().navigate().to(url); return new OptionPage(lanthan); } async switchToForm(): Promise<FormOptionPage> { - const useFormInput = await this.webdriver.findElement(By.css('#setting-source-form')); + const useFormInput = await this.webdriver.findElement( + By.css("#setting-source-form") + ); await useFormInput.click(); await this.webdriver.switchTo().alert().accept(); return new FormOptionPage(this.lanthan); diff --git a/e2e/lib/Page.ts b/e2e/lib/Page.ts index 31605cb..85bda8d 100644 --- a/e2e/lib/Page.ts +++ b/e2e/lib/Page.ts @@ -1,19 +1,18 @@ -import { WebDriver, By, until } from 'selenium-webdriver'; -import { Console } from './Console'; +import { WebDriver, By, until } from "selenium-webdriver"; +import { Console } from "./Console"; type Hint = { - displayed: boolean, - text: string, + displayed: boolean; + text: string; }; type Selection = { - from: number, - to: number, + from: number; + to: number; }; export default class Page { - private constructor(private webdriver: WebDriver) { - } + private constructor(private webdriver: WebDriver) {} static async currentContext(webdriver: WebDriver): Promise<Page> { await Page.waitForConsoleLoaded(webdriver); @@ -26,8 +25,10 @@ export default class Page { return new Page(webdriver); } - async sendKeys(...keys: Array<string|number|Promise<string|number>>): Promise<void> { - const body = await this.webdriver.findElement(By.css('body')); + async sendKeys( + ...keys: Array<string | number | Promise<string | number>> + ): Promise<void> { + const body = await this.webdriver.findElement(By.css("body")); await body.sendKeys(...keys); } @@ -38,17 +39,23 @@ export default class Page { } async showConsole(): Promise<Console> { - const iframe = this.webdriver.findElement(By.css('#vimvixen-console-frame')); + const iframe = this.webdriver.findElement( + By.css("#vimvixen-console-frame") + ); - await this.sendKeys(':'); + await this.sendKeys(":"); await this.webdriver.wait(until.elementIsVisible(iframe)); await this.webdriver.switchTo().frame(0); - await this.webdriver.wait(until.elementLocated(By.css('input.vimvixen-console-command-input'))); + await this.webdriver.wait( + until.elementLocated(By.css("input.vimvixen-console-command-input")) + ); return new Console(this.webdriver); } async getConsole(): Promise<Console> { - const iframe = this.webdriver.findElement(By.css('#vimvixen-console-frame')); + const iframe = this.webdriver.findElement( + By.css("#vimvixen-console-frame") + ); await this.webdriver.wait(until.elementIsVisible(iframe)); await this.webdriver.switchTo().frame(0); @@ -68,16 +75,22 @@ export default class Page { } pageHeight(): Promise<number> { - return this.webdriver.executeScript(() => window.document.documentElement.clientHeight); + return this.webdriver.executeScript( + () => window.document.documentElement.clientHeight + ); } async getSelection(): Promise<Selection> { - const obj = await this.webdriver.executeScript(`return window.getSelection();`) as any; + const obj = (await this.webdriver.executeScript( + `return window.getSelection();` + )) as any; return { from: obj.anchorOffset, to: obj.focusOffset }; } async clearSelection(): Promise<void> { - await this.webdriver.executeScript(`window.getSelection().removeAllRanges()`); + await this.webdriver.executeScript( + `window.getSelection().removeAllRanges()` + ); } async switchToTop(): Promise<void> { @@ -85,15 +98,17 @@ export default class Page { } async waitAndGetHints(): Promise<Hint[]> { - await this.webdriver.wait(until.elementsLocated(By.css('.vimvixen-hint'))); + await this.webdriver.wait(until.elementsLocated(By.css(".vimvixen-hint"))); - const elements = await this.webdriver.findElements(By.css(`.vimvixen-hint`)); + const elements = await this.webdriver.findElements( + By.css(`.vimvixen-hint`) + ); const hints = []; for (const e of elements) { - const display = await e.getCssValue('display'); + const display = await e.getCssValue("display"); const text = await e.getText(); hints.push({ - displayed: display !== 'none', + displayed: display !== "none", text: text, }); } @@ -105,7 +120,9 @@ export default class Page { if (!topFrame) { return; } - await webdriver.wait(until.elementLocated(By.css('iframe.vimvixen-console-frame'))); - await new Promise(resolve => setTimeout(resolve, 100)); + await webdriver.wait( + until.elementLocated(By.css("iframe.vimvixen-console-frame")) + ); + await new Promise((resolve) => setTimeout(resolve, 100)); } } diff --git a/e2e/lib/SettingRepository.ts b/e2e/lib/SettingRepository.ts index 3bdf6d2..87fb50b 100644 --- a/e2e/lib/SettingRepository.ts +++ b/e2e/lib/SettingRepository.ts @@ -1,18 +1,15 @@ -import { JSONTextSettings, SettingSource } from '../../src/shared/SettingData'; -import Settings from '../../src/shared/settings/Settings'; +import { JSONTextSettings, SettingSource } from "../../src/shared/SettingData"; +import Settings from "../../src/shared/settings/Settings"; export default class SettingRepository { - constructor( - private readonly browser: any, - ) { - } + constructor(private readonly browser: any) {} async saveJSON(settings: Settings): Promise<void> { await this.browser.storage.sync.set({ settings: { source: SettingSource.JSON, - json: JSONTextSettings.fromSettings(settings).toJSONText(), - } + json: JSONTextSettings.fromSettings(settings).toJSONText(), + }, }); } } diff --git a/e2e/lib/TestServer.ts b/e2e/lib/TestServer.ts index 5b9eee3..e0c711b 100644 --- a/e2e/lib/TestServer.ts +++ b/e2e/lib/TestServer.ts @@ -1,6 +1,6 @@ -import * as http from 'http'; -import * as net from 'net' -import express from 'express'; +import * as http from "http"; +import * as net from "net"; +import express from "express"; type HandlerFunc = (req: express.Request, res: express.Response) => void; @@ -9,10 +9,7 @@ export default class TestServer { private app: express.Application; - constructor( - private port = 0, - private address = '127.0.0.1', - ){ + constructor(private port = 0, private address = "127.0.0.1") { this.app = express(); } @@ -23,30 +20,30 @@ export default class TestServer { receiveContent(path: string, content: string): TestServer { this.app.get(path, (_req: express.Request, res: express.Response) => { - res.status(200).send(content) + res.status(200).send(content); }); return this; } - - url(path = '/'): string { + + url(path = "/"): string { if (!this.http) { - throw new Error('http server not started'); + throw new Error("http server not started"); } const addr = this.http.address() as net.AddressInfo; - return `http://${addr.address}:${addr.port}${path}` + return `http://${addr.address}:${addr.port}${path}`; } - start(): Promise<void> { + start(): Promise<void> { if (this.http) { - throw new Error('http server already started'); + throw new Error("http server already started"); } - this.http = http.createServer(this.app) + this.http = http.createServer(this.app); return new Promise((resolve) => { this.http!!.listen(this.port, this.address, () => { resolve(); - }) + }); }); } @@ -59,6 +56,6 @@ export default class TestServer { this.http = undefined; resolve(); }); - }) + }); } } diff --git a/e2e/lib/clipboard.ts b/e2e/lib/clipboard.ts index 297b71a..6cc94cb 100644 --- a/e2e/lib/clipboard.ts +++ b/e2e/lib/clipboard.ts @@ -1,18 +1,19 @@ -import { spawn } from 'child_process'; +import { spawn } from "child_process"; const readLinux = (): Promise<string> => { - let stdout = '', stderr = ''; + let stdout = "", + stderr = ""; return new Promise((resolve) => { - const xsel = spawn('xsel', ['--clipboard', '--output']); - xsel.stdout.on('data', (data) => { + const xsel = spawn("xsel", ["--clipboard", "--output"]); + xsel.stdout.on("data", (data) => { stdout += data; }); - xsel.stderr.on('data', (data) => { + xsel.stderr.on("data", (data) => { stderr += data; }); - xsel.on('close', (code) => { + xsel.on("close", (code) => { if (code !== 0) { - throw new Error(`xsel returns ${code}: ${stderr}`) + throw new Error(`xsel returns ${code}: ${stderr}`); } resolve(stdout); }); @@ -20,15 +21,15 @@ const readLinux = (): Promise<string> => { }; const writeLinux = (data: string): Promise<string> => { - let stderr = ''; + let stderr = ""; return new Promise((resolve) => { - const xsel = spawn('xsel', ['--clipboard', '--input']); - xsel.stderr.on('data', (data) => { + const xsel = spawn("xsel", ["--clipboard", "--input"]); + xsel.stderr.on("data", (data) => { stderr += data; }); - xsel.on('close', (code) => { + xsel.on("close", (code) => { if (code !== 0) { - throw new Error(`xsel returns ${code}: ${stderr}`) + throw new Error(`xsel returns ${code}: ${stderr}`); } resolve(); }); @@ -38,18 +39,19 @@ const writeLinux = (data: string): Promise<string> => { }; const readDarwin = (): Promise<string> => { - let stdout = '', stderr = ''; + let stdout = "", + stderr = ""; return new Promise((resolve) => { - const pbpaste = spawn('pbpaste'); - pbpaste.stdout.on('data', (data) => { + const pbpaste = spawn("pbpaste"); + pbpaste.stdout.on("data", (data) => { stdout += data; }); - pbpaste.stderr.on('data', (data) => { + pbpaste.stderr.on("data", (data) => { stderr += data; }); - pbpaste.on('close', (code) => { + pbpaste.on("close", (code) => { if (code !== 0) { - throw new Error(`pbpaste returns ${code}: ${stderr}`) + throw new Error(`pbpaste returns ${code}: ${stderr}`); } resolve(stdout); }); @@ -57,15 +59,15 @@ const readDarwin = (): Promise<string> => { }; const writeDarwin = (data: string): Promise<string> => { - let stderr = ''; + let stderr = ""; return new Promise((resolve) => { - const pbcopy = spawn('pbcopy'); - pbcopy.stderr.on('data', (data) => { + const pbcopy = spawn("pbcopy"); + pbcopy.stderr.on("data", (data) => { stderr += data; }); - pbcopy.on('close', (code) => { + pbcopy.on("close", (code) => { if (code !== 0) { - throw new Error(`pbcopy returns ${code}: ${stderr}`) + throw new Error(`pbcopy returns ${code}: ${stderr}`); } resolve(); }); @@ -83,25 +85,22 @@ class UnsupportedError extends Error { const read = () => { switch (process.platform) { - case 'linux': - return readLinux(); - case 'darwin': - return readDarwin(); + case "linux": + return readLinux(); + case "darwin": + return readDarwin(); } throw new UnsupportedError(process.platform); -} +}; const write = (data: string) => { switch (process.platform) { - case 'linux': - return writeLinux(data); - case 'darwin': - return writeDarwin(data); + case "linux": + return writeLinux(data); + case "darwin": + return writeDarwin(data); } throw new UnsupportedError(process.platform); -} - -export { - read, - write, }; + +export { read, write }; diff --git a/e2e/mark.test.ts b/e2e/mark.test.ts index c73423b..d7ec26c 100644 --- a/e2e/mark.test.ts +++ b/e2e/mark.test.ts @@ -1,102 +1,100 @@ -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 } from 'selenium-webdriver'; -import Page from './lib/Page'; +import TestServer from "./lib/TestServer"; +import eventually from "./eventually"; +import { Builder, Lanthan } from "lanthan"; +import { WebDriver } from "selenium-webdriver"; +import Page from "./lib/Page"; describe("mark test", () => { - const server = new TestServer().receiveContent('/', - `<!DOCTYPE html><html lang="en"><body style="width:10000px; height:10000px"></body></html>`, + const server = new TestServer().receiveContent( + "/", + `<!DOCTYPE html><html lang="en"><body style="width:10000px; height:10000px"></body></html>` ); let lanthan: Lanthan; let webdriver: WebDriver; let browser: any; - before(async() => { - lanthan = await Builder - .forBrowser('firefox') - .spyAddon(path.join(__dirname, '..')) + before(async () => { + lanthan = await Builder.forBrowser("firefox") + .spyAddon(path.join(__dirname, "..")) .build(); webdriver = lanthan.getWebDriver(); browser = lanthan.getWebExtBrowser(); - await server.start() + await server.start(); }); - after(async() => { + after(async () => { await server.stop(); if (lanthan) { await lanthan.quit(); } }); - it('should set a local mark and jump to it', async () => { + it("should set a local mark and jump to it", async () => { const page = await Page.navigateTo(webdriver, server.url()); await page.scrollTo(200, 200); - await page.sendKeys('m', 'a'); + await page.sendKeys("m", "a"); await page.scrollTo(500, 500); - await page.sendKeys('\'', 'a'); + await page.sendKeys("'", "a"); - await eventually(async() => { + await eventually(async () => { assert.strictEqual(await page.getScrollX(), 200); assert.strictEqual(await page.getScrollY(), 200); }); }); - it('should set a global mark and jump to it', async () => { - let page = await Page.navigateTo(webdriver, server.url('/#first')); + it("should set a global mark and jump to it", async () => { + let page = await Page.navigateTo(webdriver, server.url("/#first")); await page.scrollTo(200, 200); - await page.sendKeys('m', 'A'); + await page.sendKeys("m", "A"); await page.scrollTo(500, 500); - await page.sendKeys('\'', 'A'); + await page.sendKeys("'", "A"); - await eventually(async() => { + await eventually(async () => { assert.strictEqual(await page.getScrollX(), 200); assert.strictEqual(await page.getScrollY(), 200); }); - await browser.tabs.create({ url: server.url('/#second') }); + await browser.tabs.create({ url: server.url("/#second") }); page = await Page.currentContext(webdriver); - await page.sendKeys('\'', 'A'); + await page.sendKeys("'", "A"); - await eventually(async() => { + await eventually(async () => { const tab = (await browser.tabs.query({ active: true }))[0]; const url = new URL(tab.url); - assert.strictEqual(url.hash, '#first'); + assert.strictEqual(url.hash, "#first"); assert.strictEqual(await page.getScrollX(), 200); assert.strictEqual(await page.getScrollY(), 200); }); }); - it('set a global mark and creates new tab from gone', async () => { - let page = await Page.navigateTo(webdriver, server.url('/#first')); + it("set a global mark and creates new tab from gone", async () => { + let page = await Page.navigateTo(webdriver, server.url("/#first")); await page.scrollTo(500, 500); - await page.sendKeys('m', 'A'); + await page.sendKeys("m", "A"); const tab = (await browser.tabs.query({ active: true }))[0]; - await browser.tabs.create({ url: server.url('/#second') }); + await browser.tabs.create({ url: server.url("/#second") }); await browser.tabs.remove(tab.id); let handles: string[]; - await eventually(async() => { + await eventually(async () => { handles = await webdriver.getAllWindowHandles(); assert.strictEqual(handles.length, 2); }); await webdriver.switchTo().window(handles!![0]); - page = await Page.navigateTo(webdriver, server.url('/#second')); - await page.sendKeys('\'', 'A'); + page = await Page.navigateTo(webdriver, server.url("/#second")); + await page.sendKeys("'", "A"); - await eventually(async() => { + await eventually(async () => { const tab = (await browser.tabs.query({ active: true }))[0]; const url = new URL(tab.url); - assert.strictEqual(url.hash, '#first'); + assert.strictEqual(url.hash, "#first"); }); }); }); - - 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(` <!DOCTYPE html> <html lang="en"> @@ -19,26 +19,33 @@ const newApp = () => { </html>`); }); - server.handle('/pagenation-link/:page', (req, res) => { + 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> + <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', ` + 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>`); + </html>` + ); - 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 <a> 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 <a> 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 <a> by ]]', async () => { - const page = await Page.navigateTo(webdriver, server.url('/pagenation-a/10')); - await page.sendKeys(']', ']'); + it("should go next page in <a> 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 <link> by ]]', async () => { - const page = await Page.navigateTo(webdriver, server.url('/pagenation-link/10')); - await page.sendKeys('[', '['); + it("should go previous page in <link> 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 <link> by [[', async () => { - const page = await Page.navigateTo(webdriver, server.url('/pagenation-link/10')); - await page.sendKeys(']', ']'); + it("should go next page by in <link> 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); }); diff --git a/e2e/options.test.ts b/e2e/options.test.ts index 91a3dde..64f24be 100644 --- a/e2e/options.test.ts +++ b/e2e/options.test.ts @@ -1,25 +1,25 @@ -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 } from 'selenium-webdriver'; -import Page from './lib/Page'; -import OptionPage from './lib/OptionPage'; +import TestServer from "./lib/TestServer"; +import eventually from "./eventually"; +import { Builder, Lanthan } from "lanthan"; +import { WebDriver } from "selenium-webdriver"; +import Page from "./lib/Page"; +import OptionPage from "./lib/OptionPage"; describe("options page", () => { - const server = new TestServer().receiveContent('/', - `<!DOCTYPE html><html lang="en"><body style="width:10000px; height:10000px"></body></html>`, + const server = new TestServer().receiveContent( + "/", + `<!DOCTYPE html><html lang="en"><body style="width:10000px; height:10000px"></body></html>` ); let lanthan: Lanthan; let webdriver: WebDriver; let browser: any; - before(async() => { - lanthan = await Builder - .forBrowser('firefox') - .spyAddon(path.join(__dirname, '..')) + before(async () => { + lanthan = await Builder.forBrowser("firefox") + .spyAddon(path.join(__dirname, "..")) .build(); webdriver = lanthan.getWebDriver(); browser = lanthan.getWebExtBrowser(); @@ -27,43 +27,51 @@ describe("options page", () => { await server.start(); }); - after(async() => { + after(async () => { if (lanthan) { await lanthan.quit(); } await server.stop(); }); - beforeEach(async() => { + beforeEach(async () => { const tabs = await browser.tabs.query({}); for (const tab of tabs.slice(1)) { await browser.tabs.remove(tab.id); } }); - it('saves current config on blur', async () => { + it("saves current config on blur", async () => { const page = await OptionPage.open(lanthan); const jsonPage = await page.asJSONOptionPage(); await jsonPage.updateSettings(`{ "blacklist": [ "https://example.com" ] }`); - let { settings } = await browser.storage.local.get('settings'); - assert.strictEqual(settings.source, 'json'); - assert.strictEqual(settings.json, '{ "blacklist": [ "https://example.com" ] } '); + let { settings } = await browser.storage.local.get("settings"); + assert.strictEqual(settings.source, "json"); + assert.strictEqual( + settings.json, + '{ "blacklist": [ "https://example.com" ] } ' + ); await jsonPage.updateSettings(`invalid json`); - settings = (await browser.storage.local.get('settings')).settings; - assert.strictEqual(settings.source, 'json'); - assert.strictEqual(settings.json, '{ "blacklist": [ "https://example.com" ] } '); + settings = (await browser.storage.local.get("settings")).settings; + assert.strictEqual(settings.source, "json"); + assert.strictEqual( + settings.json, + '{ "blacklist": [ "https://example.com" ] } ' + ); const message = await jsonPage.getErrorMessage(); - assert.ok(message.startsWith('SyntaxError:')) + assert.ok(message.startsWith("SyntaxError:")); }); - it('updates keymaps without reloading', async () => { + it("updates keymaps without reloading", async () => { const optionPage = await OptionPage.open(lanthan); const jsonPage = await optionPage.asJSONOptionPage(); - await jsonPage.updateSettings(`{ "keymaps": { "zz": { "type": "scroll.vertically", "count": 10 } } }`); + await jsonPage.updateSettings( + `{ "keymaps": { "zz": { "type": "scroll.vertically", "count": 10 } } }` + ); await browser.tabs.create({ url: server.url(), active: false }); await new Promise((resolve) => setTimeout(resolve, 100)); @@ -71,11 +79,11 @@ describe("options page", () => { await webdriver.switchTo().window(handles[1]); const page = await Page.currentContext(webdriver); - await page.sendKeys('zz'); + await page.sendKeys("zz"); - await eventually(async() => { + await eventually(async () => { const y = await page.getScrollY(); assert.strictEqual(y, 640); }); - }) + }); }); diff --git a/e2e/options_form.test.ts b/e2e/options_form.test.ts index 2121348..bb5ebf1 100644 --- a/e2e/options_form.test.ts +++ b/e2e/options_form.test.ts @@ -1,17 +1,16 @@ -import * as path from 'path'; -import * as assert from 'assert'; +import * as path from "path"; +import * as assert from "assert"; -import { Builder, Lanthan } from 'lanthan'; -import OptionPage from './lib/OptionPage'; +import { Builder, Lanthan } from "lanthan"; +import OptionPage from "./lib/OptionPage"; describe("options form page", () => { let lanthan: Lanthan; let browser: any; - beforeEach(async() => { - lanthan = await Builder - .forBrowser('firefox') - .spyAddon(path.join(__dirname, '..')) + beforeEach(async () => { + lanthan = await Builder.forBrowser("firefox") + .spyAddon(path.join(__dirname, "..")) .build(); browser = lanthan.getWebExtBrowser(); @@ -21,109 +20,119 @@ describe("options form page", () => { } }); - afterEach(async() => { + afterEach(async () => { if (lanthan) { await lanthan.quit(); } }); - it('switch to form settings', async () => { + it("switch to form settings", async () => { const page = await OptionPage.open(lanthan); await page.switchToForm(); - const { settings } = await browser.storage.local.get('settings'); - assert.strictEqual(settings.source, 'form') + const { settings } = await browser.storage.local.get("settings"); + assert.strictEqual(settings.source, "form"); }); - it('add blacklist item', async () => { + it("add blacklist item", async () => { const page = await OptionPage.open(lanthan); const forms = await page.switchToForm(); // assert default - let settings = (await browser.storage.local.get('settings')).settings; + let settings = (await browser.storage.local.get("settings")).settings; assert.deepStrictEqual(settings.form.blacklist, []); // add blacklist items await forms.addBlacklist(); - await forms.setBlacklist(0, 'google.com'); + await forms.setBlacklist(0, "google.com"); - settings = (await browser.storage.local.get('settings')).settings; - assert.deepStrictEqual(settings.form.blacklist, ['google.com']); + settings = (await browser.storage.local.get("settings")).settings; + assert.deepStrictEqual(settings.form.blacklist, ["google.com"]); await forms.addBlacklist(); - await forms.setBlacklist(1, 'yahoo.com'); + await forms.setBlacklist(1, "yahoo.com"); - settings = (await browser.storage.local.get('settings')).settings; - assert.deepStrictEqual(settings.form.blacklist, ['google.com', 'yahoo.com']); + settings = (await browser.storage.local.get("settings")).settings; + assert.deepStrictEqual(settings.form.blacklist, [ + "google.com", + "yahoo.com", + ]); // delete first item await forms.removeBlackList(0); - settings = (await browser.storage.local.get('settings')).settings; - assert.deepStrictEqual(settings.form.blacklist, ['yahoo.com']) + settings = (await browser.storage.local.get("settings")).settings; + assert.deepStrictEqual(settings.form.blacklist, ["yahoo.com"]); }); - it('add a partial blacklist item', async () => { + it("add a partial blacklist item", async () => { const page = await OptionPage.open(lanthan); const forms = await page.switchToForm(); // assert default - let settings = (await browser.storage.local.get('settings')).settings; + let settings = (await browser.storage.local.get("settings")).settings; assert.deepStrictEqual(settings.form.blacklist, []); // add blacklist items await forms.addPartialBlacklist(); - await forms.setPartialBlacklist(0, 'google.com', 'j,k,<C-U>'); + await forms.setPartialBlacklist(0, "google.com", "j,k,<C-U>"); - settings = (await browser.storage.local.get('settings')).settings; + settings = (await browser.storage.local.get("settings")).settings; assert.deepStrictEqual(settings.form.blacklist, [ - { url: 'google.com', keys: ['j', 'k', '<C-U>'] }, + { url: "google.com", keys: ["j", "k", "<C-U>"] }, ]); await forms.addPartialBlacklist(); - await forms.setPartialBlacklist(1, 'yahoo.com', 'g,G'); + await forms.setPartialBlacklist(1, "yahoo.com", "g,G"); - settings = (await browser.storage.local.get('settings')).settings; + settings = (await browser.storage.local.get("settings")).settings; assert.deepStrictEqual(settings.form.blacklist, [ - { url: 'google.com', keys: ['j', 'k', '<C-U>'] }, - { url: 'yahoo.com', keys: ['g', 'G'] }, + { url: "google.com", keys: ["j", "k", "<C-U>"] }, + { url: "yahoo.com", keys: ["g", "G"] }, ]); await forms.addBlacklist(); - await forms.setBlacklist(0, 'bing.com'); + await forms.setBlacklist(0, "bing.com"); - settings = (await browser.storage.local.get('settings')).settings; + settings = (await browser.storage.local.get("settings")).settings; assert.deepStrictEqual(settings.form.blacklist, [ - { url: 'google.com', keys: ['j', 'k', '<C-U>'] }, - { url: 'yahoo.com', keys: ['g', 'G'] }, - 'bing.com', + { url: "google.com", keys: ["j", "k", "<C-U>"] }, + { url: "yahoo.com", keys: ["g", "G"] }, + "bing.com", ]); // delete first item await forms.removePartialBlackList(0); - settings = (await browser.storage.local.get('settings')).settings; + settings = (await browser.storage.local.get("settings")).settings; assert.deepStrictEqual(settings.form.blacklist, [ - { url: 'yahoo.com', keys: ['g', 'G'] }, - 'bing.com', - ]) + { url: "yahoo.com", keys: ["g", "G"] }, + "bing.com", + ]); }); - it('add search engines', async () => { + it("add search engines", async () => { const page = await OptionPage.open(lanthan); const forms = await page.switchToForm(); // assert default - let settings = (await browser.storage.local.get('settings')).settings; - assert.deepStrictEqual(settings.form.search.default, 'google'); + let settings = (await browser.storage.local.get("settings")).settings; + assert.deepStrictEqual(settings.form.search.default, "google"); // change default await forms.setDefaultSearchEngine(2); - settings = (await browser.storage.local.get('settings')).settings; - assert.deepStrictEqual(settings.form.search.default, 'bing'); + settings = (await browser.storage.local.get("settings")).settings; + assert.deepStrictEqual(settings.form.search.default, "bing"); await forms.addSearchEngine(); - await forms.setSearchEngine(6, 'yippy', 'https://www.yippy.com/search?query={}'); - - settings = (await browser.storage.local.get('settings')).settings; - assert.deepStrictEqual(settings.form.search.engines[6], ['yippy', 'https://www.yippy.com/search?query={}']); + await forms.setSearchEngine( + 6, + "yippy", + "https://www.yippy.com/search?query={}" + ); + + settings = (await browser.storage.local.get("settings")).settings; + assert.deepStrictEqual(settings.form.search.engines[6], [ + "yippy", + "https://www.yippy.com/search?query={}", + ]); }); }); diff --git a/e2e/partial_blacklist.test.ts b/e2e/partial_blacklist.test.ts index cb66549..8bc1c0e 100644 --- a/e2e/partial_blacklist.test.ts +++ b/e2e/partial_blacklist.test.ts @@ -1,57 +1,57 @@ -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 { Builder, Lanthan } from 'lanthan'; -import { WebDriver } from 'selenium-webdriver'; -import Page from './lib/Page'; -import Settings from '../src/shared/settings/Settings'; -import SettingRepository from './lib/SettingRepository'; +import TestServer from "./lib/TestServer"; +import { Builder, Lanthan } from "lanthan"; +import { WebDriver } from "selenium-webdriver"; +import Page from "./lib/Page"; +import Settings from "../src/shared/settings/Settings"; +import SettingRepository from "./lib/SettingRepository"; describe("partial blacklist test", () => { - const server = new TestServer().receiveContent('/*', - `<!DOCTYPE html><html lang="en"><body style="width:10000px; height:10000px"></body></html>`, + const server = new TestServer().receiveContent( + "/*", + `<!DOCTYPE html><html lang="en"><body style="width:10000px; height:10000px"></body></html>` ); let lanthan: Lanthan; let webdriver: WebDriver; let browser: any; - before(async() => { - lanthan = await Builder - .forBrowser('firefox') - .spyAddon(path.join(__dirname, '..')) + before(async () => { + lanthan = await Builder.forBrowser("firefox") + .spyAddon(path.join(__dirname, "..")) .build(); webdriver = lanthan.getWebDriver(); browser = lanthan.getWebExtBrowser(); await server.start(); - const url = server.url().replace('http://', ''); - await new SettingRepository(browser).saveJSON(Settings.fromJSON({ - keymaps: { - j: { type: 'scroll.vertically', count: 1 }, - k: { type: 'scroll.vertically', count: -1 }, - }, - blacklist: [ - { 'url': url, 'keys': ['k'] } - ] - })); + const url = server.url().replace("http://", ""); + await new SettingRepository(browser).saveJSON( + Settings.fromJSON({ + keymaps: { + j: { type: "scroll.vertically", count: 1 }, + k: { type: "scroll.vertically", count: -1 }, + }, + blacklist: [{ url: url, keys: ["k"] }], + }) + ); }); - after(async() => { + after(async () => { await server.stop(); if (lanthan) { await lanthan.quit(); } }); - it('should disable keys in the partial blacklist', async () => { - const page = await Page.navigateTo(webdriver, server.url('/')); + it("should disable keys in the partial blacklist", async () => { + const page = await Page.navigateTo(webdriver, server.url("/")); - await page.sendKeys('j'); + await page.sendKeys("j"); let scrollY = await page.getScrollY(); assert.strictEqual(scrollY, 64); - await page.sendKeys('k'); + await page.sendKeys("k"); scrollY = await page.getScrollY(); assert.strictEqual(scrollY, 64); }); diff --git a/e2e/repeat.test.ts b/e2e/repeat.test.ts index 7c8b5e2..04d1331 100644 --- a/e2e/repeat.test.ts +++ b/e2e/repeat.test.ts @@ -1,73 +1,72 @@ -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 } from 'selenium-webdriver'; -import Page from './lib/Page'; +import TestServer from "./lib/TestServer"; +import eventually from "./eventually"; +import { Builder, Lanthan } from "lanthan"; +import { WebDriver } from "selenium-webdriver"; +import Page from "./lib/Page"; describe("tab test", () => { - const server = new TestServer().receiveContent('/*', 'ok'); + const server = new TestServer().receiveContent("/*", "ok"); let lanthan: Lanthan; let webdriver: WebDriver; let browser: any; - before(async() => { - lanthan = await Builder - .forBrowser('firefox') - .spyAddon(path.join(__dirname, '..')) + before(async () => { + lanthan = await Builder.forBrowser("firefox") + .spyAddon(path.join(__dirname, "..")) .build(); webdriver = lanthan.getWebDriver(); browser = lanthan.getWebExtBrowser(); await server.start(); }); - after(async() => { + after(async () => { await server.stop(); if (lanthan) { await lanthan.quit(); } }); - it('repeats last command', async () => { + it("repeats last command", async () => { let page = await Page.navigateTo(webdriver, server.url()); const console = await page.showConsole(); - await console.execCommand(`tabopen ${server.url('/newtab')}`); + await console.execCommand(`tabopen ${server.url("/newtab")}`); - await eventually(async() => { + await eventually(async () => { const current = await browser.tabs.query({ url: `*://*/newtab` }); assert.strictEqual(current.length, 1); }); page = await Page.currentContext(webdriver); - await page.sendKeys('.'); + await page.sendKeys("."); - await eventually(async() => { + await eventually(async () => { const current = await browser.tabs.query({ url: `*://*/newtab` }); assert.strictEqual(current.length, 2); }); }); - it('repeats last operation', async () => { + it("repeats last operation", async () => { for (let i = 1; i < 5; ++i) { - await browser.tabs.create({ url: server.url('/#' + i) }); + await browser.tabs.create({ url: server.url("/#" + i) }); } const before = await browser.tabs.query({}); let page = await Page.currentContext(webdriver); - await page.sendKeys('d'); + await page.sendKeys("d"); - await eventually(async() => { + await eventually(async () => { const current = await browser.tabs.query({}); - assert.strictEqual(current.length, before.length - 1); + assert.strictEqual(current.length, before.length - 1); }); await browser.tabs.update(before[2].id, { active: true }); page = await Page.currentContext(webdriver); - await page.sendKeys('.'); + await page.sendKeys("."); - await eventually(async() => { + await eventually(async () => { const current = await browser.tabs.query({}); assert.strictEqual(current.length, before.length - 2); }); diff --git a/e2e/repeat_n_times.test.ts b/e2e/repeat_n_times.test.ts index a646112..303aa34 100644 --- a/e2e/repeat_n_times.test.ts +++ b/e2e/repeat_n_times.test.ts @@ -1,24 +1,24 @@ -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 } from 'selenium-webdriver'; -import Page from './lib/Page'; +import TestServer from "./lib/TestServer"; +import eventually from "./eventually"; +import { Builder, Lanthan } from "lanthan"; +import { WebDriver } from "selenium-webdriver"; +import Page from "./lib/Page"; describe("tab test", () => { - const server = new TestServer().receiveContent('/', - `<!DOCTYPE html><html lang="en"><body style="width:10000px; height:10000px"></body></html>`, + const server = new TestServer().receiveContent( + "/", + `<!DOCTYPE html><html lang="en"><body style="width:10000px; height:10000px"></body></html>` ); let lanthan: Lanthan; let webdriver: WebDriver; let browser: any; - before(async() => { - lanthan = await Builder - .forBrowser('firefox') - .spyAddon(path.join(__dirname, '..')) + before(async () => { + lanthan = await Builder.forBrowser("firefox") + .spyAddon(path.join(__dirname, "..")) .build(); webdriver = lanthan.getWebDriver(); browser = lanthan.getWebExtBrowser(); @@ -27,32 +27,35 @@ describe("tab test", () => { browser = browser; }); - after(async() => { + after(async () => { await server.stop(); if (lanthan) { await lanthan.quit(); } }); - it('repeats scroll 3-times', async () => { + it("repeats scroll 3-times", async () => { const page = await Page.navigateTo(webdriver, server.url()); - await page.sendKeys('3', 'j'); + await page.sendKeys("3", "j"); const scrollY = await page.getScrollY(); assert.strictEqual(scrollY, 64 * 3); }); - it('repeats tab deletion 3-times', async () => { - const win = await browser.windows.create({ url: server.url('/#0') }); + it("repeats tab deletion 3-times", async () => { + const win = await browser.windows.create({ url: server.url("/#0") }); for (let i = 1; i < 5; ++i) { - await browser.tabs.create({ url: server.url('/#' + i), windowId: win.id }); - await webdriver.navigate().to(server.url('/#' + i)); + await browser.tabs.create({ + url: server.url("/#" + i), + windowId: win.id, + }); + await webdriver.navigate().to(server.url("/#" + i)); } const page = await Page.navigateTo(webdriver, server.url()); - await page.sendKeys('3', 'd'); + await page.sendKeys("3", "d"); - await eventually(async() => { + await eventually(async () => { const current = await browser.tabs.query({ windowId: win.id }); assert.strictEqual(current.length, 2); }); diff --git a/e2e/scroll.test.ts b/e2e/scroll.test.ts index 9b39a2e..277bb2e 100644 --- a/e2e/scroll.test.ts +++ b/e2e/scroll.test.ts @@ -1,134 +1,141 @@ -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 { Builder, Lanthan } from 'lanthan'; -import { WebDriver, Key } from 'selenium-webdriver'; -import Page from './lib/Page'; +import TestServer from "./lib/TestServer"; +import { Builder, Lanthan } from "lanthan"; +import { WebDriver, Key } from "selenium-webdriver"; +import Page from "./lib/Page"; describe("scroll test", () => { - const server = new TestServer().receiveContent('/', - `<!DOCTYPE html><html lang="en"><body style="width:10000px; height:10000px"></body></html>`, + const server = new TestServer().receiveContent( + "/", + `<!DOCTYPE html><html lang="en"><body style="width:10000px; height:10000px"></body></html>` ); let lanthan: Lanthan; let webdriver: WebDriver; let page: Page; - before(async() => { - lanthan = await Builder - .forBrowser('firefox') - .spyAddon(path.join(__dirname, '..')) + before(async () => { + lanthan = await Builder.forBrowser("firefox") + .spyAddon(path.join(__dirname, "..")) .build(); webdriver = lanthan.getWebDriver(); await server.start(); }); - after(async() => { + after(async () => { await server.stop(); if (lanthan) { await lanthan.quit(); } }); - beforeEach(async() => { + beforeEach(async () => { await webdriver.navigate().to(server.url()); page = await Page.currentContext(webdriver); }); - - it('scrolls up by j', async () => { - await page.sendKeys('j'); + it("scrolls up by j", async () => { + await page.sendKeys("j"); const scrollY = await page.getScrollY(); assert.strictEqual(scrollY, 64); }); - it('scrolls down by k', async () => { + it("scrolls down by k", async () => { await webdriver.executeScript(() => window.scrollTo(0, 200)); - await page.sendKeys('k'); + await page.sendKeys("k"); const scrollY = await page.getScrollY(); assert.strictEqual(scrollY, 136); }); - it('scrolls left by h', async () => { + it("scrolls left by h", async () => { await webdriver.executeScript(() => window.scrollTo(100, 100)); - await page.sendKeys('h'); + await page.sendKeys("h"); - const pageXOffset = await webdriver.executeScript(() => window.pageXOffset) as number; + const pageXOffset = (await webdriver.executeScript( + () => window.pageXOffset + )) as number; assert.strictEqual(pageXOffset, 36); }); - it('scrolls left by l', async () => { + it("scrolls left by l", async () => { await webdriver.executeScript(() => window.scrollTo(100, 100)); - await page.sendKeys('l'); + await page.sendKeys("l"); - const pageXOffset = await webdriver.executeScript(() => window.pageXOffset) as number; + const pageXOffset = (await webdriver.executeScript( + () => window.pageXOffset + )) as number; assert.strictEqual(pageXOffset, 164); }); - it('scrolls top by gg', async () => { + it("scrolls top by gg", async () => { await webdriver.executeScript(() => window.scrollTo(0, 100)); - await page.sendKeys('g', 'g'); + await page.sendKeys("g", "g"); const scrollY = await page.getScrollY(); assert.strictEqual(scrollY, 0); }); - it('scrolls bottom by G', async () => { + it("scrolls bottom by G", async () => { await webdriver.executeScript(() => window.scrollTo(0, 100)); - await page.sendKeys(Key.SHIFT, 'g'); + await page.sendKeys(Key.SHIFT, "g"); const scrollY = await page.getScrollY(); assert.ok(scrollY > 5000); }); - it('scrolls bottom by 0', async () => { + it("scrolls bottom by 0", async () => { await webdriver.executeScript(() => window.scrollTo(0, 100)); - await page.sendKeys(Key.SHIFT, '0'); + await page.sendKeys(Key.SHIFT, "0"); - const pageXOffset = await webdriver.executeScript(() => window.pageXOffset) as number; + const pageXOffset = (await webdriver.executeScript( + () => window.pageXOffset + )) as number; assert.ok(pageXOffset === 0); }); - it('scrolls bottom by $', async () => { + it("scrolls bottom by $", async () => { await webdriver.executeScript(() => window.scrollTo(0, 100)); - await page.sendKeys(Key.SHIFT, '$'); + await page.sendKeys(Key.SHIFT, "$"); - const pageXOffset = await webdriver.executeScript(() => window.pageXOffset) as number; + const pageXOffset = (await webdriver.executeScript( + () => window.pageXOffset + )) as number; assert.ok(pageXOffset > 5000); }); - it('scrolls bottom by <C-U>', async () => { + it("scrolls bottom by <C-U>", async () => { await webdriver.executeScript(() => window.scrollTo(0, 1000)); - await page.sendKeys(Key.CONTROL, 'u'); + await page.sendKeys(Key.CONTROL, "u"); const pageHeight = await page.pageHeight(); const scrollY = await page.getScrollY(); assert.ok(Math.abs(scrollY - (1000 - Math.floor(pageHeight / 2))) < 5); }); - it('scrolls bottom by <C-D>', async () => { + it("scrolls bottom by <C-D>", async () => { await webdriver.executeScript(() => window.scrollTo(0, 1000)); - await page.sendKeys(Key.CONTROL, 'd'); + await page.sendKeys(Key.CONTROL, "d"); const pageHeight = await page.pageHeight(); const scrollY = await page.getScrollY(); assert.ok(Math.abs(scrollY - (1000 + Math.floor(pageHeight / 2))) < 5); }); - it('scrolls bottom by <C-B>', async () => { + it("scrolls bottom by <C-B>", async () => { await webdriver.executeScript(() => window.scrollTo(0, 1000)); - await page.sendKeys(Key.CONTROL, 'b'); + await page.sendKeys(Key.CONTROL, "b"); const pageHeight = await page.pageHeight(); const scrollY = await page.getScrollY(); assert.ok(Math.abs(scrollY - (1000 - pageHeight)) < 5); }); - it('scrolls bottom by <C-F>', async () => { + it("scrolls bottom by <C-F>", async () => { await webdriver.executeScript(() => window.scrollTo(0, 1000)); - await page.sendKeys(Key.CONTROL, 'f'); + await page.sendKeys(Key.CONTROL, "f"); const pageHeight = await page.pageHeight(); const scrollY = await page.getScrollY(); diff --git a/e2e/tab.test.ts b/e2e/tab.test.ts index 6a8e815..98ec9f8 100644 --- a/e2e/tab.test.ts +++ b/e2e/tab.test.ts @@ -1,57 +1,59 @@ -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 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 Page from "./lib/Page"; describe("tab test", () => { - const server = new TestServer().receiveContent('/*', 'ok'); + const server = new TestServer().receiveContent("/*", "ok"); let lanthan: Lanthan; let webdriver: WebDriver; let browser: any; let win: any; let tabs: any[]; - before(async() => { - lanthan = await Builder - .forBrowser('firefox') - .spyAddon(path.join(__dirname, '..')) + before(async () => { + lanthan = await Builder.forBrowser("firefox") + .spyAddon(path.join(__dirname, "..")) .build(); webdriver = lanthan.getWebDriver(); browser = lanthan.getWebExtBrowser(); await server.start(); }); - after(async() => { + after(async () => { await server.stop(); if (lanthan) { await lanthan.quit(); } }); - beforeEach(async() => { - win = await browser.windows.create({ url: server.url('/#0') }); + beforeEach(async () => { + win = await browser.windows.create({ url: server.url("/#0") }); for (let i = 1; i < 5; ++i) { - await browser.tabs.create({ url: server.url('/#' + i), windowId: win.id }); - await webdriver.navigate().to(server.url('/#' + i)); + await browser.tabs.create({ + url: server.url("/#" + i), + windowId: win.id, + }); + await webdriver.navigate().to(server.url("/#" + i)); } tabs = await browser.tabs.query({ windowId: win.id }); tabs.sort((t1: any, t2: any) => t1.index - t2.index); }); - afterEach(async() => { + afterEach(async () => { await browser.windows.remove(win.id); }); - it('deletes tab and selects right by d', async () => { + it("deletes tab and selects right by d", async () => { await browser.tabs.update(tabs[3].id, { active: true }); const page = await Page.currentContext(webdriver); - await page.sendKeys('d'); + await page.sendKeys("d"); - await eventually(async() => { + await eventually(async () => { const current = await browser.tabs.query({ windowId: win.id }); assert.strictEqual(current.length, tabs.length - 1); assert.strictEqual(current[3].active, true); @@ -59,34 +61,34 @@ describe("tab test", () => { }); }); - it('deletes tab and selects left by D', async () => { + it("deletes tab and selects left by D", async () => { await browser.tabs.update(tabs[3].id, { active: true }); const page = await Page.currentContext(webdriver); - await page.sendKeys(Key.SHIFT, 'D'); + await page.sendKeys(Key.SHIFT, "D"); - await eventually(async() => { + await eventually(async () => { const current = await browser.tabs.query({ windowId: win.id }); assert.strictEqual(current.length, tabs.length - 1); assert.strictEqual(current[2].active, true); assert.strictEqual(current[2].id, tabs[2].id); - }) + }); }); - it('deletes all tabs to the right by x$', async () => { + it("deletes all tabs to the right by x$", async () => { await browser.tabs.update(tabs[1].id, { active: true }); const page = await Page.currentContext(webdriver); - await page.sendKeys('x', '$'); + await page.sendKeys("x", "$"); const current = await browser.tabs.query({ windowId: win.id }); assert.strictEqual(current.length, 2); }); - it('duplicates tab by zd', async () => { + it("duplicates tab by zd", async () => { await browser.tabs.update(tabs[0].id, { active: true }); const page = await Page.currentContext(webdriver); - await page.sendKeys('z', 'd'); + await page.sendKeys("z", "d"); - await eventually(async() => { + await eventually(async () => { const current = await browser.tabs.query({ windowId: win.id }); current.sort((t1: any, t2: any) => t1.index - t2.index); assert.strictEqual(current.length, tabs.length + 1); @@ -94,118 +96,121 @@ describe("tab test", () => { }); }); - it('makes pinned by zp', async () => { + it("makes pinned by zp", async () => { await browser.tabs.update(tabs[0].id, { active: true }); const page = await Page.currentContext(webdriver); - await page.sendKeys('z', 'p'); + await page.sendKeys("z", "p"); const current = await browser.tabs.query({ windowId: win.id }); assert.strictEqual(current[0].pinned, true); }); - it('selects previous tab by K', async () => { + it("selects previous tab by K", async () => { await browser.tabs.update(tabs[2].id, { active: true }); const page = await Page.currentContext(webdriver); - await page.sendKeys(Key.SHIFT, 'K'); + await page.sendKeys(Key.SHIFT, "K"); const current = await browser.tabs.query({ windowId: win.id }); assert.strictEqual(current[1].active, true); }); - it('selects previous tab by K rotatory', async () => { + it("selects previous tab by K rotatory", async () => { await browser.tabs.update(tabs[0].id, { active: true }); const page = await Page.currentContext(webdriver); - await page.sendKeys(Key.SHIFT, 'K'); + await page.sendKeys(Key.SHIFT, "K"); const current = await browser.tabs.query({ windowId: win.id }); - assert.strictEqual(current[current.length - 1].active, true) + assert.strictEqual(current[current.length - 1].active, true); }); - it('selects next tab by J', async () => { + it("selects next tab by J", async () => { await browser.tabs.update(tabs[2].id, { active: true }); const page = await Page.currentContext(webdriver); - await page.sendKeys(Key.SHIFT, 'J'); + await page.sendKeys(Key.SHIFT, "J"); const current = await browser.tabs.query({ windowId: win.id }); assert.strictEqual(current[3].active, true); }); - it('selects previous tab by J rotatory', async () => { + it("selects previous tab by J rotatory", async () => { await browser.tabs.update(tabs[tabs.length - 1].id, { active: true }); const page = await Page.currentContext(webdriver); - await page.sendKeys(Key.SHIFT, 'J'); + await page.sendKeys(Key.SHIFT, "J"); const current = await browser.tabs.query({ windowId: win.id }); - assert.strictEqual(current[0].active, true) + assert.strictEqual(current[0].active, true); }); - it('selects first tab by g0', async () => { + it("selects first tab by g0", async () => { await browser.tabs.update(tabs[2].id, { active: true }); const page = await Page.currentContext(webdriver); - await page.sendKeys('g', '0'); + await page.sendKeys("g", "0"); const current = await browser.tabs.query({ windowId: win.id }); - assert.strictEqual(current[0].active, true) + assert.strictEqual(current[0].active, true); }); - it('selects last tab by g$', async () => { + it("selects last tab by g$", async () => { await browser.tabs.update(tabs[2].id, { active: true }); const page = await Page.currentContext(webdriver); - await page.sendKeys('g', '$'); + await page.sendKeys("g", "$"); const current = await browser.tabs.query({ windowId: win.id }); - assert.strictEqual(current[current.length - 1].active, true) + assert.strictEqual(current[current.length - 1].active, true); }); - it('selects last selected tab by <C-6>', async () => { + it("selects last selected tab by <C-6>", async () => { await browser.tabs.update(tabs[1].id, { active: true }); await browser.tabs.update(tabs[4].id, { active: true }); const page = await Page.currentContext(webdriver); - await page.sendKeys(Key.CONTROL, '6'); + await page.sendKeys(Key.CONTROL, "6"); const current = await browser.tabs.query({ windowId: win.id }); - assert.strictEqual(current[1].active, true) + assert.strictEqual(current[1].active, true); }); // browser.sessions.getRecentlyClosed() sometime throws "An unexpected error occurred" // This might be a bug in Firefox. - it.skip('reopen tab by u', async () => { + it.skip("reopen tab by u", async () => { await browser.tabs.remove(tabs[1].id); const page = await Page.currentContext(webdriver); - await page.sendKeys('u'); + await page.sendKeys("u"); const current = await browser.tabs.query({ windowId: win.id }); assert.strictEqual(current.length, tabs.length); }); - it('does not delete pinned tab by d', async () => { + it("does not delete pinned tab by d", async () => { await browser.tabs.update(tabs[0].id, { active: true, pinned: true }); const page = await Page.currentContext(webdriver); - await page.sendKeys('d'); + await page.sendKeys("d"); const current = await browser.tabs.query({ windowId: win.id }); assert.strictEqual(current.length, tabs.length); }); - it('deletes pinned tab by !d', async () => { + it("deletes pinned tab by !d", async () => { await browser.tabs.update(tabs[0].id, { active: true, pinned: true }); const page = await Page.currentContext(webdriver); - await page.sendKeys('!', 'd'); + await page.sendKeys("!", "d"); const current = await browser.tabs.query({ windowId: win.id }); assert.strictEqual(current.length, tabs.length - 1); }); - it('opens view-source by gf', async () => { + it("opens view-source by gf", async () => { await browser.tabs.update(tabs[0].id, { active: true }); const page = await Page.currentContext(webdriver); - await page.sendKeys('g', 'f'); + await page.sendKeys("g", "f"); - await eventually(async() => { + await eventually(async () => { const current = await browser.tabs.query({ windowId: win.id }); assert.strictEqual(current.length, tabs.length + 1); - assert.strictEqual(current[current.length - 1].url, `view-source:${server.url('/#0')}`); + assert.strictEqual( + current[current.length - 1].url, + `view-source:${server.url("/#0")}` + ); }); }); }); diff --git a/e2e/zoom.test.ts b/e2e/zoom.test.ts index d089097..5e21774 100644 --- a/e2e/zoom.test.ts +++ b/e2e/zoom.test.ts @@ -1,10 +1,10 @@ -import * as path from 'path'; -import * as assert from 'assert'; +import * as path from "path"; +import * as assert from "assert"; -import eventually from './eventually'; -import { Builder, Lanthan } from 'lanthan'; -import { WebDriver } from 'selenium-webdriver'; -import Page from './lib/Page'; +import eventually from "./eventually"; +import { Builder, Lanthan } from "lanthan"; +import { WebDriver } from "selenium-webdriver"; +import Page from "./lib/Page"; describe("zoom test", () => { let lanthan: Lanthan; @@ -13,10 +13,9 @@ describe("zoom test", () => { let tab: any; let page: Page; - before(async() => { - lanthan = await Builder - .forBrowser('firefox') - .spyAddon(path.join(__dirname, '..')) + before(async () => { + lanthan = await Builder.forBrowser("firefox") + .spyAddon(path.join(__dirname, "..")) .build(); webdriver = lanthan.getWebDriver(); browser = lanthan.getWebExtBrowser(); @@ -24,42 +23,41 @@ describe("zoom test", () => { page = await Page.currentContext(webdriver); }); - after(async() => { + after(async () => { await lanthan.quit(); }); - beforeEach(async() => { - await webdriver.navigate().to('about:blank'); + beforeEach(async () => { + await webdriver.navigate().to("about:blank"); }); - it('should zoom in by zi', async () => { + it("should zoom in by zi", async () => { const before = await browser.tabs.getZoom(tab.id); - await page.sendKeys('zi'); + await page.sendKeys("zi"); - await eventually(async() => { + await eventually(async () => { const actual = await browser.tabs.getZoom(tab.id); assert.ok(before < actual); }); }); - it('should zoom out by zo', async () => { + it("should zoom out by zo", async () => { const before = await browser.tabs.getZoom(tab.id); - await page.sendKeys('zo'); + await page.sendKeys("zo"); - await eventually(async() => { + await eventually(async () => { const actual = await browser.tabs.getZoom(tab.id); assert.ok(before > actual); }); }); - it('should reset zoom by zz', async () => { + it("should reset zoom by zz", async () => { await browser.tabs.setZoom(tab.id, 2); - await page.sendKeys('zz'); + await page.sendKeys("zz"); - await eventually(async() => { + await eventually(async () => { const actual = await browser.tabs.getZoom(tab.id); assert.strictEqual(actual, 1); }); }); }); - |