From 25e67de5312231e5dd0538ef2685d0ba577b8895 Mon Sep 17 00:00:00 2001 From: Tyler James Leonhardt <2644648+TylerLeonhardt@users.noreply.github.com> Date: Fri, 26 Sep 2025 16:48:01 -0700 Subject: [PATCH] await the listeners so that they're run before we mark "started" (#268578) --- test/mcp/src/application.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/test/mcp/src/application.ts b/test/mcp/src/application.ts index b9c408e1e30..d904d202497 100644 --- a/test/mcp/src/application.ts +++ b/test/mcp/src/application.ts @@ -332,9 +332,9 @@ export async function getApplication() { export class ApplicationService { private _application: Application | undefined; private _closing: Promise | undefined; - private _listeners: ((app: Application | undefined) => void)[] = []; + private _listeners: ((app: Application | undefined) => Promise | void)[] = []; - onApplicationChange(listener: (app: Application | undefined) => void): void { + onApplicationChange(listener: (app: Application | undefined) => Promise | void): void { this._listeners.push(listener); } @@ -361,19 +361,19 @@ export class ApplicationService { this._application.code.driver.browserContext.removeAllListeners(); await this._application.stop(); this._application = undefined; - this._runAllListeners(); + await this._runAllListeners(); } })(); }); - this._runAllListeners(); + await this._runAllListeners(); } return this._application; } - private _runAllListeners() { + private async _runAllListeners() { for (const listener of this._listeners) { try { - listener(this._application); + await listener(this._application); } catch (error) { console.error('Error occurred in application change listener:', error); }