mirror of
https://github.com/microsoft/playwright.git
synced 2024-12-13 17:14:02 +03:00
chore: PlaywrightClient/Server enhancements (#7980)
- ensure timeout results in a meaningful message - add onDisconnect handler
This commit is contained in:
parent
4e8e75beb1
commit
869f8d541b
@ -49,7 +49,7 @@ export class PlaywrightClient {
|
||||
playwrightClientPromise,
|
||||
errorPromise,
|
||||
closePromise,
|
||||
new Promise((_, reject) => timer = setTimeout(reject, timeout))
|
||||
new Promise((_, reject) => timer = setTimeout(() => reject(`Timeout of ${timeout}ms exceeded while connecting.`), timeout))
|
||||
]);
|
||||
return await playwrightClientPromise;
|
||||
} finally {
|
||||
|
@ -33,6 +33,7 @@ export interface PlaywrightServerDelegate {
|
||||
|
||||
export type PlaywrightServerOptions = {
|
||||
acceptForwardedPorts?: boolean
|
||||
onDisconnect?: () => void;
|
||||
};
|
||||
|
||||
export class PlaywrightServer {
|
||||
@ -40,7 +41,7 @@ export class PlaywrightServer {
|
||||
private _clientsCount = 0;
|
||||
private _delegate: PlaywrightServerDelegate;
|
||||
|
||||
static async startDefault({ acceptForwardedPorts }: PlaywrightServerOptions = {}): Promise<PlaywrightServer> {
|
||||
static async startDefault({ acceptForwardedPorts, onDisconnect }: PlaywrightServerOptions = {}): Promise<PlaywrightServer> {
|
||||
const cleanup = async () => {
|
||||
await gracefullyCloseAll().catch(e => {});
|
||||
};
|
||||
@ -57,6 +58,7 @@ export class PlaywrightServer {
|
||||
cleanup();
|
||||
playwright._disablePortForwarding();
|
||||
playwright.selectors.unregisterAll();
|
||||
onDisconnect?.();
|
||||
};
|
||||
},
|
||||
};
|
||||
|
@ -57,7 +57,6 @@ class DriverMode {
|
||||
}
|
||||
|
||||
class ServiceMode {
|
||||
private _playwrightObejct: any;
|
||||
private _client: any;
|
||||
private _serviceProcess: childProcess.ChildProcess;
|
||||
|
||||
@ -75,8 +74,7 @@ class ServiceMode {
|
||||
});
|
||||
this._serviceProcess.on('exit', this._onExit);
|
||||
this._client = await PlaywrightClient.connect({wsEndpoint: `ws://localhost:${port}/ws`});
|
||||
this._playwrightObejct = this._client.playwright();
|
||||
return this._playwrightObejct;
|
||||
return this._client.playwright();
|
||||
}
|
||||
|
||||
async teardown() {
|
||||
@ -87,7 +85,7 @@ class ServiceMode {
|
||||
await processExited;
|
||||
}
|
||||
|
||||
private _onExit(exitCode, signal) {
|
||||
private _onExit(exitCode: number, signal: string) {
|
||||
throw new Error(`Server closed with exitCode=${exitCode} signal=${signal}`);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user