Migrate e2e tests to TypeScript
This commit is contained in:
parent
91f8383ecc
commit
7e77e31ad6
29 changed files with 553 additions and 516 deletions
|
@ -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;
|
|
@ -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}`);
|
||||
};
|
||||
};
|
||||
|
||||
const detect = () => {
|
||||
switch (process.platform) {
|
||||
case 'linux':
|
||||
return {
|
||||
read: readLinux,
|
||||
write: writeLinux,
|
||||
};
|
||||
default:
|
||||
return {
|
||||
read: unsupported(process.platform),
|
||||
write: unsupported(process.platform),
|
||||
};
|
||||
class UnsupportedError extends Error {
|
||||
constructor(platform: string) {
|
||||
super();
|
||||
this.message = `Unsupported platform: ${platform}`;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = detect();
|
||||
const read = () => {
|
||||
switch (process.platform) {
|
||||
case 'linux':
|
||||
return readLinux();
|
||||
}
|
||||
throw new UnsupportedError(process.platform);
|
||||
}
|
||||
|
||||
const write = (data: string) => {
|
||||
switch (process.platform) {
|
||||
case 'linux':
|
||||
return writeLinux(data);
|
||||
}
|
||||
throw new UnsupportedError(process.platform);
|
||||
}
|
||||
|
||||
export {
|
||||
read,
|
||||
write,
|
||||
};
|
Reference in a new issue