test: fixed flaky connectOverCDP tests (#6436)

This commit is contained in:
Max Schmitt 2021-05-06 18:18:56 +02:00 committed by GitHub
parent 217cbe3e21
commit d902b06fd1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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<string>(f => wsEndpointCallback = f) : undefined;
const shouldWaitForWSListening = options.useWebSocket || options.args?.some(a => a.startsWith('--remote-debugging-port'));
const waitForWSEndpoint = shouldWaitForWSListening ? new Promise<string>(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]);