chore: do not try/catch buffer.concat (#1575)
This commit is contained in:
parent
e796bfd815
commit
4e89939ece
|
|
@ -223,14 +223,13 @@ export class CRBrowser extends platform.EventEmitter implements Browser {
|
||||||
|
|
||||||
async stopTracing(): Promise<platform.BufferType> {
|
async stopTracing(): Promise<platform.BufferType> {
|
||||||
assert(this._tracingClient, 'Tracing was not started.');
|
assert(this._tracingClient, 'Tracing was not started.');
|
||||||
let fulfill: (buffer: platform.BufferType) => void;
|
const [event] = await Promise.all([
|
||||||
const contentPromise = new Promise<platform.BufferType>(x => fulfill = x);
|
new Promise(f => this._tracingClient!.once('Tracing.tracingComplete', f)),
|
||||||
this._tracingClient.once('Tracing.tracingComplete', event => {
|
this._tracingClient.send('Tracing.end')
|
||||||
readProtocolStream(this._tracingClient!, event.stream!, this._tracingPath).then(fulfill);
|
]);
|
||||||
});
|
const result = await readProtocolStream(this._tracingClient, (event as any).stream!, this._tracingPath);
|
||||||
await this._tracingClient.send('Tracing.end');
|
|
||||||
this._tracingRecording = false;
|
this._tracingRecording = false;
|
||||||
return contentPromise;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
isConnected(): boolean {
|
isConnected(): boolean {
|
||||||
|
|
|
||||||
|
|
@ -78,12 +78,7 @@ export async function readProtocolStream(client: CRSession, handle: string, path
|
||||||
if (path)
|
if (path)
|
||||||
await platform.closeFdAsync(fd!);
|
await platform.closeFdAsync(fd!);
|
||||||
await client.send('IO.close', {handle});
|
await client.send('IO.close', {handle});
|
||||||
let resultBuffer = null;
|
return platform.Buffer.concat(bufs);
|
||||||
try {
|
|
||||||
resultBuffer = platform.Buffer.concat(bufs);
|
|
||||||
} finally {
|
|
||||||
return resultBuffer!;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function toConsoleMessageLocation(stackTrace: Protocol.Runtime.StackTrace | undefined) {
|
export function toConsoleMessageLocation(stackTrace: Protocol.Runtime.StackTrace | undefined) {
|
||||||
|
|
|
||||||
|
|
@ -75,17 +75,6 @@ module.exports.describe = function({testRunner, expect, defaultBrowserOptions, b
|
||||||
const trace = await browser.stopTracing();
|
const trace = await browser.stopTracing();
|
||||||
expect(trace).toBeTruthy();
|
expect(trace).toBeTruthy();
|
||||||
});
|
});
|
||||||
it('should return null in case of Buffer error', async({browser, page, server}) => {
|
|
||||||
await browser.startTracing(page, {screenshots: true});
|
|
||||||
await page.goto(server.PREFIX + '/grid.html');
|
|
||||||
const oldBufferConcat = Buffer.concat;
|
|
||||||
Buffer.concat = bufs => {
|
|
||||||
throw new Error('Buffer.concat fake error, should be caught by playwright');
|
|
||||||
};
|
|
||||||
const trace = await browser.stopTracing();
|
|
||||||
expect(trace).toEqual(null);
|
|
||||||
Buffer.concat = oldBufferConcat;
|
|
||||||
});
|
|
||||||
it('should support a buffer without a path', async({browser, page, server}) => {
|
it('should support a buffer without a path', async({browser, page, server}) => {
|
||||||
await browser.startTracing(page, {screenshots: true});
|
await browser.startTracing(page, {screenshots: true});
|
||||||
await page.goto(server.PREFIX + '/grid.html');
|
await page.goto(server.PREFIX + '/grid.html');
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue