mirror of
https://github.com/microsoft/playwright.git
synced 2024-12-14 05:37:20 +03:00
fix: parse report.jsonl without creating large string (#28366)
Reference https://github.com/microsoft/playwright/issues/28362
This commit is contained in:
parent
022b36332d
commit
2e762fd3d2
@ -81,19 +81,37 @@ const commonEvents = new Set(commonEventNames);
|
|||||||
const commonEventRegex = new RegExp(`${commonEventNames.join('|')}`);
|
const commonEventRegex = new RegExp(`${commonEventNames.join('|')}`);
|
||||||
|
|
||||||
function parseCommonEvents(reportJsonl: Buffer): JsonEvent[] {
|
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
|
.filter(line => commonEventRegex.test(line)) // quick filter
|
||||||
.map(line => JSON.parse(line) as JsonEvent)
|
.map(line => JSON.parse(line) as JsonEvent)
|
||||||
.filter(event => commonEvents.has(event.method));
|
.filter(event => commonEvents.has(event.method));
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseTestEvents(reportJsonl: Buffer): JsonEvent[] {
|
function parseTestEvents(reportJsonl: Buffer): JsonEvent[] {
|
||||||
return reportJsonl.toString().split('\n')
|
return splitBufferLines(reportJsonl)
|
||||||
|
.map(line => line.toString('utf8'))
|
||||||
.filter(line => line.length)
|
.filter(line => line.length)
|
||||||
.map(line => JSON.parse(line) as JsonEvent)
|
.map(line => JSON.parse(line) as JsonEvent)
|
||||||
.filter(event => !commonEvents.has(event.method));
|
.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) {
|
async function extractAndParseReports(dir: string, shardFiles: string[], internalizer: JsonStringInternalizer, printStatus: StatusCallback) {
|
||||||
const shardEvents: { file: string, localPath: string, metadata: BlobReportMetadata, parsedEvents: JsonEvent[] }[] = [];
|
const shardEvents: { file: string, localPath: string, metadata: BlobReportMetadata, parsedEvents: JsonEvent[] }[] = [];
|
||||||
await fs.promises.mkdir(path.join(dir, 'resources'), { recursive: true });
|
await fs.promises.mkdir(path.join(dir, 'resources'), { recursive: true });
|
||||||
|
Loading…
Reference in New Issue
Block a user