Skip to content

Commit fd84e37

Browse files
CopilotSkn0tt
andauthored
fix(junit): Replace spread operator with for-of loop to prevent RangeError with large console logs (#37767)
Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: Skn0tt <[email protected]> Co-authored-by: Simon Knott <[email protected]>
1 parent 9cc54a9 commit fd84e37

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

packages/playwright/src/reporters/junit.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,10 @@ class JUnitReporter implements ReporterV2 {
193193
const systemOut: string[] = [];
194194
const systemErr: string[] = [];
195195
for (const result of test.results) {
196-
systemOut.push(...result.stdout.map(item => item.toString()));
197-
systemErr.push(...result.stderr.map(item => item.toString()));
196+
for (const item of result.stdout)
197+
systemOut.push(item.toString());
198+
for (const item of result.stderr)
199+
systemErr.push(item.toString());
198200
for (const attachment of result.attachments) {
199201
if (!attachment.path)
200202
continue;

tests/playwright-test/reporter-junit.spec.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,28 @@ for (const useIntermediateMergeReport of [false, true] as const) {
126126
expect(result.exitCode).toBe(1);
127127
});
128128

129+
test('should handle large number of console logs', { annotation: { type: 'issue', description: 'https://github.com/microsoft/playwright/issues/37719' } }, async ({ runInlineTest }, testInfo) => {
130+
test.slow();
131+
// need to go via disk, otherwise our test harness would print 500k lines of stdout to the Github Actions UI that can't handle it.
132+
const reportFile = testInfo.outputPath('report.xml');
133+
const result = await runInlineTest({
134+
'a.test.ts': `
135+
import { test, expect } from '@playwright/test';
136+
test('one', async ({}) => {
137+
test.slow();
138+
for (let i = 0; i < 500000; i++) {
139+
console.log('log line ' + i);
140+
}
141+
});
142+
`,
143+
}, { reporter: 'junit' }, { PLAYWRIGHT_JUNIT_OUTPUT_FILE: reportFile });
144+
expect(result.exitCode).toBe(0);
145+
const report = await fs.promises.readFile(reportFile, 'utf8');
146+
const testcase = parseXML(report)['testsuites']['testsuite'][0]['testcase'][0];
147+
expect(testcase['system-out']).toHaveLength(1);
148+
expect(testcase['system-out'][0]).toContain('log line 99999');
149+
});
150+
129151
test('should render stdout without ansi escapes', async ({ runInlineTest }) => {
130152
const result = await runInlineTest({
131153
'playwright.config.ts': `

0 commit comments

Comments
 (0)