Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mxschmitt committed Sep 20, 2023
1 parent a5bbb2f commit c6a62f7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
11 changes: 5 additions & 6 deletions src/debugHighlight.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@ import * as vscodeTypes from './vscodeTypes';

export type DebuggerError = { error: string, location: Location };

const debugSessions = new Map<string, vscodeTypes.DebugSession>();

export class DebugHighlight {
private _debugSessions = new Map<string, vscodeTypes.DebugSession>();
private _errorInDebugger: vscodeTypes.EventEmitter<DebuggerError>;
readonly onErrorInDebugger: vscodeTypes.Event<DebuggerError>;
private _disposables: vscodeTypes.Disposable[] = [];
Expand All @@ -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', {
Expand Down Expand Up @@ -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
Expand All @@ -132,7 +131,7 @@ export type StackFrame = {

const sessionsWithHighlight = new Set<vscodeTypes.DebugSession>();

async function locatorToHighlight(document: vscodeTypes.TextDocument, position: vscodeTypes.Position, token?: vscodeTypes.CancellationToken): Promise<string | undefined> {
async function locatorToHighlight(debugSessions: Map<string, vscodeTypes.DebugSession>, document: vscodeTypes.TextDocument, position: vscodeTypes.Position, token?: vscodeTypes.CancellationToken): Promise<string | undefined> {
const fsPath = document.uri.fsPath;

if (!debugSessions.size) {
Expand Down
11 changes: 9 additions & 2 deletions tests/highlight-locators.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit c6a62f7

Please sign in to comment.