Skip to content

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

@aslakhellesoy

Description

@aslakhellesoy

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.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions