Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cherry-pick(#28366): fix: parse report.jsonl without creating large s… #28378

Merged
merged 1 commit into from
Nov 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions packages/playwright/src/reporters/merge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand Down