From 8c1a5866c566f14e6b81f8763da2b435e88f0450 Mon Sep 17 00:00:00 2001 From: Christian Bromann Date: Thu, 23 Jul 2020 16:21:15 +0200 Subject: [PATCH] fix: handle promise for reading protocol stream of trace (#6270) --- src/common/Tracing.ts | 8 ++++++-- test/tracing.spec.ts | 12 ++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/common/Tracing.ts b/src/common/Tracing.ts index ba1a5ff596b9d..ad075e9baccce 100644 --- a/src/common/Tracing.ts +++ b/src/common/Tracing.ts @@ -101,11 +101,15 @@ export class Tracing { */ async stop(): Promise { let fulfill: (value: Buffer) => void; - const contentPromise = new Promise((x) => (fulfill = x)); + let reject: (err: Error) => void; + const contentPromise = new Promise((x, y) => { + fulfill = x; + reject = y; + }); this._client.once('Tracing.tracingComplete', (event) => { helper .readProtocolStream(this._client, event.stream, this._path) - .then(fulfill); + .then(fulfill, reject); }); await this._client.send('Tracing.end'); this._recording = false; diff --git a/test/tracing.spec.ts b/test/tracing.spec.ts index 64afda9bab30d..5e06f12b4c9d6 100644 --- a/test/tracing.spec.ts +++ b/test/tracing.spec.ts @@ -118,4 +118,16 @@ describeChromeOnly('Tracing', function () { const trace = await page.tracing.stop(); expect(trace.toString()).toContain('screenshot'); }); + + it('should properly fail if readProtocolStream errors out', async () => { + await page.tracing.start({ path: __dirname }); + + let error: Error = null; + try { + await page.tracing.stop(); + } catch (error_) { + error = error_; + } + expect(error).toBeDefined(); + }); });