mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
fix: handle promise for reading protocol stream of trace (#6270)
This commit is contained in:
parent
15d1906e7c
commit
8c1a5866c5
@ -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;
|
||||
|
@ -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();
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user