Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

chore: upstream TestServerConnection changes (#39705)

Dmitry Gozman09940a53422d
diff --git a/packages/playwright/src/isomorphic/testServerConnection.ts b/packages/playwright/src/isomorphic/testServerConnection.ts
index aa4313553e..e87c0119b5 100644
--- a/packages/playwright/src/isomorphic/testServerConnection.ts
+++ b/packages/playwright/src/isomorphic/testServerConnection.ts
@@ -22,9 +22,6 @@ import type * as reporterTypes from '../../types/testReporter';
// -- Reuse boundary -- Everything below this line is reused in the vscode extension.
export class TestServerConnectionClosedError extends Error {
- constructor() {
- super('Test server connection closed');
- }
}
export interface TestServerTransport {
@@ -86,7 +83,7 @@ export class TestServerConnection implements TestServerInterface, TestServerInte
private _lastId = 0;
private _transport: TestServerTransport;
- private _callbacks = new Map<number, { resolve: (arg: any) => void, reject: (arg: Error) => void }>();
+ private _callbacks = new Map<number, { resolve: (arg: any) => void, reject: (arg: Error) => void, error: TestServerConnectionClosedError }>();
private _connectedPromise: Promise<void>;
private _isClosed = false;
@@ -125,7 +122,7 @@ export class TestServerConnection implements TestServerInterface, TestServerInte
this._onCloseEmitter.fire();
clearInterval(pingInterval);
for (const callback of this._callbacks.values())
- callback.reject(new TestServerConnectionClosedError());
+ callback.reject(callback.error);
this._callbacks.clear();
});
}
@@ -141,9 +138,11 @@ export class TestServerConnection implements TestServerInterface, TestServerInte
await this._connectedPromise;
const id = ++this._lastId;
const message = { id, method, params };
+ // Capture proper stack trace in the error here.
+ const error = new TestServerConnectionClosedError(`${method}: test server connection closed`);
this._transport.send(JSON.stringify(message));
return new Promise((resolve, reject) => {
- this._callbacks.set(id, { resolve, reject });
+ this._callbacks.set(id, { resolve, reject, error });
});
}