diff --git a/addons/xterm-addon-canvas/test/CanvasRenderer.test.ts b/addons/xterm-addon-canvas/test/CanvasRenderer.test.ts index 76f57394b0..2782081cab 100644 --- a/addons/xterm-addon-canvas/test/CanvasRenderer.test.ts +++ b/addons/xterm-addon-canvas/test/CanvasRenderer.test.ts @@ -4,7 +4,7 @@ */ import test from '@playwright/test'; -import { ISharedRendererTestContext, injectSharedRendererTests } from '../../../out-test/playwright/SharedRendererTests'; +import { ISharedRendererTestContext, injectSharedRendererTests, injectSharedRendererTestsStandalone } from '../../../out-test/playwright/SharedRendererTests'; import { ITestContext, createTestContext, openTerminal } from '../../../out-test/playwright/TestUtils'; let ctx: ITestContext; @@ -28,4 +28,5 @@ test.describe('Canvas Renderer Integration Tests', () => { test.skip(({ browserName }) => browserName === 'webkit'); injectSharedRendererTests(ctxWrapper); + injectSharedRendererTestsStandalone(ctxWrapper); }); diff --git a/addons/xterm-addon-webgl/test/WebglRenderer.test.ts b/addons/xterm-addon-webgl/test/WebglRenderer.test.ts index 718d8e0362..4b73c08b57 100644 --- a/addons/xterm-addon-webgl/test/WebglRenderer.test.ts +++ b/addons/xterm-addon-webgl/test/WebglRenderer.test.ts @@ -4,7 +4,7 @@ */ import test from '@playwright/test'; -import { ISharedRendererTestContext, injectSharedRendererTests } from '../../../out-test/playwright/SharedRendererTests'; +import { ISharedRendererTestContext, injectSharedRendererTests, injectSharedRendererTestsStandalone } from '../../../out-test/playwright/SharedRendererTests'; import { ITestContext, createTestContext, openTerminal } from '../../../out-test/playwright/TestUtils'; import { platform } from 'os'; @@ -29,4 +29,5 @@ test.describe('WebGL Renderer Integration Tests', async () => { } injectSharedRendererTests(ctxWrapper); + injectSharedRendererTestsStandalone(ctxWrapper); }); diff --git a/src/browser/renderer/dom/DomRendererRowFactory.test.ts b/src/browser/renderer/dom/DomRendererRowFactory.test.ts index 36923dbbce..dfea8b0185 100644 --- a/src/browser/renderer/dom/DomRendererRowFactory.test.ts +++ b/src/browser/renderer/dom/DomRendererRowFactory.test.ts @@ -96,6 +96,24 @@ describe('DomRendererRowFactory', () => { } }); + it('should not display cursor for before initializing', () => { + const coreService = new MockCoreService(); + coreService.isCursorInitialized = false; + const rowFactory = new DomRendererRowFactory( + dom.window.document, + new MockCharacterJoinerService(), + new MockOptionsService(), + new MockCoreBrowserService(), + coreService, + new MockDecorationService(), + new MockThemeService() + ); + const spans = rowFactory.createRow(lineData, 0, true, 'block', undefined, 0, false, 5, EMPTY_WIDTH, -1, -1); + assert.equal(extractHtml(spans), + ` ` + ); + }); + describe('attributes', () => { it('should add class for bold', () => { const cell = CellData.fromCharData([0, 'a', 1, 'a'.charCodeAt(0)]); diff --git a/src/browser/renderer/dom/DomRendererRowFactory.ts b/src/browser/renderer/dom/DomRendererRowFactory.ts index 614b2301e3..6ab68e7d6e 100644 --- a/src/browser/renderer/dom/DomRendererRowFactory.ts +++ b/src/browser/renderer/dom/DomRendererRowFactory.ts @@ -218,7 +218,7 @@ export class DomRendererRowFactory { } } - if (!this._coreService.isCursorHidden && isCursorCell) { + if (!this._coreService.isCursorHidden && isCursorCell && this._coreService.isCursorInitialized) { classes.push(RowCss.CURSOR_CLASS); if (this._coreBrowserService.isFocused) { if (cursorBlink) { diff --git a/src/common/TestUtils.test.ts b/src/common/TestUtils.test.ts index fcf0c2cdff..8e57664e97 100644 --- a/src/common/TestUtils.test.ts +++ b/src/common/TestUtils.test.ts @@ -78,7 +78,7 @@ export class MockCharsetService implements ICharsetService { export class MockCoreService implements ICoreService { public serviceBrand: any; - public isCursorInitialized: boolean = false; + public isCursorInitialized: boolean = true; public isCursorHidden: boolean = false; public isFocused: boolean = false; public modes: IModes = { diff --git a/test/playwright/Renderer.test.ts b/test/playwright/Renderer.test.ts index c5c1e94d47..77bf794166 100644 --- a/test/playwright/Renderer.test.ts +++ b/test/playwright/Renderer.test.ts @@ -5,7 +5,7 @@ import { test } from '@playwright/test'; import { ITestContext, createTestContext, openTerminal } from './TestUtils'; -import { ISharedRendererTestContext, injectSharedRendererTests } from './SharedRendererTests'; +import { ISharedRendererTestContext, injectSharedRendererTestsStandalone, injectSharedRendererTests } from './SharedRendererTests'; let ctx: ITestContext; const ctxWrapper: ISharedRendererTestContext = { value: undefined } as any; @@ -18,5 +18,5 @@ test.afterAll(async () => await ctx.page.close()); test.describe('DOM Renderer Integration Tests', () => { injectSharedRendererTests(ctxWrapper); + injectSharedRendererTestsStandalone(ctxWrapper); }); - diff --git a/test/playwright/SharedRendererTests.ts b/test/playwright/SharedRendererTests.ts index e1e56bc948..76c5051bdf 100644 --- a/test/playwright/SharedRendererTests.ts +++ b/test/playwright/SharedRendererTests.ts @@ -6,7 +6,7 @@ import { IImage32, decodePng } from '@lunapaint/png-codec'; import { LocatorScreenshotOptions, test } from '@playwright/test'; import { ITheme } from 'xterm'; -import { ITestContext, MaybeAsync, pollFor, pollForApproximate } from './TestUtils'; +import { ITestContext, MaybeAsync, openTerminal, pollFor, pollForApproximate } from './TestUtils'; export interface ISharedRendererTestContext { value: ITestContext; @@ -1150,6 +1150,40 @@ export function injectSharedRendererTests(ctx: ISharedRendererTestContext): void }); } +/** + * Injects shared renderer tests where it's required to re-initialize the terminal for each test. + * This is much slower than just calling `Terminal.reset` but testing some features needs this + * treatment. + */ +export function injectSharedRendererTestsStandalone(ctx: ISharedRendererTestContext): void { + test.beforeEach(async () => { + // Recreate terminal + await openTerminal(ctx.value); + ctx.value.page.evaluate(` + window.term.options.minimumContrastRatio = 1; + window.term.options.allowTransparency = false; + window.term.options.theme = undefined; + `); + // Clear the cached screenshot before each test + frameDetails = undefined; + }); + test.describe('regression tests', () => { + test('#4790: cursor should not be displayed before focusing', async () => { + const theme: ITheme = { + cursor: '#0000FF' + }; + await ctx.value.page.evaluate(`window.term.options.theme = ${JSON.stringify(theme)};`); + await pollFor(ctx.value.page, () => getCellColor(ctx.value, 1, 1), [0, 0, 0, 255]); + await ctx.value.proxy.focus(); + frameDetails = undefined; + await pollFor(ctx.value.page, () => getCellColor(ctx.value, 1, 1), [0, 0, 255, 255]); + await ctx.value.proxy.blur(); + frameDetails = undefined; + await pollFor(ctx.value.page, () => getCellColor(ctx.value, 1, 1), [0, 0, 0, 255]); + }); + }); +} + /** * Gets the color of the pixel in the center of a cell. * @param ctx The test context.