Fix flaky terminal api tests

This commit is contained in:
Daniel Imms
2019-11-09 18:28:24 -08:00
parent 34e703e472
commit 7ff6e4f493
2 changed files with 12 additions and 5 deletions
+6 -4
View File
@@ -6,7 +6,7 @@
import * as puppeteer from 'puppeteer';
import { assert } from 'chai';
import { ITerminalOptions } from 'xterm';
import { pollFor, writeSync } from './TestUtils';
import { pollFor, timeout, writeSync } from './TestUtils';
const APP = 'http://127.0.0.1:3000/test';
@@ -15,7 +15,7 @@ let page: puppeteer.Page;
const width = 800;
const height = 600;
describe.only('API Integration Tests', function(): void {
describe('API Integration Tests', function(): void {
before(async () => {
browser = await puppeteer.launch({
headless: process.argv.indexOf('--headless') !== -1,
@@ -162,7 +162,7 @@ describe.only('API Integration Tests', function(): void {
it('foreground', async () => {
await openTerminal({ 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.querySelector('.xterm-rows > :nth-child(1) > :nth-child(1)')`, true);
await pollFor(page, `document.querySelectorAll('.xterm-rows > :nth-child(1) > *').length`, 9);
assert.deepEqual(await page.evaluate(`
[
document.querySelector('.xterm-rows > :nth-child(1) > :nth-child(1)').className,
@@ -187,7 +187,7 @@ describe.only('API Integration Tests', function(): void {
it('background', async () => {
await openTerminal({ 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.querySelector('.xterm-rows > :nth-child(1) > :nth-child(1)')`, true);
await pollFor(page, `document.querySelectorAll('.xterm-rows > :nth-child(1) > *').length`, 9);
assert.deepEqual(await page.evaluate(`
[
document.querySelector('.xterm-rows > :nth-child(1) > :nth-child(1)').className,
@@ -358,6 +358,7 @@ describe.only('API Integration Tests', function(): void {
it('onRender', async () => {
await openTerminal();
await timeout(20); // Ensure all init events are fired
await page.evaluate(`
window.calls = [];
window.term.onRender(e => window.calls.push([e.start, e.end]));
@@ -371,6 +372,7 @@ describe.only('API Integration Tests', function(): void {
it('onResize', async () => {
await openTerminal();
await timeout(20); // Ensure all init events are fired
await page.evaluate(`
window.calls = [];
window.term.onResize(e => window.calls.push([e.cols, e.rows]));
+6 -1
View File
@@ -12,8 +12,9 @@ export async function pollFor<T>(page: puppeteer.Page, evalOrFn: string | (() =>
}
const result = typeof evalOrFn === 'string' ? await page.evaluate(evalOrFn) : await evalOrFn();
if (!deepEqual(result, val)) {
console.log('result', result, 'val', val);
return new Promise<void>(r => {
setTimeout(() => r(pollFor(page, evalOrFn, val, preFn)), 10);
setTimeout(() => r(pollFor(page, evalOrFn, val, preFn)), 1);
});
}
}
@@ -25,3 +26,7 @@ export async function writeSync(page: puppeteer.Page, data: string): Promise<voi
`);
await pollFor(page, 'window.ready', true);
}
export async function timeout(ms: number): Promise<void> {
return new Promise<void>(r => setTimeout(r, ms));
}