mirror of
https://github.com/wavetermdev/xterm.js.git
synced 2026-08-05 13:43:48 -07:00
Fix timing issues in char width test
This commit is contained in:
@@ -4,7 +4,6 @@
|
||||
*/
|
||||
|
||||
import * as puppeteer from 'puppeteer';
|
||||
import { assert } from 'chai';
|
||||
import { ITerminalOptions } from '../../../src/Types';
|
||||
import { ITheme } from 'xterm';
|
||||
|
||||
@@ -15,7 +14,7 @@ let page: puppeteer.Page;
|
||||
const width = 800;
|
||||
const height = 600;
|
||||
|
||||
describe.only('WebGL Renderer Integration Tests', function(): void {
|
||||
describe('WebGL Renderer Integration Tests', function(): void {
|
||||
before(async function(): Promise<any> {
|
||||
browser = await puppeteer.launch({
|
||||
headless: process.argv.indexOf('--headless') !== -1,
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
*/
|
||||
|
||||
import * as puppeteer from 'puppeteer';
|
||||
import { assert } from 'chai';
|
||||
import { ITerminalOptions } from 'xterm';
|
||||
import { pollFor } from './TestUtils';
|
||||
|
||||
const APP = 'http://127.0.0.1:3000/test';
|
||||
|
||||
@@ -15,12 +15,9 @@ const width = 800;
|
||||
const height = 600;
|
||||
|
||||
describe('CharWidth Integration Tests', function(): void {
|
||||
this.timeout(20000);
|
||||
|
||||
before(async function(): Promise<any> {
|
||||
browser = await puppeteer.launch({
|
||||
headless: process.argv.indexOf('--headless') !== -1,
|
||||
slowMo: 0,
|
||||
args: [`--window-size=${width},${height}`, `--no-sandbox`]
|
||||
});
|
||||
page = (await browser.pages())[0];
|
||||
@@ -41,37 +38,37 @@ describe('CharWidth Integration Tests', function(): void {
|
||||
it('ASCII chars', async function(): Promise<void> {
|
||||
const input = 'This is just ASCII text.#';
|
||||
await page.evaluate(`window.term.write('${input}')`);
|
||||
assert.equal(25, await sumWidths(0, 1, '#'));
|
||||
await pollFor(page, () => sumWidths(0, 1, '#'), 25);
|
||||
});
|
||||
|
||||
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}')`);
|
||||
assert.equal(10, await sumWidths(0, 1, '#'));
|
||||
await pollFor(page, () => sumWidths(0, 1, '#'), 10);
|
||||
});
|
||||
|
||||
it('surrogate chars', async function(): Promise<void> {
|
||||
const input = 'πππππππππππππππππππππππππππ#';
|
||||
await page.evaluate(`window.term.write('${input}')`);
|
||||
assert.equal(28, await sumWidths(0, 1, '#'));
|
||||
await pollFor(page, () => sumWidths(0, 1, '#'), 28);
|
||||
});
|
||||
|
||||
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}')`);
|
||||
assert.equal(12, await sumWidths(0, 1, '#'));
|
||||
await pollFor(page, () => sumWidths(0, 1, '#'), 12);
|
||||
});
|
||||
|
||||
it('fullwidth chars', async function(): Promise<void> {
|
||||
const input = 'οΌοΌοΌοΌοΌοΌοΌοΌοΌοΌ#';
|
||||
await page.evaluate(`window.term.write('${input}')`);
|
||||
assert.equal(21, await sumWidths(0, 1, '#'));
|
||||
await pollFor(page, () => sumWidths(0, 1, '#'), 21);
|
||||
});
|
||||
|
||||
it('fullwidth chars offset 1', async function(): Promise<void> {
|
||||
const input = 'aοΌοΌοΌοΌοΌοΌοΌοΌοΌοΌ#';
|
||||
await page.evaluate(`window.term.write('${input}')`);
|
||||
assert.equal(22, await sumWidths(0, 1, '#'));
|
||||
await pollFor(page, () => sumWidths(0, 1, '#'), 22);
|
||||
});
|
||||
|
||||
// TODO: multiline tests once #1685 is resolved
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
/**
|
||||
* Copyright (c) 2019 The xterm.js authors. All rights reserved.
|
||||
* @license MIT
|
||||
*/
|
||||
|
||||
import * as puppeteer from 'puppeteer';
|
||||
|
||||
export async function pollFor<T>(page: puppeteer.Page, evalOrFn: string | (() => Promise<T>), val: T, preFn?: () => Promise<void>): Promise<void> {
|
||||
if (preFn) {
|
||||
await preFn();
|
||||
}
|
||||
const result = typeof evalOrFn === 'string' ? await page.evaluate(evalOrFn) : await evalOrFn();
|
||||
let equal = false;
|
||||
if (typeof result === 'object') {
|
||||
equal = Object.keys(result).every(e => result[e] === (val as any)[e]);
|
||||
} else {
|
||||
equal = result === val;
|
||||
}
|
||||
if (!equal) {
|
||||
return new Promise<void>(r => {
|
||||
setTimeout(() => r(pollFor(page, evalOrFn, val, preFn)), 10);
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user