Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix(junit): Replace spread operator with for-of loop to prevent RangeError with large console logs #37767

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

Closed
Copilot wants to merge 6 commits into main from copilot/fix-rangeerror-junit-reporter

Conversation

Copy link
Contributor

@Copilot Copilot AI commented Oct 8, 2025
edited
Loading

Problem

The JUnit reporter was failing with RangeError: Maximum call stack size exceeded when tests produced a large number of console logs (>100k). This occurred because the reporter was using the spread operator to add stdout/stderr items to arrays:

systemOut.push(...result.stdout.map(item => item.toString()));
systemErr.push(...result.stderr.map(item => item.toString()));

The spread operator (...) causes stack overflow when spreading very large arrays, as it expands all arguments on the call stack at once.

Solution

Replaced the spread operator with simple for-of loops that push items one at a time:

for (const item of result.stdout)
 systemOut.push(item.toString());
for (const item of result.stderr)
 systemErr.push(item.toString());

This approach doesn't stress the call stack and can handle arbitrarily large numbers of log entries.

Testing

Added a new test case should handle large number of console logs that generates 100,000 console.log statements to verify the reporter no longer crashes with RangeError. All existing JUnit reporter tests continue to pass.

Fixes #[issue_number]

Original prompt

This section details on the original issue you should resolve

<issue_title>[Bug]: RangeError in junit reporter if test has too many logs</issue_title>
<issue_description>### Version

1.54.1

Steps to reproduce

Running the test

test('Playwright bug POC', async ({ page }) => {
 for (let i = 0; i < 500000; i++) {
 console.log(i);
 }
});

with the junit reporter enabled

Expected behavior

It should not break when a test has too many logs

Actual behavior

Playwright will fail with

Error in reporter RangeError: Maximum call stack size exceeded
at JUnitReporter._addTestCase (/node_modules/playwright/lib/reporters/junit.js:176:17)
at JUnitReporter._buildTestSuite (/node_modules/playwright/lib/reporters/junit.js:109:18)

This points to
systemOut.push(...result.stdout.map((item) => item.toString()));

Which fails because Array.prototype.push is being called with too many arguments causing the stack to overflow

If there is any trouble reproducing this issue I have only used node.js so I do not know if this issue exists anywhere else. The number of logs that triggers this bug is not always the exact same it seems to depend on the whims of v8's stack allocation

Additional context

The same could in theory happen if you have many errors although less likely to occur

Environment

System:
 OS: Linux 6.8 Ubuntu 24.04.2 LTS 24.04.2 LTS (Noble Numbat)
 CPU: (16) x64 AMD Ryzen 9 7950X3D 16-Core Processor
 Memory: 40.52 GB / 60.55 GB
 Container: Yes
 Binaries:
 Node: 24.9.0 - /usr/local/bin/node
 npm: 11.6.0 - /usr/local/bin/npm
 IDEs:
 VSCode: 1.7.33 - /home/dev/.cursor-server/bin/a84f941711ad680a635c8a3456002833186c4840/bin/remote-cli/code
 Languages:
 Bash: 5.2.21 - /usr/bin/bash
 npmPackages:
 @playwright/test: 1.54.1 => 1.54.1
```</issue_description>

## Comments on the Issue (you are @copilot in this section)

<comments>
<comment_new><author>@Skn0tt</author><body>
@copilot please fix this. first write a reproduction test in reporter-junit.spec.ts, you can base it off `should render stdout`. Ensure that it's failing with the mentioned error. Then replace the `systemOut.push(` line that the author mentions with a for-of-loop. Ensure that the test is now passing.</body></comment_new>
</comments>
Fixes #37719

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

...x RangeError with large logs
Co-authored-by: Skn0tt <14912729+Skn0tt@users.noreply.github.com>
@Copilot Copilot AI changed the title (削除) [WIP] Fix RangeError in JUnit reporter with excessive logs (削除ここまで) (追記) fix(junit): Replace spread operator with for-of loop to prevent RangeError with large console logs (追記ここまで) Oct 8, 2025
@Copilot Copilot AI requested a review from Skn0tt October 8, 2025 14:15
Copilot finished work on behalf of Skn0tt October 8, 2025 14:15
@Skn0tt Skn0tt marked this pull request as ready for review October 8, 2025 14:18
@Skn0tt Skn0tt requested a review from dgozman October 8, 2025 14:18

This comment has been minimized.

Copy link
Member

Skn0tt commented Oct 9, 2025

Hmm, it appears that the combination of a merged report and Node 18 leads to truncation. Interesting 🤔

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

Copy link
Contributor

Test results for "tests 1"

1 flaky ⚠️ [firefox-library] › library/inspector/cli-codegen-1.spec.ts:1079 › cli codegen › should not throw csp directive violation errors `@firefox-ubuntu-22.04-node18`

47110 passed, 815 skipped


Merge workflow run.

Copy link
Contributor

Test results for "MCP"

2570 passed, 108 skipped


Merge workflow run.

Copy link
Member

Stale

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@dgozman dgozman dgozman approved these changes

@Skn0tt Skn0tt Awaiting requested review from Skn0tt

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

[Bug]: RangeError in junit reporter if test has too many logs

AltStyle によって変換されたページ (->オリジナル) /