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

format: fix issues with colors support #2026

Merged
merged 15 commits into from
May 5, 2022
Merged

format: fix issues with colors support #2026

merged 15 commits into from
May 5, 2022

Conversation

davidjgoss
Copy link
Contributor

@davidjgoss davidjgoss commented May 1, 2022

🤔 What's changed?

We recently switched from colors to chalk for handling terminal colors. chalk includes its own rather comprehensive support checks at runtime, which had the unintended effect of disregarding a user-provided colorsEnabled: true (fixes #2011).

Now, rather than our own support check (which was just stream.isTTY), we explicitly delegate to chalk's detection library, for the specific output stream in question, and then construct our own chalk instance with the result (having overrided it based on the format option if necessary). See the feature file and docs for more detail, but the upshot is:

  • Auto detection of colors support is better than it was
  • The colorsEnabled option now works again
  • Users can also use FORCE_COLOR which chalk supports, and we recommend it (for reasons in the docs)

🏷️ What kind of change is this?

  • 🏦 Refactoring/debt/DX (improvement to code design, tooling, documentation etc. without changing behaviour)
  • 🐛 Bug fix (non-breaking change which fixes a defect)

♻️ Anything particular you want feedback on?

🚨 After considering this, I'd like to go a bit further and deprecate (with intent to eventually remove) the colorsEnabled format option in favour of having users just use the kinda-standard FORCE_COLOR environment variable, which can at least influence other tools like assertion libraries which use chalk directly (see #1551) and would remove some complexity on our side (as we'd just fully delegate the logic to supports-color). Mocha folks have also leant into FORCE_COLOR to some degree in mochajs/mocha#3641

Unless there are some implications I'm not seeing for integrators using Cucumber programmatically - paging @nicojs @jan-molak?

📋 Checklist:

  • I agree to respect and uphold the Cucumber Community Code of Conduct
  • I've changed the behaviour of the code
    • I have added/updated tests to cover my changes.
  • My change requires a change to the documentation.
    • I have updated the documentation accordingly.
  • Users should know about my change
    • I have added an entry to the "Unreleased" section of the CHANGELOG, linking to this pull request.

This text was originally generated from a template, then edited by hand. You can modify the template here.

@coveralls
Copy link

coveralls commented May 1, 2022

Coverage Status

Coverage increased (+0.09%) to 98.33% when pulling 64882ed on fix/colors-fixes into 5c8409c on main.

Copy link
Contributor

@aurelien-reeves aurelien-reeves left a comment

Choose a reason for hiding this comment

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

Looks good 🙂

Changelog entry is missing

Also, I do not get why do we add a stream to getColorFns?

docs/formatters.md Outdated Show resolved Hide resolved
src/formatter/get_color_fns.ts Show resolved Hide resolved
davidjgoss and others added 3 commits May 3, 2022 16:52
Co-authored-by: Aurélien Reeves <aurelien.reeves@smartbear.com>
@davidjgoss
Copy link
Contributor Author

Also, I do not get why do we add a stream to getColorFns?

We pass in the stream that the formatter is outputting to, so that supports-colors will detect the colors support for that particular stream, otherwise it would just look at process.stdout which may or may not be right.

@davidjgoss davidjgoss merged commit d00a670 into main May 5, 2022
@davidjgoss davidjgoss deleted the fix/colors-fixes branch May 5, 2022 08:11
@binarymist
Copy link

Thanks Team, tested and all good!

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.

formatter: colorsEnabled: true not honoured
4 participants