From d902b06fd13d14fc67f3702e23827dcd8ad37768 Mon Sep 17 00:00:00 2001 From: Max Schmitt Date: Thu, 6 May 2021 18:18:56 +0200 Subject: [PATCH] test: fixed flaky connectOverCDP tests (#6436) --- src/server/browserType.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/server/browserType.ts b/src/server/browserType.ts index 575e9ee25d..43dbe021ad 100644 --- a/src/server/browserType.ts +++ b/src/server/browserType.ts @@ -186,7 +186,8 @@ export abstract class BrowserType extends SdkObject { await validateHostRequirements(this._registry, options.channel as registry.BrowserName); let wsEndpointCallback: ((wsEndpoint: string) => void) | undefined; - const wsEndpoint = options.useWebSocket ? new Promise(f => wsEndpointCallback = f) : undefined; + const shouldWaitForWSListening = options.useWebSocket || options.args?.some(a => a.startsWith('--remote-debugging-port')); + const waitForWSEndpoint = shouldWaitForWSListening ? new Promise(f => wsEndpointCallback = f) : undefined; // Note: it is important to define these variables before launchProcess, so that we don't get // "Cannot access 'browserServer' before initialization" if something went wrong. let transport: ConnectionTransport | undefined = undefined; @@ -242,8 +243,11 @@ export abstract class BrowserType extends SdkObject { kill }; progress.cleanupWhenAborted(() => closeOrKill(progress.timeUntilDeadline())); + let wsEndpoint: string | undefined; + if (shouldWaitForWSListening) + wsEndpoint = await waitForWSEndpoint; if (options.useWebSocket) { - transport = await WebSocketTransport.connect(progress, await wsEndpoint!); + transport = await WebSocketTransport.connect(progress, wsEndpoint!); } else { const stdio = launchedProcess.stdio as unknown as [NodeJS.ReadableStream, NodeJS.WritableStream, NodeJS.WritableStream, NodeJS.WritableStream, NodeJS.ReadableStream]; transport = new PipeTransport(stdio[3], stdio[4]);