Fix timing issues in char width test
This commit is contained in:
@@ -4,7 +4,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import * as puppeteer from 'puppeteer';
|
import * as puppeteer from 'puppeteer';
|
||||||
import { assert } from 'chai';
|
|
||||||
import { ITerminalOptions } from '../../../src/Types';
|
import { ITerminalOptions } from '../../../src/Types';
|
||||||
import { ITheme } from 'xterm';
|
import { ITheme } from 'xterm';
|
||||||
|
|
||||||
@@ -15,7 +14,7 @@ let page: puppeteer.Page;
|
|||||||
const width = 800;
|
const width = 800;
|
||||||
const height = 600;
|
const height = 600;
|
||||||
|
|
||||||
describe.only('WebGL Renderer Integration Tests', function(): void {
|
describe('WebGL Renderer Integration Tests', function(): void {
|
||||||
before(async function(): Promise<any> {
|
before(async function(): Promise<any> {
|
||||||
browser = await puppeteer.launch({
|
browser = await puppeteer.launch({
|
||||||
headless: process.argv.indexOf('--headless') !== -1,
|
headless: process.argv.indexOf('--headless') !== -1,
|
||||||
|
|||||||
@@ -4,8 +4,8 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import * as puppeteer from 'puppeteer';
|
import * as puppeteer from 'puppeteer';
|
||||||
import { assert } from 'chai';
|
|
||||||
import { ITerminalOptions } from 'xterm';
|
import { ITerminalOptions } from 'xterm';
|
||||||
|
import { pollFor } from './TestUtils';
|
||||||
|
|
||||||
const APP = 'http://127.0.0.1:3000/test';
|
const APP = 'http://127.0.0.1:3000/test';
|
||||||
|
|
||||||
@@ -15,12 +15,9 @@ const width = 800;
|
|||||||
const height = 600;
|
const height = 600;
|
||||||
|
|
||||||
describe('CharWidth Integration Tests', function(): void {
|
describe('CharWidth Integration Tests', function(): void {
|
||||||
this.timeout(20000);
|
|
||||||
|
|
||||||
before(async function(): Promise<any> {
|
before(async function(): Promise<any> {
|
||||||
browser = await puppeteer.launch({
|
browser = await puppeteer.launch({
|
||||||
headless: process.argv.indexOf('--headless') !== -1,
|
headless: process.argv.indexOf('--headless') !== -1,
|
||||||
slowMo: 0,
|
|
||||||
args: [`--window-size=${width},${height}`, `--no-sandbox`]
|
args: [`--window-size=${width},${height}`, `--no-sandbox`]
|
||||||
});
|
});
|
||||||
page = (await browser.pages())[0];
|
page = (await browser.pages())[0];
|
||||||
@@ -41,37 +38,37 @@ describe('CharWidth Integration Tests', function(): void {
|
|||||||
it('ASCII chars', async function(): Promise<void> {
|
it('ASCII chars', async function(): Promise<void> {
|
||||||
const input = 'This is just ASCII text.#';
|
const input = 'This is just ASCII text.#';
|
||||||
await page.evaluate(`window.term.write('${input}')`);
|
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> {
|
it('combining chars', async function(): Promise<void> {
|
||||||
const input = 'e\u0301e\u0301e\u0301e\u0301e\u0301e\u0301e\u0301e\u0301e\u0301#';
|
const input = 'e\u0301e\u0301e\u0301e\u0301e\u0301e\u0301e\u0301e\u0301e\u0301#';
|
||||||
await page.evaluate(`window.term.write('${input}')`);
|
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> {
|
it('surrogate chars', async function(): Promise<void> {
|
||||||
const input = '𝄞𝄞𝄞𝄞𝄞𝄞𝄞𝄞𝄞𝄞𝄞𝄞𝄞𝄞𝄞𝄞𝄞𝄞𝄞𝄞𝄞𝄞𝄞𝄞𝄞𝄞𝄞#';
|
const input = '𝄞𝄞𝄞𝄞𝄞𝄞𝄞𝄞𝄞𝄞𝄞𝄞𝄞𝄞𝄞𝄞𝄞𝄞𝄞𝄞𝄞𝄞𝄞𝄞𝄞𝄞𝄞#';
|
||||||
await page.evaluate(`window.term.write('${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> {
|
it('surrogate combining chars', async function(): Promise<void> {
|
||||||
const input = '𓂀\u0301𓂀\u0301𓂀\u0301𓂀\u0301𓂀\u0301𓂀\u0301𓂀\u0301𓂀\u0301𓂀\u0301𓂀\u0301𓂀\u0301#';
|
const input = '𓂀\u0301𓂀\u0301𓂀\u0301𓂀\u0301𓂀\u0301𓂀\u0301𓂀\u0301𓂀\u0301𓂀\u0301𓂀\u0301𓂀\u0301#';
|
||||||
await page.evaluate(`window.term.write('${input}')`);
|
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> {
|
it('fullwidth chars', async function(): Promise<void> {
|
||||||
const input = '1234567890#';
|
const input = '1234567890#';
|
||||||
await page.evaluate(`window.term.write('${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> {
|
it('fullwidth chars offset 1', async function(): Promise<void> {
|
||||||
const input = 'a1234567890#';
|
const input = 'a1234567890#';
|
||||||
await page.evaluate(`window.term.write('${input}')`);
|
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
|
// 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