mirror of
https://github.com/wavetermdev/xterm.js.git
synced 2026-08-05 13:43:48 -07:00
Use playwright instead of puppeteer
This commit is contained in:
+14
-14
@@ -3,24 +3,24 @@
|
||||
* @license MIT
|
||||
*/
|
||||
|
||||
import * as puppeteer from 'puppeteer';
|
||||
import { ITerminalOptions } from 'xterm';
|
||||
import { pollFor } from './TestUtils';
|
||||
import { pollFor, getBrowserType } from './TestUtils';
|
||||
import { Browser, Page } from 'playwright';
|
||||
|
||||
const APP = 'http://127.0.0.1:3000/test';
|
||||
|
||||
let browser: puppeteer.Browser;
|
||||
let page: puppeteer.Page;
|
||||
let browser: Browser;
|
||||
let page: Page;
|
||||
const width = 800;
|
||||
const height = 600;
|
||||
|
||||
describe('CharWidth Integration Tests', function(): void {
|
||||
before(async function(): Promise<any> {
|
||||
browser = await puppeteer.launch({
|
||||
describe('CharWidth Integration Tests', function (): void {
|
||||
before(async function (): Promise<any> {
|
||||
browser = await getBrowserType().launch({
|
||||
headless: process.argv.indexOf('--headless') !== -1,
|
||||
args: [`--window-size=${width},${height}`, `--no-sandbox`]
|
||||
});
|
||||
page = (await browser.pages())[0];
|
||||
page = (await browser.defaultContext().pages())[0];
|
||||
await page.setViewport({ width, height });
|
||||
await page.goto(APP);
|
||||
await openTerminal({ rows: 5, cols: 30 });
|
||||
@@ -35,37 +35,37 @@ describe('CharWidth Integration Tests', function(): void {
|
||||
await page.evaluate(`window.term.reset()`);
|
||||
});
|
||||
|
||||
it('ASCII chars', async function(): Promise<void> {
|
||||
it('ASCII chars', async function (): Promise<void> {
|
||||
const input = 'This is just ASCII text.#';
|
||||
await page.evaluate(`window.term.write('${input}')`);
|
||||
await pollFor(page, () => sumWidths(0, 1, '#'), 25);
|
||||
});
|
||||
|
||||
it('combining chars', async function(): Promise<void> {
|
||||
it('combining chars', async function (): Promise<void> {
|
||||
const input = 'e\u0301e\u0301e\u0301e\u0301e\u0301e\u0301e\u0301e\u0301e\u0301#';
|
||||
await page.evaluate(`window.term.write('${input}')`);
|
||||
await pollFor(page, () => sumWidths(0, 1, '#'), 10);
|
||||
});
|
||||
|
||||
it('surrogate chars', async function(): Promise<void> {
|
||||
it('surrogate chars', async function (): Promise<void> {
|
||||
const input = '𝄞𝄞𝄞𝄞𝄞𝄞𝄞𝄞𝄞𝄞𝄞𝄞𝄞𝄞𝄞𝄞𝄞𝄞𝄞𝄞𝄞𝄞𝄞𝄞𝄞𝄞𝄞#';
|
||||
await page.evaluate(`window.term.write('${input}')`);
|
||||
await pollFor(page, () => sumWidths(0, 1, '#'), 28);
|
||||
});
|
||||
|
||||
it('surrogate combining chars', async function(): Promise<void> {
|
||||
it('surrogate combining chars', async function (): Promise<void> {
|
||||
const input = '𓂀\u0301𓂀\u0301𓂀\u0301𓂀\u0301𓂀\u0301𓂀\u0301𓂀\u0301𓂀\u0301𓂀\u0301𓂀\u0301𓂀\u0301#';
|
||||
await page.evaluate(`window.term.write('${input}')`);
|
||||
await pollFor(page, () => sumWidths(0, 1, '#'), 12);
|
||||
});
|
||||
|
||||
it('fullwidth chars', async function(): Promise<void> {
|
||||
it('fullwidth chars', async function (): Promise<void> {
|
||||
const input = '1234567890#';
|
||||
await page.evaluate(`window.term.write('${input}')`);
|
||||
await pollFor(page, () => sumWidths(0, 1, '#'), 21);
|
||||
});
|
||||
|
||||
it('fullwidth chars offset 1', async function(): Promise<void> {
|
||||
it('fullwidth chars offset 1', async function (): Promise<void> {
|
||||
const input = 'a1234567890#';
|
||||
await page.evaluate(`window.term.write('${input}')`);
|
||||
await pollFor(page, () => sumWidths(0, 1, '#'), 22);
|
||||
|
||||
@@ -3,25 +3,25 @@
|
||||
* @license MIT
|
||||
*/
|
||||
|
||||
import * as puppeteer from 'puppeteer';
|
||||
import { assert } from 'chai';
|
||||
import { ITerminalOptions } from 'xterm';
|
||||
import { pollFor } from './TestUtils';
|
||||
import { pollFor, getBrowserType } from './TestUtils';
|
||||
import { Page, Browser } from 'playwright';
|
||||
|
||||
const APP = 'http://127.0.0.1:3000/test';
|
||||
|
||||
let browser: puppeteer.Browser;
|
||||
let page: puppeteer.Page;
|
||||
let browser: Browser;
|
||||
let page: Page;
|
||||
const width = 800;
|
||||
const height = 600;
|
||||
|
||||
describe('InputHandler Integration Tests', function(): void {
|
||||
before(async function(): Promise<any> {
|
||||
browser = await puppeteer.launch({
|
||||
describe('InputHandler Integration Tests', function (): void {
|
||||
before(async function (): Promise<any> {
|
||||
browser = await getBrowserType().launch({
|
||||
headless: process.argv.indexOf('--headless') !== -1,
|
||||
args: [`--window-size=${width},${height}`, `--no-sandbox`]
|
||||
});
|
||||
page = (await browser.pages())[0];
|
||||
page = (await browser.defaultContext().pages())[0];
|
||||
await page.setViewport({ width, height });
|
||||
await page.goto(APP);
|
||||
await openTerminal();
|
||||
@@ -36,7 +36,7 @@ describe('InputHandler Integration Tests', function(): void {
|
||||
await page.evaluate(`window.term.reset()`);
|
||||
});
|
||||
|
||||
it('ICH: Insert Ps (Blank) Character(s) (default = 1) - CSI Ps @', async function(): Promise<any> {
|
||||
it('ICH: Insert Ps (Blank) Character(s) (default = 1) - CSI Ps @', async function (): Promise<any> {
|
||||
await page.evaluate(`
|
||||
// Default
|
||||
window.term.write('foo\\x1b[3D\\x1b[@\\n\\r')
|
||||
@@ -46,7 +46,7 @@ describe('InputHandler Integration Tests', function(): void {
|
||||
await pollFor(page, () => getLinesAsArray(2), [' foo', ' bar']);
|
||||
});
|
||||
|
||||
it('CUU: Cursor Up Ps Times (default = 1) - CSI Ps A', async function(): Promise<any> {
|
||||
it('CUU: Cursor Up Ps Times (default = 1) - CSI Ps A', async function (): Promise<any> {
|
||||
await page.evaluate(`
|
||||
// Default
|
||||
window.term.write('\\n\\n\\n\\n\x1b[Aa')
|
||||
@@ -56,7 +56,7 @@ describe('InputHandler Integration Tests', function(): void {
|
||||
await pollFor(page, () => getLinesAsArray(4), ['', ' b', '', 'a']);
|
||||
});
|
||||
|
||||
it('CUD: Cursor Down Ps Times (default = 1) - CSI Ps B', async function(): Promise<any> {
|
||||
it('CUD: Cursor Down Ps Times (default = 1) - CSI Ps B', async function (): Promise<any> {
|
||||
await page.evaluate(`
|
||||
// Default
|
||||
window.term.write('\x1b[Ba')
|
||||
@@ -66,7 +66,7 @@ describe('InputHandler Integration Tests', function(): void {
|
||||
await pollFor(page, () => getLinesAsArray(4), ['', 'a', '', ' b']);
|
||||
});
|
||||
|
||||
it('CUF: Cursor Forward Ps Times (default = 1) - CSI Ps C', async function(): Promise<any> {
|
||||
it('CUF: Cursor Forward Ps Times (default = 1) - CSI Ps C', async function (): Promise<any> {
|
||||
await page.evaluate(`
|
||||
// Default
|
||||
window.term.write('\x1b[Ca')
|
||||
@@ -76,7 +76,7 @@ describe('InputHandler Integration Tests', function(): void {
|
||||
await pollFor(page, () => getLinesAsArray(1), [' a b']);
|
||||
});
|
||||
|
||||
it('CUB: Cursor Backward Ps Times (default = 1) - CSI Ps D', async function(): Promise<any> {
|
||||
it('CUB: Cursor Backward Ps Times (default = 1) - CSI Ps D', async function (): Promise<any> {
|
||||
await page.evaluate(`
|
||||
// Default
|
||||
window.term.write('foo\x1b[Da')
|
||||
@@ -86,7 +86,7 @@ describe('InputHandler Integration Tests', function(): void {
|
||||
await pollFor(page, () => getLinesAsArray(1), ['fba']);
|
||||
});
|
||||
|
||||
it('CNL: Cursor Next Line Ps Times (default = 1) - CSI Ps E', async function(): Promise<any> {
|
||||
it('CNL: Cursor Next Line Ps Times (default = 1) - CSI Ps E', async function (): Promise<any> {
|
||||
await page.evaluate(`
|
||||
// Default
|
||||
window.term.write('\x1b[Ea')
|
||||
@@ -96,7 +96,7 @@ describe('InputHandler Integration Tests', function(): void {
|
||||
await pollFor(page, () => getLinesAsArray(4), ['', 'a', '', 'b']);
|
||||
});
|
||||
|
||||
it('CPL: Cursor Preceding Line Ps Times (default = 1) - CSI Ps F', async function(): Promise<any> {
|
||||
it('CPL: Cursor Preceding Line Ps Times (default = 1) - CSI Ps F', async function (): Promise<any> {
|
||||
await page.evaluate(`
|
||||
// Default
|
||||
window.term.write('\\n\\n\\n\\n\x1b[Fa')
|
||||
@@ -106,7 +106,7 @@ describe('InputHandler Integration Tests', function(): void {
|
||||
await pollFor(page, () => getLinesAsArray(5), ['', 'b', '', 'a', '']);
|
||||
});
|
||||
|
||||
it('CHA: Cursor Character Absolute [column] (default = [row,1]) - CSI Ps G', async function(): Promise<any> {
|
||||
it('CHA: Cursor Character Absolute [column] (default = [row,1]) - CSI Ps G', async function (): Promise<any> {
|
||||
await page.evaluate(`
|
||||
// Default
|
||||
window.term.write('foo\x1b[Ga')
|
||||
@@ -116,7 +116,7 @@ describe('InputHandler Integration Tests', function(): void {
|
||||
await pollFor(page, () => getLinesAsArray(1), ['aoo b']);
|
||||
});
|
||||
|
||||
it('CUP: Cursor Position [row;column] (default = [1,1]) - CSI Ps ; Ps H', async function(): Promise<any> {
|
||||
it('CUP: Cursor Position [row;column] (default = [1,1]) - CSI Ps ; Ps H', async function (): Promise<any> {
|
||||
await page.evaluate(`
|
||||
// Default
|
||||
window.term.write('foo\x1b[Ha')
|
||||
@@ -126,7 +126,7 @@ describe('InputHandler Integration Tests', function(): void {
|
||||
await pollFor(page, () => getLinesAsArray(3), ['aoo', '', ' b']);
|
||||
});
|
||||
|
||||
it('CHT: Cursor Forward Tabulation Ps tab stops (default = 1) - CSI Ps I', async function(): Promise<any> {
|
||||
it('CHT: Cursor Forward Tabulation Ps tab stops (default = 1) - CSI Ps I', async function (): Promise<any> {
|
||||
await page.evaluate(`
|
||||
// Default
|
||||
window.term.write('\x1b[Ia')
|
||||
@@ -136,7 +136,7 @@ describe('InputHandler Integration Tests', function(): void {
|
||||
await pollFor(page, () => getLinesAsArray(2), [' a', ' b']);
|
||||
});
|
||||
|
||||
it('ED: Erase in Display, VT100 - CSI Ps J', async function(): Promise<any> {
|
||||
it('ED: Erase in Display, VT100 - CSI Ps J', async function (): Promise<any> {
|
||||
const fixture = 'abc\\n\\rdef\\n\\rghi\x1b[2;2H';
|
||||
await page.evaluate(`
|
||||
// Default: Erase Below
|
||||
@@ -165,7 +165,7 @@ describe('InputHandler Integration Tests', function(): void {
|
||||
await pollFor(page, () => getLinesAsArray(5), [' 4', ' 5', 'abc', 'def', 'ghi']);
|
||||
});
|
||||
|
||||
it('DECSED: Erase in Display, VT220 - CSI ? Ps J', async function(): Promise<any> {
|
||||
it('DECSED: Erase in Display, VT220 - CSI ? Ps J', async function (): Promise<any> {
|
||||
const fixture = 'abc\\n\\rdef\\n\\rghi\x1b[2;2H';
|
||||
await page.evaluate(`
|
||||
// Default: Erase Below
|
||||
@@ -194,7 +194,7 @@ describe('InputHandler Integration Tests', function(): void {
|
||||
await pollFor(page, () => getLinesAsArray(5), [' 4', ' 5', 'abc', 'def', 'ghi']);
|
||||
});
|
||||
|
||||
it('IL: Insert Ps Line(s) (default = 1) - CSI Ps L', async function(): Promise<any> {
|
||||
it('IL: Insert Ps Line(s) (default = 1) - CSI Ps L', async function (): Promise<any> {
|
||||
await page.evaluate(`
|
||||
// Default
|
||||
window.term.write('foo\x1b[La')
|
||||
@@ -204,7 +204,7 @@ describe('InputHandler Integration Tests', function(): void {
|
||||
await pollFor(page, () => getLinesAsArray(4), ['b', '', 'a', 'foo']);
|
||||
});
|
||||
|
||||
it('DL: Delete Ps Line(s) (default = 1) - CSI Ps M', async function(): Promise<any> {
|
||||
it('DL: Delete Ps Line(s) (default = 1) - CSI Ps M', async function (): Promise<any> {
|
||||
await page.evaluate(`
|
||||
// Default
|
||||
window.term.write('a\\nb\x1b[1F\x1b[M')
|
||||
@@ -214,7 +214,7 @@ describe('InputHandler Integration Tests', function(): void {
|
||||
await pollFor(page, () => getLinesAsArray(5), [' b', ' f', '', '', '']);
|
||||
});
|
||||
|
||||
it('DCH: Delete Ps Character(s) (default = 1) - CSI Ps P', async function(): Promise<any> {
|
||||
it('DCH: Delete Ps Character(s) (default = 1) - CSI Ps P', async function (): Promise<any> {
|
||||
await page.evaluate(`
|
||||
// Default
|
||||
window.term.write('abc\x1b[1;1H\x1b[P')
|
||||
@@ -225,7 +225,7 @@ describe('InputHandler Integration Tests', function(): void {
|
||||
});
|
||||
|
||||
describe('DSR: Device Status Report', () => {
|
||||
it('Status Report - CSI 5 n', async function(): Promise<any> {
|
||||
it('Status Report - CSI 5 n', async function (): Promise<any> {
|
||||
await page.evaluate(`
|
||||
window.term.onData(e => window.result = e);
|
||||
window.term.write('\\x1b[5n');
|
||||
@@ -233,7 +233,7 @@ describe('InputHandler Integration Tests', function(): void {
|
||||
await pollFor(page, () => page.evaluate(`window.result`), '\x1b[0n');
|
||||
});
|
||||
|
||||
it('Report Cursor Position (CPR) - CSI 6 n', async function(): Promise<any> {
|
||||
it('Report Cursor Position (CPR) - CSI 6 n', async function (): Promise<any> {
|
||||
await page.evaluate(`window.term.write('\\n\\nfoo')`);
|
||||
await pollFor(page, () => page.evaluate(`
|
||||
[window.term.buffer.cursorY, window.term.buffer.cursorX]
|
||||
@@ -245,7 +245,7 @@ describe('InputHandler Integration Tests', function(): void {
|
||||
await pollFor(page, () => page.evaluate(`window.result`), '\x1b[3;4R');
|
||||
});
|
||||
|
||||
it('Report Cursor Position (DECXCPR) - CSI ? 6 n', async function(): Promise<any> {
|
||||
it('Report Cursor Position (DECXCPR) - CSI ? 6 n', async function (): Promise<any> {
|
||||
await page.evaluate(`window.term.write('\\n\\nfoo')`);
|
||||
await pollFor(page, () => page.evaluate(`
|
||||
[window.term.buffer.cursorY, window.term.buffer.cursorX]
|
||||
@@ -260,8 +260,8 @@ 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() => {
|
||||
const coords = await page.evaluate(`
|
||||
it('Pm = 1003, Set Use All Motion (any event) Mouse Tracking', async () => {
|
||||
const coords: any = await page.evaluate(`
|
||||
(function() {
|
||||
const rect = window.term.element.getBoundingClientRect();
|
||||
return {left: rect.left, top: rect.top, bottom: rect.bottom, right: rect.right};
|
||||
@@ -271,7 +271,7 @@ describe('InputHandler Integration Tests', function(): void {
|
||||
await page.mouse.click((coords.left + coords.right) / 2, (coords.top + coords.bottom) / 2);
|
||||
await page.mouse.down();
|
||||
await page.mouse.move((coords.left + coords.right) / 2, (coords.top + coords.bottom) / 4);
|
||||
assert.ok(await page.evaluate(`window.term.getSelection().length`) > 0, 'mouse events are off so there should be a selection');
|
||||
assert.ok(await page.evaluate(`window.term.getSelection().length`) as number > 0, 'mouse events are off so there should be a selection');
|
||||
await page.mouse.up();
|
||||
// Clear selection
|
||||
await page.mouse.click((coords.left + coords.right) / 2, (coords.top + coords.bottom) / 2);
|
||||
@@ -286,7 +286,7 @@ describe('InputHandler Integration Tests', function(): void {
|
||||
await pollFor(page, () => page.evaluate(`window.term.getSelection().length`), 0);
|
||||
await page.mouse.up();
|
||||
});
|
||||
it('Pm = 2004, Set bracketed paste mode', async function(): Promise<any> {
|
||||
it('Pm = 2004, Set bracketed paste mode', async function (): Promise<any> {
|
||||
await pollFor(page, () => simulatePaste('foo'), 'foo');
|
||||
await page.evaluate(`window.term.write('\x1b[?2004h')`);
|
||||
await pollFor(page, () => simulatePaste('bar'), '\x1b[200~bar\x1b[201~');
|
||||
@@ -296,7 +296,7 @@ describe('InputHandler Integration Tests', function(): void {
|
||||
});
|
||||
});
|
||||
|
||||
it('REP: Repeat preceding character, ECMA48 - CSI Ps b', async function(): Promise<any> {
|
||||
it('REP: Repeat preceding character, ECMA48 - CSI Ps b', async function (): Promise<any> {
|
||||
// default to 1
|
||||
await page.evaluate(`
|
||||
window.term.resize(10, 10);
|
||||
@@ -309,7 +309,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 +347,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 () {
|
||||
await page.evaluate(`(() => {
|
||||
window._stack = [];
|
||||
const _h = window.term.onData(data => window._stack.push(data));
|
||||
@@ -360,7 +360,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 () {
|
||||
await page.evaluate(`window.term.setOption('windowOptions', {getWinSizePixels: true});`);
|
||||
await page.evaluate(`(() => {
|
||||
window._stack = [];
|
||||
@@ -371,7 +371,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 () {
|
||||
await page.evaluate(`window.term.setOption('windowOptions', {getCellSizePixels: true});`);
|
||||
await page.evaluate(`(() => {
|
||||
window._stack = [];
|
||||
@@ -397,7 +397,7 @@ 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 });
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -434,7 +434,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};
|
||||
@@ -443,7 +443,7 @@ async function getCursor(): Promise<{col: number, row: number}> {
|
||||
}
|
||||
|
||||
async function getDimensions(): Promise<any> {
|
||||
const dim = await page.evaluate(`term._core._renderService.dimensions`);
|
||||
const dim: any = await page.evaluate(`term._core._renderService.dimensions`);
|
||||
return {
|
||||
cellWidth: dim.actualCellWidth.toFixed(0),
|
||||
cellHeight: dim.actualCellHeight.toFixed(0),
|
||||
|
||||
+245
-245
File diff suppressed because it is too large
Load Diff
@@ -3,25 +3,25 @@
|
||||
* @license MIT
|
||||
*/
|
||||
|
||||
import * as puppeteer from 'puppeteer';
|
||||
import { assert } from 'chai';
|
||||
import { ITerminalOptions } from 'xterm';
|
||||
import { writeSync } from './TestUtils';
|
||||
import { writeSync, getBrowserType } from './TestUtils';
|
||||
import { Browser, Page } from 'playwright';
|
||||
|
||||
const APP = 'http://127.0.0.1:3000/test';
|
||||
|
||||
let browser: puppeteer.Browser;
|
||||
let page: puppeteer.Page;
|
||||
let browser: Browser;
|
||||
let page: Page;
|
||||
const width = 800;
|
||||
const height = 600;
|
||||
|
||||
describe('Parser Integration Tests', function(): void {
|
||||
before(async function(): Promise<any> {
|
||||
browser = await puppeteer.launch({
|
||||
describe('Parser Integration Tests', function (): void {
|
||||
before(async function (): Promise<any> {
|
||||
browser = await getBrowserType().launch({
|
||||
headless: process.argv.indexOf('--headless') !== -1,
|
||||
args: [`--window-size=${width},${height}`, `--no-sandbox`]
|
||||
});
|
||||
page = (await browser.pages())[0];
|
||||
page = (await browser.defaultContext().pages())[0];
|
||||
await page.setViewport({ width, height });
|
||||
await page.goto(APP);
|
||||
await openTerminal();
|
||||
|
||||
@@ -3,25 +3,25 @@
|
||||
* @license MIT
|
||||
*/
|
||||
|
||||
import * as puppeteer from 'puppeteer';
|
||||
import { assert } from 'chai';
|
||||
import { ITerminalOptions } from 'xterm';
|
||||
import { pollFor, timeout, writeSync } from './TestUtils';
|
||||
import { pollFor, timeout, writeSync, getBrowserType } from './TestUtils';
|
||||
import { Browser, Page } from 'playwright';
|
||||
|
||||
const APP = 'http://127.0.0.1:3000/test';
|
||||
|
||||
let browser: puppeteer.Browser;
|
||||
let page: puppeteer.Page;
|
||||
let browser: Browser;
|
||||
let page: Page;
|
||||
const width = 800;
|
||||
const height = 600;
|
||||
|
||||
describe('API Integration Tests', function(): void {
|
||||
describe('API Integration Tests', function (): void {
|
||||
before(async () => {
|
||||
browser = await puppeteer.launch({
|
||||
browser = await getBrowserType().launch({
|
||||
headless: process.argv.indexOf('--headless') !== -1,
|
||||
args: [`--window-size=${width},${height}`, `--no-sandbox`]
|
||||
});
|
||||
page = (await browser.pages())[0];
|
||||
page = (await browser.defaultContext().pages())[0];
|
||||
await page.setViewport({ width, height });
|
||||
});
|
||||
|
||||
@@ -713,7 +713,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: Page, dimensions: IDimensions, col: number, row: number) {
|
||||
const coords = await getCellCoordinates(dimensions, col, row);
|
||||
await page.mouse.move(coords.x, coords.y);
|
||||
}
|
||||
|
||||
+19
-3
@@ -3,10 +3,11 @@
|
||||
* @license MIT
|
||||
*/
|
||||
|
||||
import * as puppeteer from 'puppeteer';
|
||||
// import * as playwright from 'playwright';
|
||||
import * as playwright from 'playwright';
|
||||
import deepEqual = require('deep-equal');
|
||||
|
||||
export async function pollFor<T>(page: puppeteer.Page, evalOrFn: string | (() => Promise<T>), val: T, preFn?: () => Promise<void>): Promise<void> {
|
||||
export async function pollFor<T>(page: playwright.Page, evalOrFn: string | (() => Promise<T>), val: T, preFn?: () => Promise<void>): Promise<void> {
|
||||
if (preFn) {
|
||||
await preFn();
|
||||
}
|
||||
@@ -18,7 +19,7 @@ export async function pollFor<T>(page: puppeteer.Page, evalOrFn: string | (() =>
|
||||
}
|
||||
}
|
||||
|
||||
export async function writeSync(page: puppeteer.Page, data: string): Promise<void> {
|
||||
export async function writeSync(page: playwright.Page, data: string): Promise<void> {
|
||||
await page.evaluate(`
|
||||
window.ready = false;
|
||||
window.term.write('${data}', () => window.ready = true);
|
||||
@@ -29,3 +30,18 @@ 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 function getBrowserType(): playwright.BrowserType {
|
||||
// Default to chromium
|
||||
let browserType: playwright.BrowserType = playwright['chromium'];
|
||||
|
||||
const index = process.argv.indexOf('--browser');
|
||||
if (index !== -1 && process.argv.length > index + 2 && typeof process.argv[index + 1] === 'string') {
|
||||
const string = process.argv[index + 1];
|
||||
if (string === 'firefox' || string === 'webkit') {
|
||||
browserType = playwright[string];
|
||||
}
|
||||
}
|
||||
|
||||
return browserType;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user