From 7ff6e4f4933bc604325aab5feb2b248e9a735082 Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Sat, 9 Nov 2019 18:28:24 -0800 Subject: [PATCH] Fix flaky terminal api tests --- test/api/Terminal.api.ts | 10 ++++++---- test/api/TestUtils.ts | 7 ++++++- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/test/api/Terminal.api.ts b/test/api/Terminal.api.ts index 6d7a4d20..0b05736d 100644 --- a/test/api/Terminal.api.ts +++ b/test/api/Terminal.api.ts @@ -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])); diff --git a/test/api/TestUtils.ts b/test/api/TestUtils.ts index f0dd71d4..a31c2b46 100644 --- a/test/api/TestUtils.ts +++ b/test/api/TestUtils.ts @@ -12,8 +12,9 @@ export async function pollFor(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(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 { + return new Promise(r => setTimeout(r, ms)); +}