diff --git a/src/common/Tracing.ts b/src/common/Tracing.ts index ba1a5ff5..ad075e9b 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 64afda9b..5e06f12b 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(); + }); });