mirror of
https://github.com/wavetermdev/xterm.js.git
synced 2026-08-05 13:43:48 -07:00
Move openTerminal() to common util file
This commit is contained in:
@@ -4,8 +4,7 @@
|
||||
*/
|
||||
|
||||
import * as puppeteer from 'puppeteer';
|
||||
import { ITerminalOptions } from 'xterm';
|
||||
import { pollFor } from './TestUtils';
|
||||
import { pollFor, openTerminal } from './TestUtils';
|
||||
|
||||
const APP = 'http://127.0.0.1:3000/test';
|
||||
|
||||
@@ -23,7 +22,7 @@ describe('CharWidth Integration Tests', function(): void {
|
||||
page = (await browser.pages())[0];
|
||||
await page.setViewport({ width, height });
|
||||
await page.goto(APP);
|
||||
await openTerminal({ rows: 5, cols: 30 });
|
||||
await openTerminal(page, { rows: 5, cols: 30 });
|
||||
});
|
||||
|
||||
after(() => {
|
||||
@@ -75,16 +74,6 @@ describe('CharWidth Integration Tests', function(): void {
|
||||
});
|
||||
});
|
||||
|
||||
async function openTerminal(options: ITerminalOptions = {}): Promise<void> {
|
||||
await page.evaluate(`window.term = new Terminal(${JSON.stringify(options)})`);
|
||||
await page.evaluate(`window.term.open(document.querySelector('#terminal-container'))`);
|
||||
if (options.rendererType === 'dom') {
|
||||
await page.waitForSelector('.xterm-rows');
|
||||
} else {
|
||||
await page.waitForSelector('.xterm-text-layer');
|
||||
}
|
||||
}
|
||||
|
||||
async function sumWidths(start: number, end: number, sentinel: string): Promise<number> {
|
||||
await page.evaluate(`
|
||||
(function() {
|
||||
|
||||
@@ -5,8 +5,7 @@
|
||||
|
||||
import * as puppeteer from 'puppeteer';
|
||||
import { assert } from 'chai';
|
||||
import { ITerminalOptions } from 'xterm';
|
||||
import { pollFor } from './TestUtils';
|
||||
import { pollFor, openTerminal } from './TestUtils';
|
||||
|
||||
const APP = 'http://127.0.0.1:3000/test';
|
||||
|
||||
@@ -24,7 +23,7 @@ describe('InputHandler Integration Tests', function(): void {
|
||||
page = (await browser.pages())[0];
|
||||
await page.setViewport({ width, height });
|
||||
await page.goto(APP);
|
||||
await openTerminal();
|
||||
await openTerminal(page);
|
||||
});
|
||||
|
||||
after(() => {
|
||||
@@ -260,7 +259,7 @@ describe('InputHandler Integration Tests', function(): void {
|
||||
|
||||
describe('SM: Set Mode', () => {
|
||||
describe('CSI ? Pm h', () => {
|
||||
it('Pm = 1003, Set Use All Motion (any event) Mouse Tracking', async() => {
|
||||
it('Pm = 1003, Set Use All Motion (any event) Mouse Tracking', async () => {
|
||||
const coords = await page.evaluate(`
|
||||
(function() {
|
||||
const rect = window.term.element.getBoundingClientRect();
|
||||
@@ -309,7 +308,7 @@ describe('InputHandler Integration Tests', function(): void {
|
||||
window.term.write('#\x1b[5b');
|
||||
`);
|
||||
await pollFor(page, () => getLinesAsArray(4), ['##', '##', '##', '######']);
|
||||
await pollFor(page, () => getCursor(), {col: 6, row: 3});
|
||||
await pollFor(page, () => getCursor(), { col: 6, row: 3 });
|
||||
// should not repeat on fullwidth chars
|
||||
await page.evaluate(`
|
||||
window.term.reset();
|
||||
@@ -347,7 +346,7 @@ describe('InputHandler Integration Tests', function(): void {
|
||||
});
|
||||
|
||||
describe('Window Options - CSI Ps ; Ps ; Ps t', () => {
|
||||
it('should be disabled by default', async function() {
|
||||
it('should be disabled by default', async function(): Promise<void> {
|
||||
await page.evaluate(`(() => {
|
||||
window._stack = [];
|
||||
const _h = window.term.onData(data => window._stack.push(data));
|
||||
@@ -360,7 +359,7 @@ describe('InputHandler Integration Tests', function(): void {
|
||||
})()`);
|
||||
await pollFor(page, async () => await page.evaluate(`(() => _stack)()`), []);
|
||||
});
|
||||
it('14 - GetWinSizePixels', async function() {
|
||||
it('14 - GetWinSizePixels', async function(): Promise<void> {
|
||||
await page.evaluate(`window.term.setOption('windowOptions', {getWinSizePixels: true});`);
|
||||
await page.evaluate(`(() => {
|
||||
window._stack = [];
|
||||
@@ -371,7 +370,7 @@ describe('InputHandler Integration Tests', function(): void {
|
||||
const d = await getDimensions();
|
||||
await pollFor(page, async () => await page.evaluate(`(() => _stack)()`), [`\x1b[4;${d.height};${d.width}t`]);
|
||||
});
|
||||
it('16 - GetCellSizePixels', async function() {
|
||||
it('16 - GetCellSizePixels', async function(): Promise<void> {
|
||||
await page.evaluate(`window.term.setOption('windowOptions', {getCellSizePixels: true});`);
|
||||
await page.evaluate(`(() => {
|
||||
window._stack = [];
|
||||
@@ -397,22 +396,12 @@ describe('InputHandler Integration Tests', function(): void {
|
||||
window.term.resize(10, 4);
|
||||
window.term.write('\\x1b[?47l\\x1b8');
|
||||
`);
|
||||
await pollFor(page, () => getCursor(), {col: 1, row: 3});
|
||||
await pollFor(page, () => getCursor(), { col: 1, row: 3 });
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
async function openTerminal(options: ITerminalOptions = {}): Promise<void> {
|
||||
await page.evaluate(`window.term = new Terminal(${JSON.stringify(options)})`);
|
||||
await page.evaluate(`window.term.open(document.querySelector('#terminal-container'))`);
|
||||
if (options.rendererType === 'dom') {
|
||||
await page.waitForSelector('.xterm-rows');
|
||||
} else {
|
||||
await page.waitForSelector('.xterm-text-layer');
|
||||
}
|
||||
}
|
||||
|
||||
async function getLinesAsArray(count: number, start: number = 0): Promise<string[]> {
|
||||
let text = '';
|
||||
for (let i = start; i < start + count; i++) {
|
||||
@@ -434,7 +423,7 @@ async function simulatePaste(text: string): Promise<string> {
|
||||
return await page.evaluate(`window.result_${id}`);
|
||||
}
|
||||
|
||||
async function getCursor(): Promise<{col: number, row: number}> {
|
||||
async function getCursor(): Promise<{ col: number, row: number }> {
|
||||
return page.evaluate(`
|
||||
(function() {
|
||||
return {col: term.buffer.cursorX, row: term.buffer.cursorY};
|
||||
|
||||
+236
-247
File diff suppressed because it is too large
Load Diff
+2
-13
@@ -5,8 +5,7 @@
|
||||
|
||||
import * as puppeteer from 'puppeteer';
|
||||
import { assert } from 'chai';
|
||||
import { ITerminalOptions } from 'xterm';
|
||||
import { writeSync } from './TestUtils';
|
||||
import { writeSync, openTerminal } from './TestUtils';
|
||||
|
||||
const APP = 'http://127.0.0.1:3000/test';
|
||||
|
||||
@@ -24,7 +23,7 @@ describe('Parser Integration Tests', function(): void {
|
||||
page = (await browser.pages())[0];
|
||||
await page.setViewport({ width, height });
|
||||
await page.goto(APP);
|
||||
await openTerminal();
|
||||
await openTerminal(page);
|
||||
});
|
||||
|
||||
after(async () => browser.close());
|
||||
@@ -110,13 +109,3 @@ describe('Parser Integration Tests', function(): void {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
async function openTerminal(options: ITerminalOptions = {}): Promise<void> {
|
||||
await page.evaluate(`window.term = new Terminal(${JSON.stringify(options)})`);
|
||||
await page.evaluate(`window.term.open(document.querySelector('#terminal-container'))`);
|
||||
if (options.rendererType === 'dom') {
|
||||
await page.waitForSelector('.xterm-rows');
|
||||
} else {
|
||||
await page.waitForSelector('.xterm-text-layer');
|
||||
}
|
||||
}
|
||||
|
||||
+43
-54
@@ -5,8 +5,7 @@
|
||||
|
||||
import * as puppeteer from 'puppeteer';
|
||||
import { assert } from 'chai';
|
||||
import { ITerminalOptions } from 'xterm';
|
||||
import { pollFor, timeout, writeSync } from './TestUtils';
|
||||
import { pollFor, timeout, writeSync, openTerminal } from './TestUtils';
|
||||
|
||||
const APP = 'http://127.0.0.1:3000/test';
|
||||
|
||||
@@ -29,13 +28,13 @@ describe('API Integration Tests', function(): void {
|
||||
beforeEach(async () => page.goto(APP));
|
||||
|
||||
it('Default options', async () => {
|
||||
await openTerminal();
|
||||
await openTerminal(page);
|
||||
assert.equal(await page.evaluate(`window.term.cols`), 80);
|
||||
assert.equal(await page.evaluate(`window.term.rows`), 24);
|
||||
});
|
||||
|
||||
it('write', async () => {
|
||||
await openTerminal();
|
||||
await openTerminal(page);
|
||||
await page.evaluate(`
|
||||
window.term.write('foo');
|
||||
window.term.write('bar');
|
||||
@@ -45,7 +44,7 @@ describe('API Integration Tests', function(): void {
|
||||
});
|
||||
|
||||
it('write with callback', async () => {
|
||||
await openTerminal();
|
||||
await openTerminal(page);
|
||||
await page.evaluate(`
|
||||
window.term.write('foo', () => { window.__x = 'a'; });
|
||||
window.term.write('bar', () => { window.__x += 'b'; });
|
||||
@@ -56,7 +55,7 @@ describe('API Integration Tests', function(): void {
|
||||
});
|
||||
|
||||
it('write - bytes (UTF8)', async () => {
|
||||
await openTerminal();
|
||||
await openTerminal(page);
|
||||
await page.evaluate(`
|
||||
// foo
|
||||
window.term.write(new Uint8Array([102, 111, 111]));
|
||||
@@ -69,7 +68,7 @@ describe('API Integration Tests', function(): void {
|
||||
});
|
||||
|
||||
it('write - bytes (UTF8) with callback', async () => {
|
||||
await openTerminal();
|
||||
await openTerminal(page);
|
||||
await page.evaluate(`
|
||||
// foo
|
||||
window.term.write(new Uint8Array([102, 111, 111]), () => { window.__x = 'A'; });
|
||||
@@ -83,7 +82,7 @@ describe('API Integration Tests', function(): void {
|
||||
});
|
||||
|
||||
it('writeln', async () => {
|
||||
await openTerminal();
|
||||
await openTerminal(page);
|
||||
await page.evaluate(`
|
||||
window.term.writeln('foo');
|
||||
window.term.writeln('bar');
|
||||
@@ -95,7 +94,7 @@ describe('API Integration Tests', function(): void {
|
||||
});
|
||||
|
||||
it('writeln with callback', async () => {
|
||||
await openTerminal();
|
||||
await openTerminal(page);
|
||||
await page.evaluate(`
|
||||
window.term.writeln('foo', () => { window.__x = '1'; });
|
||||
window.term.writeln('bar', () => { window.__x += '2'; });
|
||||
@@ -108,7 +107,7 @@ describe('API Integration Tests', function(): void {
|
||||
});
|
||||
|
||||
it('writeln - bytes (UTF8)', async () => {
|
||||
await openTerminal();
|
||||
await openTerminal(page);
|
||||
await page.evaluate(`
|
||||
window.term.writeln(new Uint8Array([102, 111, 111]));
|
||||
window.term.writeln(new Uint8Array([98, 97, 114]));
|
||||
@@ -120,7 +119,7 @@ describe('API Integration Tests', function(): void {
|
||||
});
|
||||
|
||||
it('paste', async () => {
|
||||
await openTerminal();
|
||||
await openTerminal(page);
|
||||
await page.evaluate(`
|
||||
window.calls = [];
|
||||
window.term.onData(e => calls.push(e));
|
||||
@@ -134,7 +133,7 @@ describe('API Integration Tests', function(): void {
|
||||
});
|
||||
|
||||
it('clear', async () => {
|
||||
await openTerminal({ rows: 5 });
|
||||
await openTerminal(page, { rows: 5 });
|
||||
await page.evaluate(`
|
||||
window.term.write('test0');
|
||||
window.parsed = 0;
|
||||
@@ -152,7 +151,7 @@ describe('API Integration Tests', function(): void {
|
||||
});
|
||||
|
||||
it('getOption, setOption', async () => {
|
||||
await openTerminal();
|
||||
await openTerminal(page);
|
||||
assert.equal(await page.evaluate(`window.term.getOption('rendererType')`), 'canvas');
|
||||
await page.evaluate(`window.term.setOption('rendererType', 'dom')`);
|
||||
assert.equal(await page.evaluate(`window.term.getOption('rendererType')`), 'dom');
|
||||
@@ -160,7 +159,7 @@ describe('API Integration Tests', function(): void {
|
||||
|
||||
describe('renderer', () => {
|
||||
it('foreground', async () => {
|
||||
await openTerminal({ rendererType: 'dom' });
|
||||
await openTerminal(page, { rendererType: 'dom' });
|
||||
await writeSync(page, '\\x1b[30m0\\x1b[31m1\\x1b[32m2\\x1b[33m3\\x1b[34m4\\x1b[35m5\\x1b[36m6\\x1b[37m7');
|
||||
await pollFor(page, `document.querySelectorAll('.xterm-rows > :nth-child(1) > *').length`, 9);
|
||||
assert.deepEqual(await page.evaluate(`
|
||||
@@ -185,7 +184,7 @@ describe('API Integration Tests', function(): void {
|
||||
});
|
||||
|
||||
it('background', async () => {
|
||||
await openTerminal({ rendererType: 'dom' });
|
||||
await openTerminal(page, { rendererType: 'dom' });
|
||||
await writeSync(page, '\\x1b[40m0\\x1b[41m1\\x1b[42m2\\x1b[43m3\\x1b[44m4\\x1b[45m5\\x1b[46m6\\x1b[47m7');
|
||||
await pollFor(page, `document.querySelectorAll('.xterm-rows > :nth-child(1) > *').length`, 9);
|
||||
assert.deepEqual(await page.evaluate(`
|
||||
@@ -211,7 +210,7 @@ describe('API Integration Tests', function(): void {
|
||||
});
|
||||
|
||||
it('selection', async () => {
|
||||
await openTerminal({ rows: 5, cols: 5 });
|
||||
await openTerminal(page, { rows: 5, cols: 5 });
|
||||
await page.evaluate(`window.term.write('\\n\\nfoo\\n\\n\\rbar\\n\\n\\rbaz')`);
|
||||
assert.equal(await page.evaluate(`window.term.hasSelection()`), false);
|
||||
assert.equal(await page.evaluate(`window.term.getSelection()`), '');
|
||||
@@ -231,7 +230,7 @@ describe('API Integration Tests', function(): void {
|
||||
});
|
||||
|
||||
it('focus, blur', async () => {
|
||||
await openTerminal();
|
||||
await openTerminal(page);
|
||||
assert.equal(await page.evaluate(`document.activeElement.className`), '');
|
||||
await page.evaluate(`window.term.focus()`);
|
||||
assert.equal(await page.evaluate(`document.activeElement.className`), 'xterm-helper-textarea');
|
||||
@@ -241,7 +240,7 @@ describe('API Integration Tests', function(): void {
|
||||
|
||||
describe('loadAddon', () => {
|
||||
it('constructor', async () => {
|
||||
await openTerminal({ cols: 5 });
|
||||
await openTerminal(page, { cols: 5 });
|
||||
await page.evaluate(`
|
||||
window.cols = 0;
|
||||
window.term.loadAddon({
|
||||
@@ -253,7 +252,7 @@ describe('API Integration Tests', function(): void {
|
||||
});
|
||||
|
||||
it('dispose (addon)', async () => {
|
||||
await openTerminal();
|
||||
await openTerminal(page);
|
||||
await page.evaluate(`
|
||||
window.disposeCalled = false
|
||||
window.addon = {
|
||||
@@ -268,7 +267,7 @@ describe('API Integration Tests', function(): void {
|
||||
});
|
||||
|
||||
it('dispose (terminal)', async () => {
|
||||
await openTerminal();
|
||||
await openTerminal(page);
|
||||
await page.evaluate(`
|
||||
window.disposeCalled = false
|
||||
window.term.loadAddon({
|
||||
@@ -284,7 +283,7 @@ describe('API Integration Tests', function(): void {
|
||||
|
||||
describe('Events', () => {
|
||||
it('onCursorMove', async () => {
|
||||
await openTerminal();
|
||||
await openTerminal(page);
|
||||
await page.evaluate(`
|
||||
window.callCount = 0;
|
||||
window.term.onCursorMove(e => window.callCount++);
|
||||
@@ -296,7 +295,7 @@ describe('API Integration Tests', function(): void {
|
||||
});
|
||||
|
||||
it('onData', async () => {
|
||||
await openTerminal();
|
||||
await openTerminal(page);
|
||||
await page.evaluate(`
|
||||
window.calls = [];
|
||||
window.term.onData(e => calls.push(e));
|
||||
@@ -306,7 +305,7 @@ describe('API Integration Tests', function(): void {
|
||||
});
|
||||
|
||||
it('onKey', async () => {
|
||||
await openTerminal();
|
||||
await openTerminal(page);
|
||||
await page.evaluate(`
|
||||
window.calls = [];
|
||||
window.term.onKey(e => calls.push(e.key));
|
||||
@@ -316,7 +315,7 @@ describe('API Integration Tests', function(): void {
|
||||
});
|
||||
|
||||
it('onLineFeed', async () => {
|
||||
await openTerminal();
|
||||
await openTerminal(page);
|
||||
await page.evaluate(`
|
||||
window.callCount = 0;
|
||||
window.term.onLineFeed(() => callCount++);
|
||||
@@ -328,7 +327,7 @@ describe('API Integration Tests', function(): void {
|
||||
});
|
||||
|
||||
it('onScroll', async () => {
|
||||
await openTerminal({ rows: 5 });
|
||||
await openTerminal(page, { rows: 5 });
|
||||
await page.evaluate(`
|
||||
window.calls = [];
|
||||
window.term.onScroll(e => window.calls.push(e));
|
||||
@@ -344,7 +343,7 @@ describe('API Integration Tests', function(): void {
|
||||
});
|
||||
|
||||
it('onSelectionChange', async () => {
|
||||
await openTerminal();
|
||||
await openTerminal(page);
|
||||
await page.evaluate(`
|
||||
window.callCount = 0;
|
||||
window.term.onSelectionChange(() => window.callCount++);
|
||||
@@ -356,9 +355,9 @@ describe('API Integration Tests', function(): void {
|
||||
await pollFor(page, `window.callCount`, 2);
|
||||
});
|
||||
|
||||
it('onRender', async function (): Promise<void> {
|
||||
it('onRender', async function(): Promise<void> {
|
||||
this.retries(3);
|
||||
await openTerminal();
|
||||
await openTerminal(page);
|
||||
await timeout(20); // Ensure all init events are fired
|
||||
await page.evaluate(`
|
||||
window.calls = [];
|
||||
@@ -372,7 +371,7 @@ describe('API Integration Tests', function(): void {
|
||||
});
|
||||
|
||||
it('onResize', async () => {
|
||||
await openTerminal();
|
||||
await openTerminal(page);
|
||||
await timeout(20); // Ensure all init events are fired
|
||||
await page.evaluate(`
|
||||
window.calls = [];
|
||||
@@ -386,7 +385,7 @@ describe('API Integration Tests', function(): void {
|
||||
});
|
||||
|
||||
it('onTitleChange', async () => {
|
||||
await openTerminal();
|
||||
await openTerminal(page);
|
||||
await page.evaluate(`
|
||||
window.calls = [];
|
||||
window.term.onTitleChange(e => window.calls.push(e));
|
||||
@@ -399,7 +398,7 @@ describe('API Integration Tests', function(): void {
|
||||
|
||||
describe('buffer', () => {
|
||||
it('cursorX, cursorY', async () => {
|
||||
await openTerminal({ rows: 5, cols: 5 });
|
||||
await openTerminal(page, { rows: 5, cols: 5 });
|
||||
assert.equal(await page.evaluate(`window.term.buffer.cursorX`), 0);
|
||||
assert.equal(await page.evaluate(`window.term.buffer.cursorY`), 0);
|
||||
await writeSync(page, 'foo');
|
||||
@@ -420,7 +419,7 @@ describe('API Integration Tests', function(): void {
|
||||
});
|
||||
|
||||
it('viewportY', async () => {
|
||||
await openTerminal({ rows: 5 });
|
||||
await openTerminal(page, { rows: 5 });
|
||||
assert.equal(await page.evaluate(`window.term.buffer.viewportY`), 0);
|
||||
await writeSync(page, '\\n\\n\\n\\n');
|
||||
assert.equal(await page.evaluate(`window.term.buffer.viewportY`), 0);
|
||||
@@ -435,7 +434,7 @@ describe('API Integration Tests', function(): void {
|
||||
});
|
||||
|
||||
it('baseY', async () => {
|
||||
await openTerminal({ rows: 5 });
|
||||
await openTerminal(page, { rows: 5 });
|
||||
assert.equal(await page.evaluate(`window.term.buffer.baseY`), 0);
|
||||
await writeSync(page, '\\n\\n\\n\\n');
|
||||
assert.equal(await page.evaluate(`window.term.buffer.baseY`), 0);
|
||||
@@ -450,7 +449,7 @@ describe('API Integration Tests', function(): void {
|
||||
});
|
||||
|
||||
it('length', async () => {
|
||||
await openTerminal({ rows: 5 });
|
||||
await openTerminal(page, { rows: 5 });
|
||||
assert.equal(await page.evaluate(`window.term.buffer.length`), 5);
|
||||
await writeSync(page, '\\n\\n\\n\\n');
|
||||
assert.equal(await page.evaluate(`window.term.buffer.length`), 5);
|
||||
@@ -462,13 +461,13 @@ describe('API Integration Tests', function(): void {
|
||||
|
||||
describe('getLine', () => {
|
||||
it('invalid index', async () => {
|
||||
await openTerminal({ rows: 5 });
|
||||
await openTerminal(page, { rows: 5 });
|
||||
assert.equal(await page.evaluate(`window.term.buffer.getLine(-1)`), undefined);
|
||||
assert.equal(await page.evaluate(`window.term.buffer.getLine(5)`), undefined);
|
||||
});
|
||||
|
||||
it('isWrapped', async () => {
|
||||
await openTerminal({ cols: 5 });
|
||||
await openTerminal(page, { cols: 5 });
|
||||
assert.equal(await page.evaluate(`window.term.buffer.getLine(0).isWrapped`), false);
|
||||
assert.equal(await page.evaluate(`window.term.buffer.getLine(1).isWrapped`), false);
|
||||
await writeSync(page, 'abcde');
|
||||
@@ -480,7 +479,7 @@ describe('API Integration Tests', function(): void {
|
||||
});
|
||||
|
||||
it('translateToString', async () => {
|
||||
await openTerminal({ cols: 5 });
|
||||
await openTerminal(page, { cols: 5 });
|
||||
assert.equal(await page.evaluate(`window.term.buffer.getLine(0).translateToString()`), ' ');
|
||||
assert.equal(await page.evaluate(`window.term.buffer.getLine(0).translateToString(true)`), '');
|
||||
await writeSync(page, 'foo');
|
||||
@@ -495,7 +494,7 @@ describe('API Integration Tests', function(): void {
|
||||
});
|
||||
|
||||
it('getCell', async () => {
|
||||
await openTerminal({ cols: 5 });
|
||||
await openTerminal(page, { cols: 5 });
|
||||
assert.equal(await page.evaluate(`window.term.buffer.getLine(0).getCell(-1)`), undefined);
|
||||
assert.equal(await page.evaluate(`window.term.buffer.getLine(0).getCell(5)`), undefined);
|
||||
assert.equal(await page.evaluate(`window.term.buffer.getLine(0).getCell(0).getChars()`), '');
|
||||
@@ -520,14 +519,14 @@ describe('API Integration Tests', function(): void {
|
||||
});
|
||||
|
||||
it('dispose (opened)', async () => {
|
||||
await openTerminal();
|
||||
await openTerminal(page);
|
||||
await page.evaluate(`window.term.dispose()`);
|
||||
assert.equal(await page.evaluate(`window.term._core._isDisposed`), true);
|
||||
});
|
||||
|
||||
describe('registerLinkProvider', () => {
|
||||
it('should fire provideLink when hovering cells', async () => {
|
||||
await openTerminal({ rendererType: 'dom' });
|
||||
await openTerminal(page, { rendererType: 'dom' });
|
||||
await page.evaluate(`
|
||||
window.calls = [];
|
||||
window.disposable = window.term.registerLinkProvider({
|
||||
@@ -546,7 +545,7 @@ describe('API Integration Tests', function(): void {
|
||||
});
|
||||
|
||||
it('should fire hover and leave events on the link', async () => {
|
||||
await openTerminal({ rendererType: 'dom' });
|
||||
await openTerminal(page, { rendererType: 'dom' });
|
||||
await writeSync(page, 'foo bar baz');
|
||||
// Wait for renderer to catch up as links are cleared on render
|
||||
await pollFor(page, `document.querySelector('.xterm-rows').textContent`, 'foo bar baz ');
|
||||
@@ -581,7 +580,7 @@ describe('API Integration Tests', function(): void {
|
||||
});
|
||||
|
||||
it('should work fine when hover and leave callbacks are not provided', async () => {
|
||||
await openTerminal({ rendererType: 'dom' });
|
||||
await openTerminal(page, { rendererType: 'dom' });
|
||||
await writeSync(page, 'foo bar baz');
|
||||
// Wait for renderer to catch up as links are cleared on render
|
||||
await pollFor(page, `document.querySelector('.xterm-rows').textContent`, 'foo bar baz ');
|
||||
@@ -614,7 +613,7 @@ describe('API Integration Tests', function(): void {
|
||||
});
|
||||
|
||||
it('should fire activate events when clicking the link', async () => {
|
||||
await openTerminal({ rendererType: 'dom' });
|
||||
await openTerminal(page, { rendererType: 'dom' });
|
||||
await writeSync(page, 'a b c');
|
||||
|
||||
// Wait for renderer to catch up as links are cleared on render
|
||||
@@ -662,16 +661,6 @@ describe('API Integration Tests', function(): void {
|
||||
});
|
||||
});
|
||||
|
||||
async function openTerminal(options: ITerminalOptions = {}): Promise<void> {
|
||||
await page.evaluate(`window.term = new Terminal(${JSON.stringify(options)})`);
|
||||
await page.evaluate(`window.term.open(document.querySelector('#terminal-container'))`);
|
||||
if (options.rendererType === 'dom') {
|
||||
await page.waitForSelector('.xterm-rows');
|
||||
} else {
|
||||
await page.waitForSelector('.xterm-text-layer');
|
||||
}
|
||||
}
|
||||
|
||||
interface IDimensions {
|
||||
top: number;
|
||||
left: number;
|
||||
@@ -713,7 +702,7 @@ async function getCellCoordinates(dimensions: IDimensions, col: number, row: num
|
||||
};
|
||||
}
|
||||
|
||||
async function moveMouseCell(page: puppeteer.Page, dimensions: IDimensions, col: number, row: number) {
|
||||
async function moveMouseCell(page: puppeteer.Page, dimensions: IDimensions, col: number, row: number): Promise<void> {
|
||||
const coords = await getCellCoordinates(dimensions, col, row);
|
||||
await page.mouse.move(coords.x, coords.y);
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
import * as puppeteer from 'puppeteer';
|
||||
import deepEqual = require('deep-equal');
|
||||
import { ITerminalOptions } from 'xterm';
|
||||
|
||||
export async function pollFor<T>(page: puppeteer.Page, evalOrFn: string | (() => Promise<T>), val: T, preFn?: () => Promise<void>): Promise<void> {
|
||||
if (preFn) {
|
||||
@@ -29,3 +30,13 @@ export async function writeSync(page: puppeteer.Page, data: string): Promise<voi
|
||||
export async function timeout(ms: number): Promise<void> {
|
||||
return new Promise<void>(r => setTimeout(r, ms));
|
||||
}
|
||||
|
||||
export async function openTerminal(page: puppeteer.Page, options: ITerminalOptions = {}): Promise<void> {
|
||||
await page.evaluate(`window.term = new Terminal(${JSON.stringify(options)})`);
|
||||
await page.evaluate(`window.term.open(document.querySelector('#terminal-container'))`);
|
||||
if (options.rendererType === 'dom') {
|
||||
await page.waitForSelector('.xterm-rows');
|
||||
} else {
|
||||
await page.waitForSelector('.xterm-text-layer');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user