Skip to content

Commit

Permalink
test: attempt to unflake highlight-locators.spec
Browse files Browse the repository at this point in the history
  • Loading branch information
dgozman committed Jan 10, 2025
1 parent 059dd1a commit 44d0429
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
6 changes: 5 additions & 1 deletion src/debugHighlight.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,13 @@ export class DebugHighlight {
}

private async _highlightLocator(document: vscodeTypes.TextDocument, position: vscodeTypes.Position, token?: vscodeTypes.CancellationToken) {
if (!this._reusedBrowser.pageCount())
console.log(`debugHighlight._highlightLocator`);
if (!this._reusedBrowser.pageCount()) {
console.log(`debugHighlight._highlightLocator: no pages!`);
return;
}
const result = await locatorToHighlight(this._debugSessions, document, position, token);
console.log(`debugHighlight._highlightLocator: ${result}`);
if (result)
this._reusedBrowser.highlight(result).catch(() => {});
else
Expand Down
12 changes: 6 additions & 6 deletions tests/highlight-locators.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ test.beforeEach(({ showBrowser }) => {
});

test('should work', async ({ activate }) => {
test.slow();

const cdpPort = 9234 + test.info().workerIndex * 2;
const { vscode, testController } = await activate({
'playwright.config.js': `module.exports = {
Expand Down Expand Up @@ -90,15 +92,13 @@ test('should work', async ({ activate }) => {
[[17, 30], boxOne],
] as const) {
await test.step(`should highlight ${language} ${line}:${column}`, async () => {
// Clear highlight.
vscode.languages.emitHoverEvent(language, vscode.window.activeTextEditor.document, new vscode.Position(0, 0));
// Let highlight poll update its state.
await new Promise(f => setTimeout(f, 500));
vscode.languages.emitHoverEvent(language, vscode.window.activeTextEditor.document, new vscode.Position(line, column));
// Let highlight poll update its state.
await new Promise(f => setTimeout(f, 1500));
if (!expectedBox) {
await expect(page.locator('x-pw-highlight')).toBeHidden();
await expect(page.locator('x-pw-highlight')).toBeHidden({ timeout: 10000 });
} else {
await expect(page.locator('x-pw-highlight')).toBeVisible();
await expect(page.locator('x-pw-highlight')).toBeVisible({ timeout: 10000 });
expect(await page.locator('x-pw-highlight').boundingBox()).toEqual(expectedBox);
}
});
Expand Down

0 comments on commit 44d0429

Please sign in to comment.