misc: correct newline wrapping in logs for strings with ANSI codes #33283
+37
−2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Additional details
The log header when Cypress is run, shows the Node Version with path.
In the CI environment of GitHub Actions runners, the paths are longer than on a typical non-CI installation:
macos-15/Users/runner/actions-runner/cached/externals/node24/bin/nodeubuntu-24.04/home/runner/actions-runner/cached/externals/node24/bin/nodewindows-2025C:\actions-runner\cached\externals\node24\bin\node.exeThis results in characters from ANSI escape code sequences being visibly printed to the logs for
macos-15andubuntu-24.04macos-15ubuntu-24.04The shorter path encountered on
windows-2025does not suffer from this issue, and the path is rendered correctly in the log header.The packages/server/lib/util/newlines.js utility is enhanced so that it correctly deals with strings containing ANSI escape sequences, such as created by the chalk package, to set text as gray.
Before checking if a newline is needed, the string to be printed is stripped of any (non-printable) ANSI escape sequences.
If the string then needs wrapping with a newline, the string is returned wrapped without the ANSI escape sequences. This is necessary because in the Cypress run log header, the string is embedded in a table and even if the newline character (
\n) is added to the string without overwriting an ANSI escape sequence, only the first line of the string would be displayed as desired. Following lines have had their color status separately reset.This resolves the issue #32736 for GitHub Actions, since the Node.js paths can be displayed in the table within the available space. They were however getting incorrectly wrapped because newlines.js was counting the non-printing characters of the ANSI escape sequences as printing characters.
Note
Low Risk
Low risk: small, localized change to a string-wrapping utility used in run header formatting, plus added unit coverage; main risk is minor output formatting differences for ANSI-colored paths.
Overview
Fixes log header wrapping when values include ANSI escape sequences (e.g. colored Node.js paths in CI).
addNewlineAtEveryNCharnow strips VT control characters for length calculation, returning the original string when no wrapping is needed but dropping ANSI codes when wrapping occurs to avoid broken table output.Updates unit tests to cover non-wrapping cases and ANSI-colored inputs, and records the user-facing fix in the CLI changelog.
Written by Cursor Bugbot for commit 0efbd03. This will update automatically on new commits. Configure here.
Steps to test
On Windows 11 install Node.js 22.19.0 https://nodejs.org/dist/v22.19.0/node-v22.19.0-x64.msi to
C:\Program Files\home-runner-actions-runner-cachedD\to simulate the Ubuntu path length/home/runner/actions-runner/cached/externals/node24/bin/node, sincenode.exeis added to the original path.How has the user experience changed?
Users of GitHub Actions with Ubuntu or macOS runners will no longer see printed ANSI escape characters in the log header in the Node Version line.
This may also affect other CI providers and could occur if Node.js is installed elsewhere with a longer path. When Node.js is installed locally and default locations are used, the issue would not occur.
PR Tasks
cypress-documentation?type definitions?