From 86c3988e26b7e356d85fcb095def777d20d9efa1 Mon Sep 17 00:00:00 2001 From: Nikolay Vitkov <34244704+Lightning00Blade@users.noreply.github.com> Date: Thu, 8 Feb 2024 12:00:37 +0100 Subject: [PATCH] test: remove Buffer.concat overwrite (#11876) --- packages/puppeteer-core/src/common/util.ts | 2 +- test/TestExpectations.json | 12 -------- test/src/tracing.spec.ts | 32 +++++++++++++++------- 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/packages/puppeteer-core/src/common/util.ts b/packages/puppeteer-core/src/common/util.ts index 2d0c82a7b63..59038d6fe9a 100644 --- a/packages/puppeteer-core/src/common/util.ts +++ b/packages/puppeteer-core/src/common/util.ts @@ -209,7 +209,7 @@ export async function getReadableAsBuffer( readable: ReadableStream, path?: string ): Promise { - const buffers = []; + const buffers: Uint8Array[] = []; const reader = readable.getReader(); if (path) { const fs = await importFSPromises(); diff --git a/test/TestExpectations.json b/test/TestExpectations.json index 233f0223f4b..81fb02cb9a9 100644 --- a/test/TestExpectations.json +++ b/test/TestExpectations.json @@ -1521,18 +1521,6 @@ "parameters": ["cdp", "firefox"], "expectations": ["FAIL"] }, - { - "testIdPattern": "[browsercontext.spec] BrowserContext window.open should use parent tab context", - "platforms": ["darwin", "linux", "win32"], - "parameters": ["chrome", "webDriverBiDi"], - "expectations": ["PASS"] - }, - { - "testIdPattern": "[browsercontext.spec] BrowserContext window.open should use parent tab context", - "platforms": ["darwin", "linux", "win32"], - "parameters": ["firefox", "webDriverBiDi"], - "expectations": ["PASS"] - }, { "testIdPattern": "[CDPSession.spec] Target.createCDPSession should be able to detach session", "platforms": ["darwin", "linux", "win32"], diff --git a/test/src/tracing.spec.ts b/test/src/tracing.spec.ts index 2c0a5aff192..7ee6d461921 100644 --- a/test/src/tracing.spec.ts +++ b/test/src/tracing.spec.ts @@ -8,6 +8,8 @@ import fs from 'fs'; import path from 'path'; import expect from 'expect'; +import * as utils from 'puppeteer-core/internal/common/util.js'; +import sinon from 'sinon'; import {launch} from './mocha-utils.js'; @@ -113,16 +115,26 @@ describe('Tracing', function () { await page.tracing.start({screenshots: true}); await page.goto(server.PREFIX + '/grid.html'); - const oldBufferConcat = Buffer.concat; - try { - Buffer.concat = () => { - throw new Error('error'); - }; - const trace = await page.tracing.stop(); - expect(trace).toEqual(undefined); - } finally { - Buffer.concat = oldBufferConcat; - } + const oldGetReadableAsBuffer = utils.getReadableAsBuffer; + sinon.stub(utils, 'getReadableAsBuffer').callsFake(() => { + return oldGetReadableAsBuffer({ + getReader() { + return { + done: false, + read() { + if (!this.done) { + this.done = true; + return {done: false, value: 42}; + } + return {done: true}; + }, + }; + }, + } as unknown as ReadableStream); + }); + + const trace = await page.tracing.stop(); + expect(trace).toEqual(undefined); }); it('should support a buffer without a path', async () => {