Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Oct 8, 2025

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.

@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
Copy link
Contributor

github-actions bot commented Oct 8, 2025

Test results for "tests 1"

4 failed
❌ [playwright-test] › reporter-junit.spec.ts:129 › merged › should handle large number of console logs @macos-latest-node18-1
❌ [playwright-test] › reporter-junit.spec.ts:129 › merged › should handle large number of console logs @ubuntu-latest-node18-1
❌ [playwright-test] › playwright.trace.spec.ts:345 › should retain traces for interrupted tests @windows-latest-node18-1
❌ [playwright-test] › reporter-junit.spec.ts:129 › merged › should handle large number of console logs @windows-latest-node18-1

3 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`
⚠️ [firefox-page] › page/page-goto.spec.ts:83 › should work with Cross-Origin-Opener-Policy `@firefox-ubuntu-22.04-node18`
⚠️ [playwright-test] › ui-mode-trace.spec.ts:397 › should work behind reverse proxy `@macos-latest-node18-1`

46929 passed, 816 skipped


Merge workflow run.

@Skn0tt
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 🤔

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

3 participants