Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
chore: do not try/catch buffer.concat (#1575)
Pavel Feldman4e89939ece49
diff --git a/src/chromium/crBrowser.ts b/src/chromium/crBrowser.tsindex fe3fcdac97..5c47067fed 100644--- a/src/chromium/crBrowser.ts+++ b/src/chromium/crBrowser.ts@@ -223,14 +223,13 @@ export class CRBrowser extends platform.EventEmitter implements Browser {async stopTracing(): Promise<platform.BufferType> {assert(this._tracingClient, 'Tracing was not started.');- let fulfill: (buffer: platform.BufferType) => void;- const contentPromise = new Promise<platform.BufferType>(x => fulfill = x);- this._tracingClient.once('Tracing.tracingComplete', event => {- readProtocolStream(this._tracingClient!, event.stream!, this._tracingPath).then(fulfill);- });- await this._tracingClient.send('Tracing.end');+ const [event] = await Promise.all([+ new Promise(f => this._tracingClient!.once('Tracing.tracingComplete', f)),+ this._tracingClient.send('Tracing.end')+ ]);+ const result = await readProtocolStream(this._tracingClient, (event as any).stream!, this._tracingPath);this._tracingRecording = false;- return contentPromise;+ return result;}isConnected(): boolean {diff --git a/src/chromium/crProtocolHelper.ts b/src/chromium/crProtocolHelper.tsindex d49d312364..83f57bf693 100644--- a/src/chromium/crProtocolHelper.ts+++ b/src/chromium/crProtocolHelper.ts@@ -78,12 +78,7 @@ export async function readProtocolStream(client: CRSession, handle: string, pathif (path)await platform.closeFdAsync(fd!);await client.send('IO.close', {handle});- let resultBuffer = null;- try {- resultBuffer = platform.Buffer.concat(bufs);- } finally {- return resultBuffer!;- }+ return platform.Buffer.concat(bufs);}export function toConsoleMessageLocation(stackTrace: Protocol.Runtime.StackTrace | undefined) {diff --git a/test/chromium/tracing.spec.js b/test/chromium/tracing.spec.jsindex d1959f4f3e..55075a25e0 100644--- a/test/chromium/tracing.spec.js+++ b/test/chromium/tracing.spec.js@@ -75,17 +75,6 @@ module.exports.describe = function({testRunner, expect, defaultBrowserOptions, bconst trace = await browser.stopTracing();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}) => {await browser.startTracing(page, {screenshots: true});await page.goto(server.PREFIX + '/grid.html');