Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: handle promise for reading protocol stream of trace #6270

Merged
merged 1 commit into from Jul 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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();
});
});