Fix timing issues in char width test

This commit is contained in:
Daniel Imms
2019-11-09 14:12:46 -08:00
parent b0c0f8701e
commit 74f04ae92e
3 changed files with 32 additions and 12 deletions
+7 -10
View File
@@ -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
+24
View File
@@ -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);
});
}
}