Skip to content
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

Strip ANSI colour escapes from STDOUT and STDERR when streams are not TTY #1698

Closed
aslakhellesoy opened this issue Jun 16, 2021 · 0 comments · Fixed by #2035
Closed

Strip ANSI colour escapes from STDOUT and STDERR when streams are not TTY #1698

aslakhellesoy opened this issue Jun 16, 2021 · 0 comments · Fixed by #2035
Assignees
Labels
⚡ enhancement Request for new functionality

Comments

@aslakhellesoy
Copy link
Contributor

When cucumber-js' STDERR or STDOUT is redirected to a file, there are still ANSI escapes in the output.

We should remove ANSI escapes when writing to a non-TTY stream.

One of the reasons we should do this is that the suggestion to redirect STDERR to a file in #1458 makes it difficult to read the contents written to that file:

�[32m�[1m┌──────────────────────────────────────────────────────────────────────────┐�[0m
�[32m�[1m│�[0m View your Cucumber Report at:                                            �[32m�[1m│�[0m
�[32m�[1m│�[0m �[1m�[36m�[4mhttps://reports.cucumber.io/reports/59fbb8b0-a625-4f0e-8c5b-284b95387f03�[0m �[32m�[1m│�[0m
�[32m�[1m│�[0m                                                                          �[32m�[1m│�[0m
�[32m�[1m│�[0m �[1mThis report will self-destruct in 24h.�[0m                                   �[32m�[1m│�[0m
�[32m�[1m│�[0m Keep reports forever: �[4m�[1m�[36mhttps://reports.cucumber.io/profile�[0m                �[32m�[1m│�[0m
�[32m�[1m└──────────────────────────────────────────────────────────────────────────┘�[0m

Since the ANSI escapes in this case come from the Cucumber Reports server (and not our own code), I suggest we implement this like this:

const stderr = process.stderr.pipe(replaceAnsiStream())
const stdout = process.stderr.pipe(replaceAnsiStream())

See https://github.com/chalk/strip-ansi-stream

Also see #1050 which didn't really solve the problem of stripping ANSI - it just disallows using formatters that output ANSI.

@aslakhellesoy aslakhellesoy added the ⚡ enhancement Request for new functionality label Jun 16, 2021
@davidjgoss davidjgoss self-assigned this May 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
⚡ enhancement Request for new functionality
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants