From efc7ec1e801cb830515c3034833b9a5ca18e7e64 Mon Sep 17 00:00:00 2001 From: Yury Semikhatsky Date: Tue, 28 Nov 2023 10:04:15 -0800 Subject: [PATCH] =?UTF-8?q?cherry-pick(#28366):=20fix:=20parse=20report.js?= =?UTF-8?q?onl=20without=20creating=20large=20s=E2=80=A6=20(#28378)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit …tring Fixes https://github.com/microsoft/playwright/issues/28362 --- packages/playwright/src/reporters/merge.ts | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/packages/playwright/src/reporters/merge.ts b/packages/playwright/src/reporters/merge.ts index 8028d4d1e2280..1574d0c8b6746 100644 --- a/packages/playwright/src/reporters/merge.ts +++ b/packages/playwright/src/reporters/merge.ts @@ -92,19 +92,37 @@ const commonEvents = new Set(commonEventNames); const commonEventRegex = new RegExp(`${commonEventNames.join('|')}`); function parseCommonEvents(reportJsonl: Buffer): JsonEvent[] { - return reportJsonl.toString().split('\n') + return splitBufferLines(reportJsonl) + .map(line => line.toString('utf8')) .filter(line => commonEventRegex.test(line)) // quick filter .map(line => JSON.parse(line) as JsonEvent) .filter(event => commonEvents.has(event.method)); } function parseTestEvents(reportJsonl: Buffer): JsonEvent[] { - return reportJsonl.toString().split('\n') + return splitBufferLines(reportJsonl) + .map(line => line.toString('utf8')) .filter(line => line.length) .map(line => JSON.parse(line) as JsonEvent) .filter(event => !commonEvents.has(event.method)); } +function splitBufferLines(buffer: Buffer) { + const lines = []; + let start = 0; + while (start < buffer.length) { + // 0x0A is the byte for '\n' + const end = buffer.indexOf(0x0A, start); + if (end === -1) { + lines.push(buffer.slice(start)); + break; + } + lines.push(buffer.slice(start, end)); + start = end + 1; + } + return lines; +} + async function extractAndParseReports(dir: string, shardFiles: string[], internalizer: JsonStringInternalizer, printStatus: StatusCallback) { const shardEvents: { file: string, localPath: string, metadata: BlobReportMetadata, parsedEvents: JsonEvent[] }[] = []; await fs.promises.mkdir(path.join(dir, 'resources'), { recursive: true });