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

This commit is contained in:
Christian Bromann 2020-07-23 16:21:15 +02:00 committed by GitHub
parent 15d1906e7c
commit 8c1a5866c5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 2 deletions

View File

@ -101,11 +101,15 @@ export class Tracing {
*/ */
async stop(): Promise<Buffer> { async stop(): Promise<Buffer> {
let fulfill: (value: Buffer) => void; 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) => { this._client.once('Tracing.tracingComplete', (event) => {
helper helper
.readProtocolStream(this._client, event.stream, this._path) .readProtocolStream(this._client, event.stream, this._path)
.then(fulfill); .then(fulfill, reject);
}); });
await this._client.send('Tracing.end'); await this._client.send('Tracing.end');
this._recording = false; this._recording = false;

View File

@ -118,4 +118,16 @@ describeChromeOnly('Tracing', function () {
const trace = await page.tracing.stop(); const trace = await page.tracing.stop();
expect(trace.toString()).toContain('screenshot'); 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();
});
}); });