diff --git a/src/debugHighlight.ts b/src/debugHighlight.ts index 4fd2d8071..5552b47c2 100644 --- a/src/debugHighlight.ts +++ b/src/debugHighlight.ts @@ -23,9 +23,8 @@ import * as vscodeTypes from './vscodeTypes'; export type DebuggerError = { error: string, location: Location }; -const debugSessions = new Map(); - export class DebugHighlight { + private _debugSessions = new Map(); private _errorInDebugger: vscodeTypes.EventEmitter; readonly onErrorInDebugger: vscodeTypes.Event; private _disposables: vscodeTypes.Disposable[] = []; @@ -40,10 +39,10 @@ export class DebugHighlight { this._disposables = [ vscode.debug.onDidStartDebugSession(session => { if (isPlaywrightSession(session)) - debugSessions.set(session.id, session); + this._debugSessions.set(session.id, session); }), vscode.debug.onDidTerminateDebugSession(session => { - debugSessions.delete(session.id); + this._debugSessions.delete(session.id); self._hideHighlight(); }), vscode.languages.registerHoverProvider('typescript', { @@ -105,7 +104,7 @@ export class DebugHighlight { private async _highlightLocator(document: vscodeTypes.TextDocument, position: vscodeTypes.Position, token?: vscodeTypes.CancellationToken) { if (!this._reusedBrowser.pageCount()) return; - const result = await locatorToHighlight(document, position, token); + const result = await locatorToHighlight(this._debugSessions, document, position, token); if (result) this._reusedBrowser.highlight(result); else @@ -132,7 +131,7 @@ export type StackFrame = { const sessionsWithHighlight = new Set(); -async function locatorToHighlight(document: vscodeTypes.TextDocument, position: vscodeTypes.Position, token?: vscodeTypes.CancellationToken): Promise { +async function locatorToHighlight(debugSessions: Map, document: vscodeTypes.TextDocument, position: vscodeTypes.Position, token?: vscodeTypes.CancellationToken): Promise { const fsPath = document.uri.fsPath; if (!debugSessions.size) { diff --git a/tests/highlight-locators.spec.ts b/tests/highlight-locators.spec.ts index 4972ba818..8308b7414 100644 --- a/tests/highlight-locators.spec.ts +++ b/tests/highlight-locators.spec.ts @@ -78,8 +78,15 @@ test('should work', async ({ activate }) => { [[16, 30], page.getByRole('button', { name: 'two' })], [[17, 30], page.getByRole('button', { name: 'one' })], ] as const) { - vscode.languages.emitHoverEvent(language, vscode.window.activeTextEditor.document, new vscode.Position(line, column)); - await expect.poll(() => page.locator('x-pw-highlight').boundingBox()).toEqual(expectedLocator ? await expectedLocator.boundingBox() : null); + await test.step(`should highlight ${language} ${line}:${column}`, async () => { + vscode.languages.emitHoverEvent(language, vscode.window.activeTextEditor.document, new vscode.Position(line, column)); + await expect(async () => { + if (!expectedLocator) + await expect(page.locator('x-pw-highlight')).toBeHidden(); + else + expect(await page.locator('x-pw-highlight').boundingBox()).toEqual(await expectedLocator.boundingBox()); + }).toPass(); + }); } } await browser.close();