test: attempt to unflake vscode highlight tests (#34267)

This commit is contained in:
Dmitry Gozman 2025-01-10 09:52:39 +00:00 committed by GitHub
parent 75d2661497
commit b32d546159
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 8 additions and 21 deletions

View File

@ -62,10 +62,11 @@ export class DebugController extends SdkObject {
setReportStateChanged(enabled: boolean) {
if (enabled && !this._trackHierarchyListener) {
this._trackHierarchyListener = {
onPageOpen: () => this._emitSnapshot(),
onPageClose: () => this._emitSnapshot(),
onPageOpen: () => this._emitSnapshot(false),
onPageClose: () => this._emitSnapshot(false),
};
this._playwright.instrumentation.addListener(this._trackHierarchyListener, null);
this._emitSnapshot(true);
} else if (!enabled && this._trackHierarchyListener) {
this._playwright.instrumentation.removeListener(this._trackHierarchyListener);
this._trackHierarchyListener = undefined;
@ -162,24 +163,10 @@ export class DebugController extends SdkObject {
await Promise.all(this.allBrowsers().map(browser => browser.close({ reason: 'Close all browsers requested' })));
}
private _emitSnapshot() {
const browsers = [];
let pageCount = 0;
for (const browser of this._playwright.allBrowsers()) {
const b = {
contexts: [] as any[]
};
browsers.push(b);
for (const context of browser.contexts()) {
const c = {
pages: [] as any[]
};
b.contexts.push(c);
for (const page of context.pages())
c.pages.push(page.mainFrame().url());
pageCount += context.pages().length;
}
}
private _emitSnapshot(initial: boolean) {
const pageCount = this._playwright.allPages().length;
if (initial && !pageCount)
return;
this.emit(DebugController.Events.StateChanged, { pageCount });
}

View File

@ -52,7 +52,7 @@ export class PollingRecorder implements RecorderDelegate {
const pollPeriod = 1000;
if (this._pollRecorderModeTimer)
clearTimeout(this._pollRecorderModeTimer);
const state = await this._embedder.__pw_recorderState().catch(() => {});
const state = await this._embedder.__pw_recorderState().catch(() => null);
if (!state) {
this._pollRecorderModeTimer = this._recorder.injectedScript.builtinSetTimeout(() => this._pollRecorderMode(), pollPeriod);
return;