Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
fix: wait for worker to be ready before initializing (#13270)
Thomas Scholtes3e65ef35cfe2
diff --git a/packages/playwright-test/src/dispatcher.ts b/packages/playwright-test/src/dispatcher.tsindex b7c1907646..65c155ed28 100644--- a/packages/playwright-test/src/dispatcher.ts+++ b/packages/playwright-test/src/dispatcher.ts@@ -466,6 +466,7 @@ class Worker extends EventEmitter {private _didSendStop = false;private _didFail = false;private didExit = false;+ private _ready: Promise<void>;constructor(hash: string, parallelIndex: number) {super();@@ -494,9 +495,15 @@ class Worker extends EventEmitter {const { method, params } = message;this.emit(method, params);});++ this._ready = new Promise((resolve, reject) => {+ this.process.once('exit', () => reject(new Error('worker exited before it became ready')));+ this.once('ready', () => resolve());+ });}async init(testGroup: TestGroup, loaderData: SerializedLoaderData) {+ await this._ready;const params: WorkerInitParams = {workerIndex: this.workerIndex,parallelIndex: this.parallelIndex,@@ -505,7 +512,6 @@ class Worker extends EventEmitter {loader: loaderData,};this.send({ method: 'init', params });- await new Promise(f => this.process.once('message', f)); // Ready ack}run(testGroup: TestGroup) {