aboutsummaryrefslogtreecommitdiff
path: root/e2e/lib
diff options
context:
space:
mode:
authorShin'ya Ueoka <ueokande@i-beam.org>2019-09-22 16:13:12 +0900
committerShin'ya Ueoka <ueokande@i-beam.org>2019-09-22 16:13:12 +0900
commit7e77e31ad64c3649888eae337e0c984fd9c2ea2a (patch)
tree4d3e630f82712abce5afd7e498d514253464a6ea /e2e/lib
parent91f8383ecc2f7ef3f95173ad973a74f79e277a6c (diff)
Migrate e2e tests to TypeScript
Diffstat (limited to 'e2e/lib')
-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
2 files changed, 46 insertions, 37 deletions
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,
+};