Skip to content

Commit

Permalink
fix: handle promise for reading protocol stream of trace (#6270)
Browse files Browse the repository at this point in the history
  • Loading branch information
christian-bromann committed Jul 23, 2020
1 parent 15d1906 commit 8c1a586
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/common/Tracing.ts
Expand Up @@ -101,11 +101,15 @@ export class Tracing {
*/
async stop(): Promise<Buffer> {
let fulfill: (value: Buffer) => void;
const contentPromise = new Promise<Buffer>((x) => (fulfill = x));
let reject: (err: Error) => void;
const contentPromise = new Promise<Buffer>((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;
Expand Down
12 changes: 12 additions & 0 deletions test/tracing.spec.ts
Expand Up @@ -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();
});
});

0 comments on commit 8c1a586

Please sign in to comment.