Skip to content

misc: correct newline wrapping in logs for strings with ANSI codes#33283

Merged
mschile merged 4 commits intocypress-io:developfrom
MikeMcC399:issue-32736-newlines-ansi
Feb 6, 2026
Merged

misc: correct newline wrapping in logs for strings with ANSI codes#33283
mschile merged 4 commits intocypress-io:developfrom
MikeMcC399:issue-32736-newlines-ansi

Conversation

@MikeMcC399
Copy link
Contributor

@MikeMcC399 MikeMcC399 commented Jan 26, 2026

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:

Runner Path
macos-15 /Users/runner/actions-runner/cached/externals/node24/bin/node
ubuntu-24.04 /home/runner/actions-runner/cached/externals/node24/bin/node
windows-2025 C:\actions-runner\cached\externals\node24\bin\node.exe

This results in characters from ANSI escape code sequences being visibly printed to the logs for macos-15 and ubuntu-24.04

macos-15

  │ Node Version:   v24.12.0 (/Users/runner/actions-runner/cached/externals/node24/bin/node)       │
  │                 [39m                                                                           │

ubuntu-24.04

  │ Node Version:   v24.12.0 (/home/runner/actions-runner/cached/externals/node24/bin/node)[0m       │
  │                 39m                                                                            │

The shorter path encountered on windows-2025 does 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. In the case of Cypress run log headers, the text is being set to gray with ANSI escape sequences.

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
Small, localized formatting change to a newline-wrapping utility plus targeted unit tests and a changelog entry; risk is limited to minor log output differences.

Overview
Fixes log header wrapping for strings containing ANSI/VT control codes (eg chalk-colored Node.js paths) by stripping non-printable characters before deciding where to insert newlines, and falling back to returning the original string unchanged when it would fit.

Updates unit coverage in newlines_spec.ts to include length edge cases and ANSI-containing strings, and documents the user-visible behavior change in cli/CHANGELOG.md for GitHub Actions environments.

Written by Cursor Bugbot for commit 38cccfd. 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, since node.exe is added to the original path.

git clone --branch 32736-ansi-escape https://github.com/MikeMcC399/cypress-test-tiny
cd cypress-test-tiny
npm ci
npx cypress run # note 39m character incorrectly displayed
cd ..

npm install yarn@latest -g
git clone --branch issue-32736-newlines-ansi https://github.com/MikeMcC399/cypress
cd cypress
yarn
cd packages/server
yarn test-unit newlines_spec # unit test should pass
cd ../..
yarn cypress:run --project ../cypress-test-tiny # no printed ANSI escape characters in log header
image

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-app-bot
Copy link
Collaborator

@MikeMcC399

This comment was marked as outdated.

@cacieprins cacieprins self-requested a review January 27, 2026 17:35
@cacieprins cacieprins self-assigned this Jan 27, 2026
@MikeMcC399 MikeMcC399 force-pushed the issue-32736-newlines-ansi branch from 0efbd03 to 0e959e8 Compare February 4, 2026 06:54
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.

@MikeMcC399

This comment was marked as resolved.

@MikeMcC399
Copy link
Contributor Author

MikeMcC399 commented Feb 4, 2026

Hi @mschile, I was asked to tag you on PRs I'd like reviewed.

The one here principally benefits use of Cypress in GitHub Actions where the path to the location of Node.js is long enough to mess up the Cypress header log display. The issue has been around for a while and I only recently got around to analyzing the issue and proposing a fix.

Handles strings containing ANSI escape code sequences
If printable string length is within allowed width, does not wrap
Converts strings to plain string without ANSI escape code sequences
when printable width exceeded, then wraps accordingly

Resolves issue displaying longer Node.js paths such as encountered on
GitHub Actions in Ubuntu and macOS runners
@MikeMcC399 MikeMcC399 force-pushed the issue-32736-newlines-ansi branch from 8026e23 to 34d664b Compare February 5, 2026 09:48
@MikeMcC399

This comment was marked as outdated.

@MikeMcC399

This comment was marked as outdated.

@mschile mschile merged commit 877cad2 into cypress-io:develop Feb 6, 2026
64 of 66 checks passed
@MikeMcC399 MikeMcC399 deleted the issue-32736-newlines-ansi branch February 7, 2026 08:03
@MikeMcC399
Copy link
Contributor Author

@mschile

Thank you very much for merging! I rechecked in the develop branch that the steps to test continue to pass.

I would like to test it in GitHub Actions before the release. Unfortunately the pre-release build for the commit 877cad2 is only partially available.

Executing npm install https://cdn.cypress.io/beta/npm/15.10.1/linux-x64/develop-877cad268c9bc1638a30b071f76b8469c5ce48af/cypress.tgz on Ubuntu 24.04 leads to the error

npm error Installing Cypress (version: https://cdn.cypress.io/beta/binary/15.10.1/linux-x64/develop-877cad268c9bc1638a30b071f76b8469c5ce48af/cypress.zip)
npm error
npm error [STARTED] Task without title.
npm error Failed downloading the Cypress binary.
npm error Response code: 404

Perhaps the cache needs some attention?

@mschile
Copy link
Contributor

mschile commented Feb 8, 2026

@MikeMcC399, I purged the cache if you want to try again.

@MikeMcC399
Copy link
Contributor Author

@mschile

I purged the cache if you want to try again.

Thanks for that!

All looks good and ready for release. No stray ANSI escape sequences printing out and disturbing the layout!🙂 See screenshots below.

macOS

image

Ubuntu

image

Windows

image

@cypress-bot
Copy link
Contributor

cypress-bot bot commented Feb 25, 2026

Released in 15.11.0.

This comment thread has been locked. If you are still experiencing this issue after upgrading to
Cypress v15.11.0, please open a new issue.

@cypress-bot cypress-bot bot locked as resolved and limited conversation to collaborators Feb 25, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bad format for Node Version in summary on GitHub Actions

4 participants