diff options
author | Shin'ya Ueoka <ueokande@i-beam.org> | 2019-09-22 16:13:12 +0900 |
---|---|---|
committer | Shin'ya Ueoka <ueokande@i-beam.org> | 2019-09-22 16:13:12 +0900 |
commit | 7e77e31ad64c3649888eae337e0c984fd9c2ea2a (patch) | |
tree | 4d3e630f82712abce5afd7e498d514253464a6ea /e2e | |
parent | 91f8383ecc2f7ef3f95173ad973a74f79e277a6c (diff) |
Migrate e2e tests to TypeScript
Diffstat (limited to 'e2e')
-rw-r--r-- | e2e/blacklist.test.ts (renamed from e2e/blacklist.test.js) | 24 | ||||
-rw-r--r-- | e2e/clipboard.test.ts (renamed from e2e/clipboard.test.js) | 32 | ||||
-rw-r--r-- | e2e/command_addbookmark.test.ts (renamed from e2e/command_addbookmark.test.js) | 24 | ||||
-rw-r--r-- | e2e/command_bdelete.test.ts (renamed from e2e/command_bdelete.test.js) | 30 | ||||
-rw-r--r-- | e2e/command_buffer.test.ts (renamed from e2e/command_buffer.test.js) | 24 | ||||
-rw-r--r-- | e2e/command_open.test.ts (renamed from e2e/command_open.test.js) | 30 | ||||
-rw-r--r-- | e2e/command_quit.test.ts (renamed from e2e/command_quit.test.js) | 23 | ||||
-rw-r--r-- | e2e/command_tabopen.test.ts (renamed from e2e/command_tabopen.test.js) | 31 | ||||
-rw-r--r-- | e2e/command_winopen.test.ts (renamed from e2e/command_winopen.test.js) | 30 | ||||
-rw-r--r-- | e2e/completion.test.ts (renamed from e2e/completion.test.js) | 48 | ||||
-rw-r--r-- | e2e/completion_buffers.test.ts (renamed from e2e/completion_buffers.test.js) | 86 | ||||
-rw-r--r-- | e2e/completion_open.test.ts (renamed from e2e/completion_open.test.js) | 57 | ||||
-rw-r--r-- | e2e/completion_set.test.ts (renamed from e2e/completion_set.test.js) | 36 | ||||
-rw-r--r-- | e2e/console.test.ts (renamed from e2e/console.test.js) | 42 | ||||
-rw-r--r-- | e2e/eventually.js | 23 | ||||
-rw-r--r-- | e2e/eventually.ts | 30 | ||||
-rw-r--r-- | e2e/follow.test.ts (renamed from e2e/follow.test.js) | 46 | ||||
-rw-r--r-- | e2e/follow_properties.test.ts (renamed from e2e/follow_properties.test.js) | 38 | ||||
-rw-r--r-- | e2e/lib/Console.ts (renamed from e2e/lib/Console.js) | 30 | ||||
-rw-r--r-- | e2e/lib/clipboard.ts (renamed from e2e/lib/clipboard.js) | 53 | ||||
-rw-r--r-- | e2e/mark.test.ts (renamed from e2e/mark.test.js) | 30 | ||||
-rw-r--r-- | e2e/navigate.test.ts (renamed from e2e/navigate.test.js) | 44 | ||||
-rw-r--r-- | e2e/options.test.ts (renamed from e2e/options.test.js) | 27 | ||||
-rw-r--r-- | e2e/options_form.test.ts (renamed from e2e/options_form.test.js) | 20 | ||||
-rw-r--r-- | e2e/repeat.test.ts (renamed from e2e/repeat.test.js) | 29 | ||||
-rw-r--r-- | e2e/scroll.test.ts (renamed from e2e/scroll.test.js) | 69 | ||||
-rw-r--r-- | e2e/settings.ts (renamed from e2e/settings.js) | 4 | ||||
-rw-r--r-- | e2e/tab.test.ts (renamed from e2e/tab.test.js) | 78 | ||||
-rw-r--r-- | e2e/zoom.test.ts (renamed from e2e/zoom.test.js) | 29 |
29 files changed, 552 insertions, 515 deletions
diff --git a/e2e/blacklist.test.js b/e2e/blacklist.test.ts index 8a8996e..c88f655 100644 --- a/e2e/blacklist.test.js +++ b/e2e/blacklist.test.ts @@ -1,13 +1,13 @@ -const express = require('express'); -const path = require('path'); -const assert = require('assert'); -const settings = require('./settings'); -const { Builder } = require('lanthan'); -const { By } = require('selenium-webdriver'); +import express from 'express'; +import * as path from 'path'; +import * as assert from 'assert'; +import { Builder, Lanthan } from 'lanthan'; +import { WebDriver, By } from 'selenium-webdriver'; +import * as http from 'http'; const newApp = () => { let app = express(); - app.get('/*', (req, res) => { + app.get('/*', (_req, res) => { res.status(200).send(`<!DOCTYPEhtml> <html lang="en"> <body style="width:10000px; height:10000px"></body> @@ -17,12 +17,11 @@ const newApp = () => { }; describe("navigate test", () => { - const port = 12321; - let http; - let lanthan; - let webdriver; - let browser; + let http: http.Server; + let lanthan: Lanthan; + let webdriver: WebDriver; + let browser: any; before(async() => { http = newApp().listen(port); @@ -73,4 +72,3 @@ describe("navigate test", () => { assert.equal(pageYOffset, 64); }); }); - diff --git a/e2e/clipboard.test.js b/e2e/clipboard.test.ts index df31770..dbc00de 100644 --- a/e2e/clipboard.test.js +++ b/e2e/clipboard.test.ts @@ -1,15 +1,17 @@ -const express = require('express'); -const path = require('path'); -const assert = require('assert'); -const eventually = require('./eventually'); -const clipboard = require('./lib/clipboard'); -const settings = require('./settings'); -const { Builder } = require('lanthan'); -const { By, Key } = require('selenium-webdriver'); +import express from 'express'; +import * as path from 'path'; +import * as assert from 'assert'; +import * as http from 'http'; + +import eventually from './eventually'; +import * as clipboard from './lib/clipboard'; +import settings from './settings'; +import { Builder, Lanthan } from 'lanthan'; +import { WebDriver, By, Key } from 'selenium-webdriver'; const newApp = () => { let app = express(); - app.get('/', (req, res) => { + app.get('/', (_req, res) => { res.status(200).send(`<html lang="en"></html">`); }); return app; @@ -18,10 +20,10 @@ const newApp = () => { describe("navigate test", () => { const port = 12321; - let http; - let lanthan; - let webdriver; - let browser; + let http: http.Server; + let lanthan: Lanthan; + let webdriver: WebDriver; + let browser: any; before(async() => { http = newApp().listen(port); @@ -85,7 +87,7 @@ describe("navigate test", () => { await eventually(async() => { let tabs = await browser.tabs.query({}); - assert.deepEqual(tabs.map(t => t.url), [ + assert.deepEqual(tabs.map((t: any) => t.url), [ `http://127.0.0.1:${port}/`, `http://127.0.0.1:${port}/#open_to_new_tab`, ]); @@ -114,7 +116,7 @@ describe("navigate test", () => { await eventually(async() => { let tabs = await browser.tabs.query({}); - assert.deepEqual(tabs.map(t => t.url), [ + assert.deepEqual(tabs.map((t: any) => t.url), [ `http://127.0.0.1:${port}/`, `http://127.0.0.1:${port}/google?q=an%20apple`, ]); diff --git a/e2e/command_addbookmark.test.js b/e2e/command_addbookmark.test.ts index 68d1c6d..ad94494 100644 --- a/e2e/command_addbookmark.test.js +++ b/e2e/command_addbookmark.test.ts @@ -1,13 +1,15 @@ -const express = require('express'); -const path = require('path'); -const assert = require('assert'); -const eventually = require('./eventually'); -const { Builder } = require('lanthan'); -const { By, Key } = require('selenium-webdriver'); +import express from 'express'; +import * as path from 'path'; +import * as assert from 'assert'; +import * as http from 'http'; + +import eventually from './eventually'; +import { Builder, Lanthan } from 'lanthan'; +import { WebDriver, By, Key } from 'selenium-webdriver'; const newApp = () => { let app = express(); - app.get('/happy', (req, res) => { + app.get('/happy', (_req, res) => { res.send(`<!DOCTYPEhtml> <html lang="en"> <head> @@ -20,10 +22,10 @@ const newApp = () => { describe('addbookmark command test', () => { const port = 12321; - let http; - let lanthan; - let webdriver; - let browser; + let http: http.Server; + let lanthan: Lanthan; + let webdriver: WebDriver; + let browser: any; before(async() => { http = newApp().listen(port); diff --git a/e2e/command_bdelete.test.js b/e2e/command_bdelete.test.ts index aae5b67..ce54b23 100644 --- a/e2e/command_bdelete.test.js +++ b/e2e/command_bdelete.test.ts @@ -1,9 +1,11 @@ -const express = require('express'); -const path = require('path'); -const assert = require('assert'); -const eventually = require('./eventually'); -const { Builder } = require('lanthan'); -const { By, Key } = require('selenium-webdriver'); +import express from 'express'; +import * as path from 'path'; +import * as assert from 'assert'; +import * as http from 'http'; + +import eventually from './eventually'; +import { Builder, Lanthan } from 'lanthan'; +import { WebDriver, By, Key } from 'selenium-webdriver'; const newApp = () => { let app = express(); @@ -21,10 +23,10 @@ const newApp = () => { describe('bdelete/bdeletes command test', () => { const port = 12321; - let http; - let lanthan; - let webdriver; - let browser; + let http: http.Server; + let lanthan: Lanthan; + let webdriver: WebDriver; + let browser: any; before(async() => { http = newApp().listen(port); @@ -74,7 +76,7 @@ describe('bdelete/bdeletes command test', () => { await eventually(async() => { let tabs = await browser.tabs.query({}); - assert.deepEqual(tabs.map(t => t.url), [ + assert.deepEqual(tabs.map((t: any) => t.url), [ `http://127.0.0.1:${port}/site1`, `http://127.0.0.1:${port}/site2`, `http://127.0.0.1:${port}/site3`, @@ -137,7 +139,7 @@ describe('bdelete/bdeletes command test', () => { await eventually(async() => { let tabs = await browser.tabs.query({}); - assert.deepEqual(tabs.map(t => t.url), [ + assert.deepEqual(tabs.map((t: any) => t.url), [ `http://127.0.0.1:${port}/site1`, `http://127.0.0.1:${port}/site2`, `http://127.0.0.1:${port}/site3`, @@ -156,7 +158,7 @@ describe('bdelete/bdeletes command test', () => { await eventually(async() => { let tabs = await browser.tabs.query({}); - assert.deepEqual(tabs.map(t => t.url), [ + assert.deepEqual(tabs.map((t: any) => t.url), [ `http://127.0.0.1:${port}/site2`, `http://127.0.0.1:${port}/site3`, `http://127.0.0.1:${port}/site4`, @@ -175,7 +177,7 @@ describe('bdelete/bdeletes command test', () => { await eventually(async() => { let tabs = await browser.tabs.query({}); - assert.deepEqual(tabs.map(t => t.url), [ + assert.deepEqual(tabs.map((t: any) => t.url), [ `http://127.0.0.1:${port}/site1`, `http://127.0.0.1:${port}/site2`, `http://127.0.0.1:${port}/site3`, diff --git a/e2e/command_buffer.test.js b/e2e/command_buffer.test.ts index b3336dc..e642673 100644 --- a/e2e/command_buffer.test.js +++ b/e2e/command_buffer.test.ts @@ -1,9 +1,11 @@ -const express = require('express'); -const path = require('path'); -const assert = require('assert'); -const eventually = require('./eventually'); -const { Builder } = require('lanthan'); -const { By, Key } = require('selenium-webdriver'); +import express from 'express'; +import * as path from 'path'; +import * as assert from 'assert'; +import * as http from 'http'; + +import eventually from './eventually'; +import { Builder, Lanthan } from 'lanthan'; +import { WebDriver, By, Key } from 'selenium-webdriver'; const newApp = () => { let app = express(); @@ -21,10 +23,10 @@ const newApp = () => { describe('buffer command test', () => { const port = 12321; - let http; - let lanthan; - let webdriver; - let browser; + let http: http.Server; + let lanthan: Lanthan; + let webdriver: WebDriver; + let browser: any; before(async() => { http = newApp().listen(port); @@ -105,7 +107,7 @@ describe('buffer command test', () => { assert.equal(text, 'tab 0 does not exist'); }); - await webdriver.switchTo().parentFrame(); + await (webdriver.switchTo() as any).parentFrame(); body = await webdriver.findElement(By.css('body')); await body.sendKeys(':'); diff --git a/e2e/command_open.test.js b/e2e/command_open.test.ts index ccf7393..cfaee15 100644 --- a/e2e/command_open.test.js +++ b/e2e/command_open.test.ts @@ -1,23 +1,25 @@ -const express = require('express'); -const path = require('path'); -const assert = require('assert'); -const eventually = require('./eventually'); -const settings = require('./settings'); -const { Builder } = require('lanthan'); -const { By, Key } = require('selenium-webdriver'); +import express from 'express'; +import * as path from 'path'; +import * as assert from 'assert'; +import * as http from 'http'; + +import settings from './settings'; +import eventually from './eventually'; +import { Builder, Lanthan } from 'lanthan'; +import { WebDriver, WebElement, By, Key } from 'selenium-webdriver'; const newApp = () => { let app = express(); for (let name of ['google', 'yahoo', 'bing', 'duckduckgo', 'twitter', 'wikipedia']) { - app.get('/' + name, (req, res) => { + app.get('/' + name, (_req, res) => { res.send(`<!DOCTYPEhtml> <html lang="en"> <body><h1>${name.charAt(0).toUpperCase() + name.slice(1)}</h1></body> </html">`); }); } - app.get('/', (req, res) => { + app.get('/', (_req, res) => { res.send(`<!DOCTYPEhtml> <html lang="en"> <body><h1>home</h1></body> @@ -28,11 +30,11 @@ const newApp = () => { describe("open command test", () => { const port = 12321; - let http; - let lanthan; - let webdriver; - let browser; - let body; + let http: http.Server; + let lanthan: Lanthan; + let webdriver: WebDriver; + let browser: any; + let body: WebElement; before(async() => { lanthan = await Builder diff --git a/e2e/command_quit.test.js b/e2e/command_quit.test.ts index 07e770a..29b947a 100644 --- a/e2e/command_quit.test.js +++ b/e2e/command_quit.test.ts @@ -1,9 +1,12 @@ -const express = require('express'); -const path = require('path'); -const assert = require('assert'); -const eventually = require('./eventually'); -const { Builder } = require('lanthan'); -const { By, Key } = require('selenium-webdriver'); +import express from 'express'; +import * as path from 'path'; +import * as assert from 'assert'; +import * as http from 'http'; + +import eventually from './eventually'; +import { Builder, Lanthan } from 'lanthan'; +import { WebDriver, By, Key } from 'selenium-webdriver'; + const newApp = () => { let app = express(); @@ -21,10 +24,10 @@ const newApp = () => { describe('quit/quitall command test', () => { const port = 12321; - let http; - let lanthan; - let webdriver; - let browser; + let http: http.Server; + let lanthan: Lanthan; + let webdriver: WebDriver; + let browser: any; before(async() => { http = newApp().listen(port); diff --git a/e2e/command_tabopen.test.js b/e2e/command_tabopen.test.ts index 78f5d7f..ca4ad92 100644 --- a/e2e/command_tabopen.test.js +++ b/e2e/command_tabopen.test.ts @@ -1,23 +1,26 @@ -const express = require('express'); -const path = require('path'); -const assert = require('assert'); -const eventually = require('./eventually'); -const settings = require('./settings'); -const { Builder } = require('lanthan'); -const { By, Key } = require('selenium-webdriver'); +import express from 'express'; +import * as path from 'path'; +import * as assert from 'assert'; +import * as http from 'http'; + +import settings from './settings'; +import eventually from './eventually'; +import { Builder, Lanthan } from 'lanthan'; +import { WebDriver, WebElement, By, Key } from 'selenium-webdriver'; + const newApp = () => { let app = express(); for (let name of ['google', 'yahoo', 'bing', 'duckduckgo', 'twitter', 'wikipedia']) { - app.get('/' + name, (req, res) => { + app.get('/' + name, (_req, res) => { res.send(`<!DOCTYPEhtml> <html lang="en"> <body><h1>${name.charAt(0).toUpperCase() + name.slice(1)}</h1></body> </html">`); }); } - app.get('/', (req, res) => { + app.get('/', (_req, res) => { res.send(`<!DOCTYPEhtml> <html lang="en"> <body><h1>home</h1></body> @@ -28,11 +31,11 @@ const newApp = () => { describe("tabopen command test", () => { const port = 12321; - let http; - let lanthan; - let webdriver; - let browser; - let body; + let http: http.Server; + let lanthan: Lanthan; + let webdriver: WebDriver; + let browser: any; + let body: WebElement; before(async() => { http = newApp().listen(port); diff --git a/e2e/command_winopen.test.js b/e2e/command_winopen.test.ts index 149d775..cdd4c1c 100644 --- a/e2e/command_winopen.test.js +++ b/e2e/command_winopen.test.ts @@ -1,23 +1,25 @@ -const express = require('express'); -const path = require('path'); -const assert = require('assert'); -const eventually = require('./eventually'); -const settings = require('./settings'); -const { Builder } = require('lanthan'); -const { By, Key } = require('selenium-webdriver'); +import express from 'express'; +import * as path from 'path'; +import * as assert from 'assert'; +import * as http from 'http'; + +import settings from './settings'; +import eventually from './eventually'; +import { Builder, Lanthan } from 'lanthan'; +import { WebDriver, WebElement, By, Key } from 'selenium-webdriver'; const newApp = () => { let app = express(); for (let name of ['google', 'yahoo', 'bing', 'duckduckgo', 'twitter', 'wikipedia']) { - app.get('/' + name, (req, res) => { + app.get('/' + name, (_req, res) => { res.send(`<!DOCTYPEhtml> <html lang="en"> <body><h1>${name.charAt(0).toUpperCase() + name.slice(1)}</h1></body> </html">`); }); } - app.get('/', (req, res) => { + app.get('/', (_req, res) => { res.send(`<!DOCTYPEhtml> <html lang="en"> <body><h1>home</h1></body> @@ -28,11 +30,11 @@ const newApp = () => { describe("winopen command test", () => { const port = 12321; - let http; - let lanthan; - let webdriver; - let browser; - let body; + let http: http.Server; + let lanthan: Lanthan; + let webdriver: WebDriver; + let browser: any; + let body: WebElement; before(async() => { http = newApp().listen(port); diff --git a/e2e/completion.test.js b/e2e/completion.test.ts index fc87df0..fd58f74 100644 --- a/e2e/completion.test.js +++ b/e2e/completion.test.ts @@ -1,15 +1,17 @@ -const express = require('express'); -const path = require('path'); -const assert = require('assert'); -const eventually = require('./eventually'); -const settings = require('./settings'); -const { Builder } = require('lanthan'); -const { By, Key } = require('selenium-webdriver'); -const Console = require('./lib/Console'); +import express from 'express'; +import * as path from 'path'; +import * as assert from 'assert'; +import * as http from 'http'; + +import settings from './settings'; +import eventually from './eventually'; +import { Builder, Lanthan } from 'lanthan'; +import { WebDriver, WebElement, By, Key } from 'selenium-webdriver'; +import { Console } from './lib/Console'; const newApp = () => { let app = express(); - app.get('/', (req, res) => { + app.get('/', (_req, res) => { res.send(`<!DOCTYPEhtml> <html lang="en"> <body>ok</body> @@ -20,11 +22,11 @@ const newApp = () => { describe("general completion test", () => { const port = 12321; - let http; - let lanthan; - let webdriver; - let browser; - let body; + let http: http.Server; + let lanthan: Lanthan; + let webdriver: WebDriver; + let browser: any; + let body: WebElement; before(async() => { lanthan = await Builder @@ -62,9 +64,9 @@ describe("general completion test", () => { let items = await c.getCompletions(); assert.equal(items.length, 10); assert.deepEqual(items[0], { type: 'title', text: 'Console Command' }); - assert(items[1].text.startsWith('set')) - assert(items[2].text.startsWith('open')) - assert(items[3].text.startsWith('tabopen')) + assert.ok(items[1].text.startsWith('set')) + assert.ok(items[2].text.startsWith('open')) + assert.ok(items[3].text.startsWith('tabopen')) }); }); @@ -79,9 +81,9 @@ describe("general completion test", () => { let items = await c.getCompletions(); assert.equal(items.length, 4); assert.deepEqual(items[0], { type: 'title', text: 'Console Command' }); - assert(items[1].text.startsWith('buffer')) - assert(items[2].text.startsWith('bdelete')) - assert(items[3].text.startsWith('bdeletes')) + assert.ok(items[1].text.startsWith('buffer')) + assert.ok(items[2].text.startsWith('bdelete')) + assert.ok(items[3].text.startsWith('bdeletes')) }); }); @@ -100,7 +102,7 @@ describe("general completion test", () => { await c.sendKeys(Key.TAB); await eventually(async() => { let items = await c.getCompletions(); - assert(items[1].highlight) + assert.ok(items[1].highlight) let v = await c.currentValue(); assert.equal(v, 'buffer'); @@ -109,7 +111,7 @@ describe("general completion test", () => { await c.sendKeys(Key.TAB, Key.TAB); await eventually(async() => { let items = await c.getCompletions(); - assert(items[3].highlight) + assert.ok(items[3].highlight) let v = await c.currentValue(); assert.equal(v, 'bdeletes'); @@ -124,7 +126,7 @@ describe("general completion test", () => { await c.sendKeys(Key.SHIFT, Key.TAB); await eventually(async() => { let items = await c.getCompletions(); - assert(items[3].highlight) + assert.ok(items[3].highlight) let v = await c.currentValue(); assert.equal(v, 'bdeletes'); diff --git a/e2e/completion_buffers.test.js b/e2e/completion_buffers.test.ts index 87d2397..9c212cc 100644 --- a/e2e/completion_buffers.test.js +++ b/e2e/completion_buffers.test.ts @@ -1,11 +1,13 @@ -const express = require('express'); -const path = require('path'); -const assert = require('assert'); -const eventually = require('./eventually'); -const settings = require('./settings'); -const Console = require('./lib/Console'); -const { Builder } = require('lanthan'); -const { By, Key } = require('selenium-webdriver'); +import express from 'express'; +import * as path from 'path'; +import * as assert from 'assert'; +import * as http from 'http'; + +import settings from './settings'; +import eventually from './eventually'; +import { Builder, Lanthan } from 'lanthan'; +import { WebDriver, WebElement, By } from 'selenium-webdriver'; +import { Console } from './lib/Console'; const newApp = () => { @@ -24,11 +26,11 @@ const newApp = () => { describe("completion on buffer/bdelete/bdeletes", () => { const port = 12321; - let http; - let lanthan; - let webdriver; - let browser; - let body; + let http: http.Server; + let lanthan: Lanthan; + let webdriver: WebDriver; + let browser: any; + let body: WebElement; before(async() => { lanthan = await Builder @@ -85,14 +87,14 @@ describe("completion on buffer/bdelete/bdeletes", () => { let items = await c.getCompletions(); assert.equal(items.length, 6); assert.deepEqual(items[0], { type: 'title', text: 'Buffers' }); - assert(items[1].text.startsWith('1:')); - assert(items[2].text.startsWith('2:')); - assert(items[3].text.startsWith('3:')); - assert(items[4].text.startsWith('4:')); - assert(items[5].text.startsWith('5:')); - - assert(items[3].text.includes('%')); - assert(items[5].text.includes('#')); + 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('#')); }); }) @@ -106,9 +108,9 @@ describe("completion on buffer/bdelete/bdeletes", () => { await eventually(async() => { let items = await c.getCompletions(); assert.deepEqual(items[0], { type: 'title', text: 'Buffers' }); - assert(items[1].text.startsWith('2:')); - assert(items[1].text.includes('title_site2')); - assert(items[1].text.includes(`http://127.0.0.1:${port}/site2`)); + assert.ok(items[1].text.startsWith('2:')); + assert.ok(items[1].text.includes('title_site2')); + assert.ok(items[1].text.includes(`http://127.0.0.1:${port}/site2`)); }); }) @@ -122,7 +124,7 @@ describe("completion on buffer/bdelete/bdeletes", () => { await eventually(async() => { let items = await c.getCompletions(); assert.deepEqual(items[0], { type: 'title', text: 'Buffers' }); - assert(items[1].text.startsWith('2:')); + assert.ok(items[1].text.startsWith('2:')); }); }) @@ -137,7 +139,7 @@ describe("completion on buffer/bdelete/bdeletes", () => { let items = await c.getCompletions(); assert.equal(items.length, 2); assert.deepEqual(items[0], { type: 'title', text: 'Buffers' }); - assert(items[1].text.startsWith('2:')); + assert.ok(items[1].text.startsWith('2:')); }); }) @@ -151,9 +153,9 @@ describe("completion on buffer/bdelete/bdeletes", () => { await eventually(async() => { let items = await c.getCompletions(); assert.equal(items.length, 4); - assert(items[1].text.includes('site3')); - assert(items[2].text.includes('site4')); - assert(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')); }); }) @@ -167,9 +169,9 @@ describe("completion on buffer/bdelete/bdeletes", () => { await eventually(async() => { let items = await c.getCompletions(); assert.equal(items.length, 4); - assert(items[1].text.includes('site3')); - assert(items[2].text.includes('site4')); - assert(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')); }); }) @@ -183,11 +185,11 @@ describe("completion on buffer/bdelete/bdeletes", () => { await eventually(async() => { let items = await c.getCompletions(); assert.equal(items.length, 6); - assert(items[1].text.includes('site1')); - assert(items[2].text.includes('site2')); - assert(items[3].text.includes('site3')); - assert(items[4].text.includes('site4')); - assert(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')); }); }) @@ -201,11 +203,11 @@ describe("completion on buffer/bdelete/bdeletes", () => { await eventually(async() => { let items = await c.getCompletions(); assert.equal(items.length, 6); - assert(items[1].text.includes('site1')); - assert(items[2].text.includes('site2')); - assert(items[3].text.includes('site3')); - assert(items[4].text.includes('site4')); - assert(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.js b/e2e/completion_open.test.ts index b2b7484..dcd1829 100644 --- a/e2e/completion_open.test.js +++ b/e2e/completion_open.test.ts @@ -1,17 +1,18 @@ -const express = require('express'); -const lanthan = require('lanthan'); -const path = require('path'); -const assert = require('assert'); -const eventually = require('./eventually'); -const settings = require('./settings'); -const { Builder } = require('lanthan'); -const { By, Key } = require('selenium-webdriver'); -const Console = require('./lib/Console'); +import express from 'express'; +import * as path from 'path'; +import * as assert from 'assert'; +import * as http from 'http'; + +import settings from './settings'; +import eventually from './eventually'; +import { Builder, Lanthan } from 'lanthan'; +import { WebDriver, WebElement, By, Key } from 'selenium-webdriver'; +import { Console } from './lib/Console'; const newApp = () => { let app = express(); - app.get('/', (req, res) => { + app.get('/', (_req, res) => { res.send(`<!DOCTYPEhtml> <html lang="en"> <body>ok</body> @@ -22,11 +23,11 @@ const newApp = () => { describe("completion on open/tabopen/winopen commands", () => { const port = 12321; - let http; - let lanthan; - let webdriver; - let browser; - let body; + let http: http.Server; + let lanthan: Lanthan; + let webdriver: WebDriver; + let browser: any; + let body: WebElement; before(async() => { lanthan = await Builder @@ -66,9 +67,9 @@ describe("completion on open/tabopen/winopen commands", () => { await eventually(async() => { let completions = await c.getCompletions(); - assert(completions.find(x => x.type === 'title' && x.text === 'Search Engines')); - assert(completions.find(x => x.type === 'title' && x.text === 'Bookmarks')); - assert(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')); }); }); @@ -82,7 +83,7 @@ describe("completion on open/tabopen/winopen commands", () => { await eventually(async() => { let completions = await c.getCompletions(); let items = completions.filter(x => x.type === 'item').map(x => x.text); - assert(items.every(x => x.includes('https://'))); + assert.ok(items.every(x => x.includes('https://'))); }); }) @@ -96,7 +97,7 @@ describe("completion on open/tabopen/winopen commands", () => { await eventually(async() => { let completions = await c.getCompletions(); let items = completions.filter(x => x.type === 'item').map(x => x.text); - assert(items.every(x => x.toLowerCase().includes('getting'))); + assert.ok(items.every(x => x.toLowerCase().includes('getting'))); }); }) @@ -110,7 +111,7 @@ describe("completion on open/tabopen/winopen commands", () => { await eventually(async() => { let completions = await c.getCompletions(); let items = completions.filter(x => x.type === 'item').map(x => x.text); - assert(items.every(x => x.includes('https://'))); + assert.ok(items.every(x => x.includes('https://'))); }); }) @@ -124,22 +125,22 @@ describe("completion on open/tabopen/winopen commands", () => { await eventually(async() => { let completions = await c.getCompletions(); let items = completions.filter(x => x.type === 'item').map(x => x.text); - assert(items.every(x => x.includes('https://'))); + assert.ok(items.every(x => x.includes('https://'))); }); }) it('should display only specified items in "complete" property by set command', async() => { let c = new Console(webdriver); - const execCommand = async(line) => { + const execCommand = async(line: string) => { await body.sendKeys(':'); await webdriver.switchTo().frame(0); await c.sendKeys(line, Key.ENTER); await new Promise(resolve => setTimeout(resolve, 100)); - await webdriver.switchTo().parentFrame(); + await (webdriver.switchTo() as any).parentFrame(); } - const typeCommand = async(...keys) => { + const typeCommand = async(...keys: string[]) => { await body.sendKeys(':'); await webdriver.switchTo().frame(0); await c.sendKeys(...keys); @@ -148,7 +149,7 @@ describe("completion on open/tabopen/winopen commands", () => { const cancel = async() => { await c.sendKeys(Key.ESCAPE); await new Promise(resolve => setTimeout(resolve, 100)); - await webdriver.switchTo().parentFrame(); + await (webdriver.switchTo() as any).parentFrame(); } await execCommand('set complete=sbh'); @@ -191,7 +192,7 @@ describe("completion on open/tabopen/winopen commands", () => { let c = new Console(webdriver); - const typeCommand = async(...keys) => { + const typeCommand = async(...keys: string[]) => { await body.sendKeys(':'); await webdriver.switchTo().frame(0); await c.sendKeys(...keys); @@ -200,7 +201,7 @@ describe("completion on open/tabopen/winopen commands", () => { const cancel = async() => { await c.sendKeys(Key.ESCAPE); await new Promise(resolve => setTimeout(resolve, 100)); - await webdriver.switchTo().parentFrame(); + await (webdriver.switchTo() as any).parentFrame(); } await browser.storage.local.set({ settings: { diff --git a/e2e/completion_set.test.js b/e2e/completion_set.test.ts index a6ec248..018479f 100644 --- a/e2e/completion_set.test.js +++ b/e2e/completion_set.test.ts @@ -1,19 +1,17 @@ -const express = require('express'); -const lanthan = require('lanthan'); -const path = require('path'); -const assert = require('assert'); -const eventually = require('./eventually'); -const settings = require('./settings'); -const Console = require('./lib/Console'); -const { Builder } = require('lanthan'); -const { By } = require('selenium-webdriver'); +import * as path from 'path'; +import * as assert from 'assert'; + +import settings from './settings'; +import eventually from './eventually'; +import { Builder, Lanthan } from 'lanthan'; +import { WebDriver, WebElement, By } from 'selenium-webdriver'; +import { Console } from './lib/Console'; describe("completion on set commands", () => { - const port = 12321; - let lanthan; - let session; - let browser; - let body; + let lanthan: Lanthan; + let webdriver: WebDriver; + let browser: any; + let body: WebElement; before(async() => { lanthan = await Builder @@ -50,10 +48,10 @@ describe("completion on set commands", () => { let items = await c.getCompletions(); assert.equal(items.length, 5); assert.deepEqual(items[0], { type: 'title', text: 'Properties' }); - assert(items[1].text.startsWith('hintchars')) - assert(items[2].text.startsWith('smoothscroll')) - assert(items[3].text.startsWith('nosmoothscroll')) - assert(items[4].text.startsWith('complete')) + 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')) }); }); @@ -67,7 +65,7 @@ describe("completion on set commands", () => { await eventually(async() => { let items = await c.getCompletions(); assert.equal(items.length, 2); - assert(items[1].text.includes('nosmoothscroll')) + assert.ok(items[1].text.includes('nosmoothscroll')) }); }); }); diff --git a/e2e/console.test.js b/e2e/console.test.ts index 131a4ef..65c5d2d 100644 --- a/e2e/console.test.js +++ b/e2e/console.test.ts @@ -1,13 +1,14 @@ -const express = require('express'); -const path = require('path'); -const assert = require('assert'); -const eventually = require('./eventually'); -const { Builder } = require('lanthan'); -const { Key, By } = require('selenium-webdriver'); +import express from 'express'; +import * as path from 'path'; +import * as assert from 'assert'; +import * as http from 'http'; + +import { Builder, Lanthan } from 'lanthan'; +import { WebDriver, WebElement, By, Key } from 'selenium-webdriver'; const newApp = () => { let app = express(); - app.get('/', (req, res) => { + app.get('/', (_req, res) => { res.send(`<!DOCTYPEhtml> <html lang="en"> <head> @@ -21,12 +22,10 @@ const newApp = () => { describe("console test", () => { const port = 12321; - let http; - let lanthan; - let webdriver; - let browser; - let tab; - let body; + let http: http.Server; + let lanthan: Lanthan; + let webdriver: WebDriver; + let body: WebElement; before(async() => { http = newApp().listen(port); @@ -35,7 +34,6 @@ describe("console test", () => { .spyAddon(path.join(__dirname, '..')) .build(); webdriver = lanthan.getWebDriver(); - browser = lanthan.getWebExtBrowser(); }); after(async() => { @@ -65,7 +63,7 @@ describe("console test", () => { await body.sendKeys('o'); await webdriver.switchTo().frame(0); - let value = await webdriver.executeScript(() => document.querySelector('input').value); + let value = await webdriver.executeScript(() => document.querySelector('input')!!.value); assert.equal(value, 'open '); }); @@ -73,7 +71,7 @@ describe("console test", () => { await body.sendKeys(Key.SHIFT, 'o'); await webdriver.switchTo().frame(0); - let value = await webdriver.executeScript(() => document.querySelector('input').value); + let value = await webdriver.executeScript(() => document.querySelector('input')!!.value); assert.equal(value, `open http://127.0.0.1:${port}/`); }); @@ -81,7 +79,7 @@ describe("console test", () => { await body.sendKeys('t'); await webdriver.switchTo().frame(0); - let value = await webdriver.executeScript(() => document.querySelector('input').value); + let value = await webdriver.executeScript(() => document.querySelector('input')!!.value); assert.equal(value, 'tabopen '); }); @@ -89,7 +87,7 @@ describe("console test", () => { await body.sendKeys(Key.SHIFT, 't'); await webdriver.switchTo().frame(0); - let value = await webdriver.executeScript(() => document.querySelector('input').value); + let value = await webdriver.executeScript(() => document.querySelector('input')!!.value); assert.equal(value, `tabopen http://127.0.0.1:${port}/`); }); @@ -97,7 +95,7 @@ describe("console test", () => { await body.sendKeys('w'); await webdriver.switchTo().frame(0); - let value = await webdriver.executeScript(() => document.querySelector('input').value); + let value = await webdriver.executeScript(() => document.querySelector('input')!!.value); assert.equal(value, 'winopen '); }); @@ -105,7 +103,7 @@ describe("console test", () => { await body.sendKeys(Key.SHIFT, 'W'); await webdriver.switchTo().frame(0); - let value = await webdriver.executeScript(() => document.querySelector('input').value); + let value = await webdriver.executeScript(() => document.querySelector('input')!!.value); assert.equal(value, `winopen http://127.0.0.1:${port}/`); }); @@ -113,7 +111,7 @@ describe("console test", () => { await body.sendKeys('b'); await webdriver.switchTo().frame(0); - let value = await webdriver.executeScript(() => document.querySelector('input').value); + let value = await webdriver.executeScript(() => document.querySelector('input')!!.value); assert.equal(value, `buffer `); }); @@ -121,7 +119,7 @@ describe("console test", () => { await body.sendKeys('a'); await webdriver.switchTo().frame(0); - let value = await webdriver.executeScript(() => document.querySelector('input').value); + let value = await webdriver.executeScript(() => document.querySelector('input')!!.value); assert.equal(value, `addbookmark Hello, world!`); }); }); diff --git a/e2e/eventually.js b/e2e/eventually.js deleted file mode 100644 index ab0ae25..0000000 --- a/e2e/eventually.js +++ /dev/null @@ -1,23 +0,0 @@ -let defaultInterval = 100; -let defaultTimeout = 2000; - -function sleep(ms) { - return new Promise(resolve => setTimeout(resolve, ms)); -} - -const eventually = async (fn, timeout = defaultTimeout, interval = defaultInterval) => { - let start = Date.now(); - let loop = async() => { - try { - await fn(); - } catch (err) { - if (Date.now() - start > timeout) { - throw err; - } - await new Promise((resolve) => setTimeout(resolve, interval)) - await loop(); - } - }; - await loop(); -}; -module.exports = eventually; diff --git a/e2e/eventually.ts b/e2e/eventually.ts new file mode 100644 index 0000000..12c4552 --- /dev/null +++ b/e2e/eventually.ts @@ -0,0 +1,30 @@ +const defaultInterval = 100; +const defaultTimeout = 2000; + +type Handler = () => void + +const sleep = (ms: number): Promise<void> => { + return new Promise(resolve => setTimeout(resolve, ms)); +} + +const eventually = async ( + fn: Handler, + timeout = defaultTimeout, + interval = defaultInterval, +): Promise<void> => { + let start = Date.now(); + let loop = async() => { + try { + await fn(); + } catch (err) { + if (Date.now() - start > timeout) { + throw err; + } + await sleep(interval); + await loop(); + } + }; + await loop(); +}; + +export default eventually; diff --git a/e2e/follow.test.js b/e2e/follow.test.ts index 336d673..5d38085 100644 --- a/e2e/follow.test.js +++ b/e2e/follow.test.ts @@ -1,28 +1,30 @@ -const express = require('express'); -const path = require('path'); -const assert = require('assert'); -const eventually = require('./eventually'); -const { Builder } = require('lanthan'); -const { Key, By } = require('selenium-webdriver'); +import express from 'express'; +import * as path from 'path'; +import * as assert from 'assert'; +import * as http from 'http'; + +import eventually from './eventually'; +import { Builder, Lanthan } from 'lanthan'; +import { WebDriver, By, Key } from 'selenium-webdriver'; const newApp = () => { let app = express(); - app.get('/', (req, res) => { + app.get('/', (_req, res) => { res.send(`<!DOCTYPEhtml> <html lang="en"> <body><a href="hello">hello</a></body> </html">`); }); - app.get('/follow-input', (req, res) => { + app.get('/follow-input', (_req, res) => { res.send(`<!DOCTYPEhtml> <html lang="en"> <body><input></body> </html">`); }); - app.get('/area', (req, res) => { + app.get('/area', (_req, res) => { res.send(`<!DOCTYPEhtml> <html lang="en"> <body> @@ -49,7 +51,7 @@ const newApp = () => { * | | * +-----------------+ */ - app.get('/test1', (req, res) => { + app.get('/test1', (_req, res) => { res.send(`<!DOCTYPEhtml> <html lang="en"> <body> @@ -71,13 +73,13 @@ const newApp = () => { * | | * +-----------------+ */ - app.get('/test2', (req, res) => { + app.get('/test2', (_req, res) => { res.send(`<!DOCTYPEhtml> <html lang="en"> <body><iframe height="5000" src='/test2-frame'></body> </html">`); }); - app.get('/test2-frame', (req, res) => { + app.get('/test2-frame', (_req, res) => { res.send(`<!DOCTYPEhtml> <html lang="en"> <body> @@ -98,13 +100,13 @@ const newApp = () => { * | | * +-----------------+ */ - app.get('/test3', (req, res) => { + app.get('/test3', (_req, res) => { res.send(`<!DOCTYPEhtml> <html lang="en"> <body><iframe src='/test3-frame'></body> </html">`); }); - app.get('/test3-frame', (req, res) => { + app.get('/test3-frame', (_req, res) => { res.send(`<!DOCTYPEhtml> <html lang="en"> <body> @@ -118,20 +120,20 @@ const newApp = () => { return app; }; -const waitForHints = async(webdriver) => { +const waitForHints = async(webdriver: WebDriver): Promise<void> => { await eventually(async() => { let hints = await webdriver.findElements(By.css(`.vimvixen-hint`)); - assert(hints.length > 0); + assert.ok(hints.length > 0); }); }; describe('follow test', () => { const port = 12321; - let http; - let lanthan; - let webdriver; - let browser; + let http: http.Server; + let lanthan: Lanthan; + let webdriver: WebDriver; + let browser: any; before(async() => { http = newApp().listen(port); @@ -167,7 +169,7 @@ describe('follow test', () => { await waitForHints(webdriver); await body.sendKeys('a'); - let tagName = await webdriver.executeScript(() => document.activeElement.tagName); + let tagName = await webdriver.executeScript(() => document.activeElement!!.tagName) as string; assert.equal(tagName.toLowerCase(), 'input'); }); @@ -193,7 +195,7 @@ describe('follow test', () => { await waitForHints(webdriver); await body.sendKeys('a'); - let tagName = await webdriver.executeScript(() => document.activeElement.tagName); + let tagName = await webdriver.executeScript(() => document.activeElement!!.tagName) as string; assert.equal(tagName.toLowerCase(), 'input'); }); diff --git a/e2e/follow_properties.test.js b/e2e/follow_properties.test.ts index 5e22a40..47556a2 100644 --- a/e2e/follow_properties.test.js +++ b/e2e/follow_properties.test.ts @@ -1,15 +1,17 @@ -const express = require('express'); -const path = require('path'); -const assert = require('assert'); -const eventually = require('./eventually'); -const Console = require('./lib/Console'); -const { Builder } = require('lanthan'); -const { Key, By } = require('selenium-webdriver'); +import express from 'express'; +import * as path from 'path'; +import * as assert from 'assert'; +import * as http from 'http'; + +import eventually from './eventually'; +import { Builder, Lanthan } from 'lanthan'; +import { WebDriver, WebElement, By, Key } from 'selenium-webdriver'; +import { Console } from './lib/Console'; const newApp = () => { let app = express(); - app.get('/', (req, res) => { + app.get('/', (_req, res) => { res.send(`<!DOCTYPEhtml> <html lang="en"> <body> @@ -24,21 +26,13 @@ const newApp = () => { return app; }; -const waitForHints = async(webdriver) => { - await eventually(async() => { - let hints = await webdriver.findElements(By.css(`.vimvixen-hint`)); - assert(hints.length > 0); - }); -}; - describe('follow properties test', () => { - const port = 12321; - let http; - let lanthan; - let webdriver; - let browser; - let body; + let http: http.Server; + let lanthan: Lanthan; + let webdriver: WebDriver; + let browser: any; + let body: WebElement; before(async() => { http = newApp().listen(port); @@ -152,7 +146,7 @@ describe('follow properties test', () => { await webdriver.switchTo().frame(0); await c.sendKeys('set hintchars=abc', Key.ENTER); await new Promise(resolve => setTimeout(resolve, 100)); - await webdriver.switchTo().parentFrame(); + await (webdriver.switchTo() as any).parentFrame(); await body.sendKeys('f'); await eventually(async() => { diff --git a/e2e/lib/Console.js b/e2e/lib/Console.ts index 6016de1..37b0597 100644 --- a/e2e/lib/Console.js +++ b/e2e/lib/Console.ts @@ -1,11 +1,16 @@ -const { By } = require('selenium-webdriver'); +import { WebDriver, By } from 'selenium-webdriver'; -class Console { - constructor(webdriver) { - this.webdriver = webdriver; +export type CompletionItem = { + type: string; + text: string; + highlight: boolean; +} + +export class Console { + constructor(private webdriver: WebDriver) { } - async sendKeys(...keys) { + async sendKeys(...keys: string[]) { let input = await this.webdriver.findElement(By.css('input')); input.sendKeys(...keys); } @@ -13,24 +18,27 @@ class Console { async currentValue() { return await this.webdriver.executeScript(() => { let input = document.querySelector('input'); + if (input === null) { + throw new Error('could not find input element'); + } return input.value; }); } - async getCompletions() { - return await this.webdriver.executeScript(() => { + getCompletions(): Promise<CompletionItem[]> { + return this.webdriver.executeScript(() => { let items = document.querySelectorAll('.vimvixen-console-completion > li'); if (items.length === 0) { throw new Error('completion items not found'); } let objs = []; - for (let li of items) { + for (let li of Array.from(items)) { if (li.classList.contains('vimvixen-console-completion-title')) { - objs.push({ type: 'title', text: li.textContent.trim() }); + objs.push({ type: 'title', text: li.textContent!!.trim() }); } else if ('vimvixen-console-completion-item') { let highlight = li.classList.contains('vimvixen-completion-selected'); - objs.push({ type: 'item', text: li.textContent.trim(), highlight }); + objs.push({ type: 'item', text: li.textContent!!.trim(), highlight }); } else { throw new Error(`unexpected class: ${li.className}`); } @@ -39,5 +47,3 @@ class Console { }); } } - -module.exports = Console; diff --git a/e2e/lib/clipboard.js b/e2e/lib/clipboard.ts index 4061dbd..13d95df 100644 --- a/e2e/lib/clipboard.js +++ b/e2e/lib/clipboard.ts @@ -1,10 +1,8 @@ -'use strict'; +import { spawn } from 'child_process'; -const { spawn } = require('child_process'); - -const readLinux = () => { +const readLinux = (): Promise<string> => { let stdout = '', stderr = ''; - return new Promise((resolve, reject) => { + return new Promise((resolve) => { let xsel = spawn('xsel', ['--clipboard', '--output']); xsel.stdout.on('data', (data) => { stdout += data; @@ -21,9 +19,9 @@ const readLinux = () => { }); }; -const writeLinux = (data) => { - let stdout = '', stderr = ''; - return new Promise((resolve, reject) => { +const writeLinux = (data: string): Promise<string> => { + let stderr = ''; + return new Promise((resolve) => { let xsel = spawn('xsel', ['--clipboard', '--input']); xsel.stderr.on('data', (data) => { stderr += data; @@ -39,25 +37,30 @@ const writeLinux = (data) => { }); }; -const unsupported = (os) => { - return () => { - throw new Error(`Unsupported os: ${os}`); - }; -}; +class UnsupportedError extends Error { + constructor(platform: string) { + super(); + this.message = `Unsupported platform: ${platform}`; + } +} -const detect = () => { +const read = () => { switch (process.platform) { - case 'linux': - return { - read: readLinux, - write: writeLinux, - }; - default: - return { - read: unsupported(process.platform), - write: unsupported(process.platform), - }; + case 'linux': + return readLinux(); } + throw new UnsupportedError(process.platform); } -module.exports = detect(); +const write = (data: string) => { + switch (process.platform) { + case 'linux': + return writeLinux(data); + } + throw new UnsupportedError(process.platform); +} + +export { + read, + write, +}; diff --git a/e2e/mark.test.js b/e2e/mark.test.ts index cc32c85..14885ee 100644 --- a/e2e/mark.test.js +++ b/e2e/mark.test.ts @@ -1,13 +1,15 @@ -const express = require('express'); -const path = require('path'); -const assert = require('assert'); -const eventually = require('./eventually'); -const { Builder } = require('lanthan'); -const { By } = require('selenium-webdriver'); +import express from 'express'; +import * as path from 'path'; +import * as assert from 'assert'; +import * as http from 'http'; + +import eventually from './eventually'; +import { Builder, Lanthan } from 'lanthan'; +import { WebDriver, By } from 'selenium-webdriver'; const newApp = () => { let app = express(); - app.get('/', (req, res) => { + app.get('/', (_req, res) => { res.send(`<!DOCTYPEhtml> <html lang="en"> <body style="width:10000px; height:10000px"></body> @@ -17,12 +19,11 @@ const newApp = () => { }; describe("mark test", () => { - const port = 12321; - let http; - let lanthan; - let webdriver; - let browser; + let http: http.Server; + let lanthan: Lanthan; + let webdriver: WebDriver; + let browser: any; before(async() => { http = newApp().listen(port); @@ -103,12 +104,13 @@ describe("mark test", () => { await browser.tabs.create({ url: `http://127.0.0.1:${port}#second` }); await browser.tabs.remove(tab.id); - let handles; + let handles: string[]; await eventually(async() => { handles = await webdriver.getAllWindowHandles(); + await webdriver.getAllWindowHandles assert.equal(handles.length, 2); }); - await webdriver.switchTo().window(handles[0]); + await webdriver.switchTo().window(handles!![0]); await webdriver.navigate().to(`http://127.0.0.1:${port}#second`); body = await webdriver.findElement(By.css('body')); await body.sendKeys('\'', 'A'); diff --git a/e2e/navigate.test.js b/e2e/navigate.test.ts index e4b8f69..4b664e4 100644 --- a/e2e/navigate.test.js +++ b/e2e/navigate.test.ts @@ -1,10 +1,12 @@ -const express = require('express'); -const path = require('path'); -const assert = require('assert'); -const eventually = require('./eventually'); -const { Builder } = require('lanthan'); -const { Options: FirefoxOptions } = require('selenium-webdriver/firefox'); -const { Key, By } = require('selenium-webdriver'); +import express from 'express'; +import * as path from 'path'; +import * as assert from 'assert'; +import * as http from 'http'; + +import eventually from './eventually'; +import { Builder, Lanthan } from 'lanthan'; +import { WebDriver, By, Key } from 'selenium-webdriver'; +import { Options as FirefoxOptions } from 'selenium-webdriver/firefox'; const newApp = () => { let app = express(); @@ -24,7 +26,7 @@ const newApp = () => { </head> </html">`); }); - app.get('/reload', (req, res) => { + app.get('/reload', (_req, res) => { res.status(200).send(` <html lang="en"> <head> @@ -46,13 +48,13 @@ const newApp = () => { describe("navigate test", () => { const port = 12321; - let http; - let lanthan; - let webdriver; - let browser; + let http: http.Server; + let lanthan: Lanthan; + let webdriver: WebDriver; + let browser: any; before(async() => { - let opts = new FirefoxOptions() + let opts = (new FirefoxOptions() as any) .setPreference('browser.startup.homepage', `http://127.0.0.1:${port}#home`); http = newApp().listen(port); lanthan = await Builder @@ -135,8 +137,8 @@ describe("navigate test", () => { await body.sendKeys(Key.SHIFT, 'l'); await eventually(async() => { - tab = (await browser.tabs.query({}))[0]; - url = new URL(tab.url); + let tab = (await browser.tabs.query({}))[0]; + let url = new URL(tab.url); assert.equal(url.pathname, `/second`) }); }); @@ -220,11 +222,11 @@ describe("navigate test", () => { it('should reload current tab by r', async () => { await webdriver.navigate().to(`http://127.0.0.1:${port}/reload`); await webdriver.executeScript(() => window.scrollTo(500, 500)); - let before + let before: number; await eventually(async() => { let tab = (await browser.tabs.query({}))[0]; before = Number(new URL(tab.url).hash.split('#')[1]); - assert(before > 0); + assert.ok(before > 0); }); let body = await webdriver.findElement(By.css('body')); @@ -234,7 +236,7 @@ describe("navigate test", () => { await eventually(async() => { let tab = (await browser.tabs.query({}))[0]; after = Number(new URL(tab.url).hash.split('#')[1]); - assert(after > before); + assert.ok(after > before); }); await eventually(async() => { @@ -246,11 +248,11 @@ describe("navigate test", () => { it('should reload current tab without cache by R', async () => { await webdriver.navigate().to(`http://127.0.0.1:${port}/reload`); await webdriver.executeScript(() => window.scrollTo(500, 500)); - let before + let before: number; await eventually(async() => { let tab = (await browser.tabs.query({}))[0]; before = Number(new URL(tab.url).hash.split('#')[1]); - assert(before > 0); + assert.ok(before > 0); }); let body = await webdriver.findElement(By.css('body')); @@ -260,7 +262,7 @@ describe("navigate test", () => { await eventually(async() => { let tab = (await browser.tabs.query({}))[0]; after = Number(new URL(tab.url).hash.split('#')[1]); - assert(after > before); + assert.ok(after > before); }); // assert that the page offset is reset to 0, and 'eventually' is timed-out. diff --git a/e2e/options.test.js b/e2e/options.test.ts index 456c80b..dba6992 100644 --- a/e2e/options.test.js +++ b/e2e/options.test.ts @@ -1,13 +1,14 @@ -const express = require('express'); -const path = require('path'); -const assert = require('assert'); -const eventually = require('./eventually'); -const { Builder } = require('lanthan'); -const { By } = require('selenium-webdriver'); +import express from 'express'; +import * as path from 'path'; +import * as assert from 'assert'; +import * as http from 'http'; + +import { Builder, Lanthan } from 'lanthan'; +import { WebDriver, By } from 'selenium-webdriver'; const newApp = () => { let app = express(); - app.get('/', (req, res) => { + app.get('/', (_req, res) => { res.send(`<!DOCTYPEhtml> <html lang="en"> <body style="width:10000px; height:10000px"></body> @@ -18,10 +19,10 @@ const newApp = () => { describe("options page", () => { const port = 12321; - let http; - let lanthan; - let session; - let browser; + let http: http.Server; + let lanthan: Lanthan; + let webdriver: WebDriver; + let browser: any; before(async() => { http = newApp().listen(port); @@ -50,11 +51,11 @@ describe("options page", () => { } }) - const updateTextarea = async(value) => { + const updateTextarea = async(value: string) => { let textarea = await webdriver.findElement(By.css('textarea')); await webdriver.executeScript(`document.querySelector('textarea').value = '${value}'`) await textarea.sendKeys(' '); - await webdriver.executeScript(() => document.querySelector('textarea').blur()); + await webdriver.executeScript(() => document.querySelector('textarea')!!.blur()); } it('saves current config on blur', async () => { diff --git a/e2e/options_form.test.js b/e2e/options_form.test.ts index 4f41738..04803da 100644 --- a/e2e/options_form.test.js +++ b/e2e/options_form.test.ts @@ -1,12 +1,14 @@ -const path = require('path'); -const assert = require('assert'); -const { Builder } = require('lanthan'); -const { By } = require('selenium-webdriver'); +import * as path from 'path'; +import * as assert from 'assert'; + +import { Builder, Lanthan } from 'lanthan'; +import { WebDriver, By } from 'selenium-webdriver'; + describe("options form page", () => { - let lanthan; - let webdriver; - let browser; + let lanthan: Lanthan; + let webdriver: WebDriver; + let browser: any; beforeEach(async() => { lanthan = await Builder @@ -28,14 +30,14 @@ describe("options form page", () => { } }) - const setBlacklistValue = async(nth, value) => { + const setBlacklistValue = async(nth: number, value: string) => { let selector = '.form-blacklist-form .column-url'; let input = (await webdriver.findElements(By.css(selector)))[nth]; await input.sendKeys(value); await webdriver.executeScript(`document.querySelectorAll('${selector}')[${nth}].blur()`); } - const setSearchEngineValue = async(nth, name, url) => { + const setSearchEngineValue = async(nth: number, name: string, url: string) => { let selector = '.form-search-form input.column-name'; let input = (await webdriver.findElements(By.css(selector)))[nth]; await input.sendKeys(name); diff --git a/e2e/repeat.test.js b/e2e/repeat.test.ts index b068b18..2280ed8 100644 --- a/e2e/repeat.test.js +++ b/e2e/repeat.test.ts @@ -1,28 +1,29 @@ -const express = require('express'); -const path = require('path'); -const assert = require('assert'); -const eventually = require('./eventually'); -const { Builder } = require('lanthan'); -const { Key, By } = require('selenium-webdriver'); +import express from 'express'; +import * as path from 'path'; +import * as assert from 'assert'; +import * as http from 'http'; + +import eventually from './eventually'; +import { Builder, Lanthan } from 'lanthan'; +import { WebDriver, By, Key } from 'selenium-webdriver'; + const newApp = () => { let app = express(); - app.get('/', (req, res) => { + app.get('/', (_req, res) => { res.send('ok'); }); return app; }; describe("tab test", () => { - const port = 12321; const url = `http://127.0.0.1:${port}/`; - let http; - let lanthan; - let webdriver - let browser; - let tabs; + let http: http.Server; + let lanthan: Lanthan; + let webdriver: WebDriver; + let browser: any; before(async() => { lanthan = await Builder @@ -46,8 +47,6 @@ describe("tab test", () => { }); it('repeats last operation', async () => { - let before = await browser.tabs.query({}); - let body = await webdriver.findElement(By.css('body')); await body.sendKeys(':'); diff --git a/e2e/scroll.test.js b/e2e/scroll.test.ts index b728f47..63ac8a8 100644 --- a/e2e/scroll.test.js +++ b/e2e/scroll.test.ts @@ -1,12 +1,14 @@ -const express = require('express'); -const path = require('path'); -const assert = require('assert'); -const { Builder } = require('lanthan'); -const { Key, By } = require('selenium-webdriver'); +import express from 'express'; +import * as path from 'path'; +import * as assert from 'assert'; +import * as http from 'http'; + +import { Builder, Lanthan } from 'lanthan'; +import { WebDriver, WebElement, By, Key } from 'selenium-webdriver'; const newApp = () => { let app = express(); - app.get('/', (req, res) => { + app.get('/', (_req, res) => { res.send(`<!DOCTYPEhtml> <html lang="en"> <body style="width:10000px; height:10000px"></body> @@ -16,12 +18,11 @@ const newApp = () => { }; describe("scroll test", () => { - const port = 12321; - let http; - let lanthan; - let webdriver; - let body; + let http: http.Server; + let lanthan: Lanthan; + let webdriver: WebDriver; + let body: WebElement; before(async() => { http = newApp().listen(port); @@ -51,7 +52,7 @@ describe("scroll test", () => { it('scrolls up by k', async () => { await body.sendKeys('j'); - let pageYOffset = await webdriver.executeScript(() => window.pageYOffset); + let pageYOffset = await webdriver.executeScript(() => window.pageYOffset) as number; assert.equal(pageYOffset, 64); }); @@ -59,7 +60,7 @@ describe("scroll test", () => { await webdriver.executeScript(() => window.scrollTo(0, 200)); await body.sendKeys('k'); - let pageYOffset = await webdriver.executeScript(() => window.pageYOffset); + let pageYOffset = await webdriver.executeScript(() => window.pageYOffset) as number; assert.equal(pageYOffset, 136); }); @@ -67,7 +68,7 @@ describe("scroll test", () => { await webdriver.executeScript(() => window.scrollTo(100, 100)); await body.sendKeys('h'); - let pageXOffset = await webdriver.executeScript(() => window.pageXOffset); + let pageXOffset = await webdriver.executeScript(() => window.pageXOffset) as number; assert.equal(pageXOffset, 36); }); @@ -75,7 +76,7 @@ describe("scroll test", () => { await webdriver.executeScript(() => window.scrollTo(100, 100)); await body.sendKeys('l'); - let pageXOffset = await webdriver.executeScript(() => window.pageXOffset); + let pageXOffset = await webdriver.executeScript(() => window.pageXOffset) as number; assert.equal(pageXOffset, 164); }); @@ -83,7 +84,7 @@ describe("scroll test", () => { await webdriver.executeScript(() => window.scrollTo(0, 100)); await body.sendKeys('g', 'g'); - let pageYOffset = await webdriver.executeScript(() => window.pageYOffset); + let pageYOffset = await webdriver.executeScript(() => window.pageYOffset) as number; assert.equal(pageYOffset, 0); }); @@ -91,24 +92,24 @@ describe("scroll test", () => { await webdriver.executeScript(() => window.scrollTo(0, 100)); await body.sendKeys(Key.SHIFT, 'g'); - let pageYOffset = await webdriver.executeScript(() => window.pageYOffset); - assert(pageYOffset > 5000); + let pageYOffset = await webdriver.executeScript(() => window.pageYOffset) as number; + assert.ok(pageYOffset > 5000); }); it('scrolls bottom by 0', async () => { await webdriver.executeScript(() => window.scrollTo(0, 100)); await body.sendKeys(Key.SHIFT, '0'); - let pageXOffset = await webdriver.executeScript(() => window.pageXOffset); - assert(pageXOffset === 0); + let pageXOffset = await webdriver.executeScript(() => window.pageXOffset) as number; + assert.ok(pageXOffset === 0); }); it('scrolls bottom by $', async () => { await webdriver.executeScript(() => window.scrollTo(0, 100)); await body.sendKeys(Key.SHIFT, '$'); - let pageXOffset = await webdriver.executeScript(() => window.pageXOffset); - assert(pageXOffset > 5000); + let pageXOffset = await webdriver.executeScript(() => window.pageXOffset) as number; + assert.ok(pageXOffset > 5000); }); it('scrolls bottom by <C-U>', async () => { @@ -116,9 +117,9 @@ describe("scroll test", () => { await body.sendKeys(Key.CONTROL, 'u'); let pageHeight = - await webdriver.executeScript(() => window.document.documentElement.clientHeight); - let pageYOffset = await webdriver.executeScript(() => window.pageYOffset); - assert(Math.abs(pageYOffset - (1000 - Math.floor(pageHeight / 2))) < 5); + await webdriver.executeScript(() => window.document.documentElement.clientHeight) as number; + let pageYOffset = await webdriver.executeScript(() => window.pageYOffset) as number; + assert.ok(Math.abs(pageYOffset - (1000 - Math.floor(pageHeight / 2))) < 5); }); it('scrolls bottom by <C-D>', async () => { @@ -126,9 +127,9 @@ describe("scroll test", () => { await body.sendKeys(Key.CONTROL, 'd'); let pageHeight = - await webdriver.executeScript(() => window.document.documentElement.clientHeight); - let pageYOffset = await webdriver.executeScript(() => window.pageYOffset); - assert(Math.abs(pageYOffset - (1000 + Math.floor(pageHeight / 2))) < 5); + await webdriver.executeScript(() => window.document.documentElement.clientHeight) as number; + let pageYOffset = await webdriver.executeScript(() => window.pageYOffset) as number; + assert.ok(Math.abs(pageYOffset - (1000 + Math.floor(pageHeight / 2))) < 5); }); it('scrolls bottom by <C-B>', async () => { @@ -136,9 +137,9 @@ describe("scroll test", () => { await body.sendKeys(Key.CONTROL, 'b'); let pageHeight = - await webdriver.executeScript(() => window.document.documentElement.clientHeight); - let pageYOffset = await webdriver.executeScript(() => window.pageYOffset); - assert(Math.abs(pageYOffset - (1000 - pageHeight)) < 5); + await webdriver.executeScript(() => window.document.documentElement.clientHeight) as number; + let pageYOffset = await webdriver.executeScript(() => window.pageYOffset) as number; + assert.ok(Math.abs(pageYOffset - (1000 - pageHeight)) < 5); }); it('scrolls bottom by <C-F>', async () => { @@ -146,8 +147,8 @@ describe("scroll test", () => { await body.sendKeys(Key.CONTROL, 'f'); let pageHeight = - await webdriver.executeScript(() => window.document.documentElement.clientHeight); - let pageYOffset = await webdriver.executeScript(() => window.pageYOffset); - assert(Math.abs(pageYOffset - (1000 + pageHeight)) < 5); + await webdriver.executeScript(() => window.document.documentElement.clientHeight) as number; + let pageYOffset = await webdriver.executeScript(() => window.pageYOffset) as number; + assert.ok(Math.abs(pageYOffset - (1000 + pageHeight)) < 5); }); }); diff --git a/e2e/settings.js b/e2e/settings.ts index e78add0..b88caf0 100644 --- a/e2e/settings.js +++ b/e2e/settings.ts @@ -1,4 +1,4 @@ -module.exports = { +export default { source: 'json', json: `{ "keymaps": { @@ -83,4 +83,4 @@ module.exports = { "blacklist": [ ] }`, -} +}; diff --git a/e2e/tab.test.js b/e2e/tab.test.ts index 4e3a681..c75541b 100644 --- a/e2e/tab.test.js +++ b/e2e/tab.test.ts @@ -1,30 +1,30 @@ -const express = require('express'); -const lanthan = require('lanthan'); -const path = require('path'); -const assert = require('assert'); -const eventually = require('./eventually'); -const { Builder } = require('lanthan'); -const { Key, By } = require('selenium-webdriver'); +import express from 'express'; +import * as path from 'path'; +import * as assert from 'assert'; +import * as http from 'http'; + +import eventually from './eventually'; +import { Builder, Lanthan } from 'lanthan'; +import { WebDriver, By, Key } from 'selenium-webdriver'; const newApp = () => { let app = express(); - app.get('/', (req, res) => { + app.get('/', (_req, res) => { res.send('ok'); }); return app; }; describe("tab test", () => { - const port = 12321; const url = `http://127.0.0.1:${port}/`; - let http; - let lanthan; - let webdriver - let browser; - let win; - let tabs; + let http: http.Server; + let lanthan: Lanthan; + let webdriver: WebDriver; + let browser: any; + let win: any; + let tabs: any[]; before(async() => { lanthan = await Builder @@ -52,7 +52,7 @@ describe("tab test", () => { await webdriver.navigate().to(`${url}#${i}`); } tabs = await browser.tabs.query({ windowId: win.id }); - tabs.sort((t1, t2) => t1.index - t2.index); + tabs.sort((t1: any, t2: any) => t1.index - t2.index); }); afterEach(async() => { @@ -65,9 +65,9 @@ describe("tab test", () => { await body.sendKeys('d'); let current = await browser.tabs.query({ windowId: win.id }); - assert(current.length === tabs.length - 1); - assert(current[3].active); - assert(current[3].url === tabs[4].url); + assert.ok(current.length === tabs.length - 1); + assert.ok(current[3].active); + assert.ok(current[3].url === tabs[4].url); }); it('deletes tab and selects left by D', async () => { @@ -77,9 +77,9 @@ describe("tab test", () => { await eventually(async() => { let current = await browser.tabs.query({ windowId: win.id }); - assert(current.length === tabs.length - 1); - assert(current[2].active); - assert(current[2].url === tabs[2].url); + assert.ok(current.length === tabs.length - 1); + assert.ok(current[2].active); + assert.ok(current[2].url === tabs[2].url); }) }); @@ -89,7 +89,7 @@ describe("tab test", () => { await body.sendKeys('x', '$'); let current = await browser.tabs.query({ windowId: win.id }); - assert(current.length === 2); + assert.ok(current.length === 2); }); it('duplicates tab by zd', async () => { @@ -99,9 +99,9 @@ describe("tab test", () => { await eventually(async() => { let current = await browser.tabs.query({ windowId: win.id }); - current.sort((t1, t2) => t1.index - t2.index); - assert(current.length === tabs.length + 1); - assert(current[0].url === current[1].url); + current.sort((t1: any, t2: any) => t1.index - t2.index); + assert.ok(current.length === tabs.length + 1); + assert.ok(current[0].url === current[1].url); }); }); @@ -111,7 +111,7 @@ describe("tab test", () => { await body.sendKeys('z', 'p'); let current = await browser.tabs.query({ windowId: win.id }); - assert(current[0].pinned); + assert.ok(current[0].pinned); }); it('selects previous tab by K', async () => { @@ -120,7 +120,7 @@ describe("tab test", () => { await body.sendKeys(Key.SHIFT, 'K'); let current = await browser.tabs.query({ windowId: win.id }); - assert(current[1].active); + assert.ok(current[1].active); }); it('selects previous tab by K rotatory', async () => { @@ -129,7 +129,7 @@ describe("tab test", () => { await body.sendKeys(Key.SHIFT, 'K'); let current = await browser.tabs.query({ windowId: win.id }); - assert(current[current.length - 1].active) + assert.ok(current[current.length - 1].active) }); it('selects next tab by J', async () => { @@ -138,7 +138,7 @@ describe("tab test", () => { await body.sendKeys(Key.SHIFT, 'J'); let current = await browser.tabs.query({ windowId: win.id }); - assert(current[3].active); + assert.ok(current[3].active); }); it('selects previous tab by J rotatory', async () => { @@ -147,7 +147,7 @@ describe("tab test", () => { await body.sendKeys(Key.SHIFT, 'J'); let current = await browser.tabs.query({ windowId: win.id }); - assert(current[0].active) + assert.ok(current[0].active) }); it('selects first tab by g0', async () => { @@ -156,7 +156,7 @@ describe("tab test", () => { await body.sendKeys('g', '0'); let current = await browser.tabs.query({ windowId: win.id }); - assert(current[0].active) + assert.ok(current[0].active) }); it('selects last tab by g$', async () => { @@ -165,7 +165,7 @@ describe("tab test", () => { await body.sendKeys('g', '$'); let current = await browser.tabs.query({ windowId: win.id }); - assert(current[current.length - 1].active) + assert.ok(current[current.length - 1].active) }); it('selects last selected tab by <C-6>', async () => { @@ -176,7 +176,7 @@ describe("tab test", () => { await body.sendKeys(Key.CONTROL, '6'); let current = await browser.tabs.query({ windowId: win.id }); - assert(current[1].active) + assert.ok(current[1].active) }); // browser.sessions.getRecentlyClosed() sometime throws "An unexpected error occurred" @@ -187,7 +187,7 @@ describe("tab test", () => { await body.sendKeys('u'); let current = await browser.tabs.query({ windowId: win.id }); - assert(current.length === tabs.length); + assert.ok(current.length === tabs.length); }); it('does not delete pinned tab by d', async () => { @@ -196,7 +196,7 @@ describe("tab test", () => { await body.sendKeys('d'); let current = await browser.tabs.query({ windowId: win.id }); - assert(current.length === tabs.length); + assert.ok(current.length === tabs.length); }); it('deletes pinned tab by !d', async () => { @@ -205,7 +205,7 @@ describe("tab test", () => { await body.sendKeys('!', 'd'); let current = await browser.tabs.query({ windowId: win.id }); - assert(current.length === tabs.length - 1); + assert.ok(current.length === tabs.length - 1); }); it('opens view-source by gf', async () => { @@ -215,8 +215,8 @@ describe("tab test", () => { await eventually(async() => { let current = await browser.tabs.query({ windowId: win.id }); - assert(current.length === tabs.length + 1); - assert(current[current.length - 1].url === `view-source:${url}#0`); + assert.ok(current.length === tabs.length + 1); + assert.ok(current[current.length - 1].url === `view-source:${url}#0`); }); }); }); diff --git a/e2e/zoom.test.js b/e2e/zoom.test.ts index c11ed1e..0b55a4d 100644 --- a/e2e/zoom.test.js +++ b/e2e/zoom.test.ts @@ -1,16 +1,17 @@ -const express = require('express'); -const { Builder } = require('lanthan'); -const path = require('path'); -const assert = require('assert'); -const eventually = require('./eventually'); -const { Key, By } = require('selenium-webdriver'); +import * as path from 'path'; +import * as assert from 'assert'; + +import eventually from './eventually'; +import { Builder, Lanthan } from 'lanthan'; +import { WebDriver, WebElement, By } from 'selenium-webdriver'; + describe("zoom test", () => { - let lanthan; - let webdriver; - let browser; - let tab; - let body; + let lanthan: Lanthan; + let webdriver: WebDriver; + let browser: any; + let tab: any; + let body: WebElement; before(async() => { lanthan = await Builder @@ -37,7 +38,7 @@ describe("zoom test", () => { await eventually(async() => { let actual = await browser.tabs.getZoom(tab.id); - assert(before < actual); + assert.ok(before < actual); }); }); @@ -47,7 +48,7 @@ describe("zoom test", () => { await eventually(async() => { let actual = await browser.tabs.getZoom(tab.id); - assert(before > actual); + assert.ok(before > actual); }); }); @@ -57,7 +58,7 @@ describe("zoom test", () => { await eventually(async() => { let actual = await browser.tabs.getZoom(tab.id); - assert(actual === 1); + assert.ok(actual === 1); }); }); }); |