Closed MynockSpit closed 1 year ago
I'm all for it 👍🏻
Note that access to process.env.*
still needs to be guarded since it's not defined in browsers.
I would prefer using just COLORS=false
. That leaves us room to add more levels later on.
:tada: This fix is included in version 8.18.0 :tada:
The release is available on:
Describe the feature you'd like:
A mechanism for turning off color highlighting in all
prettyDOM
calls.When tests are being run in environments that don't respect colors, the output of prettyDOM is very challenging to read.
Example:
Right now, there's an automatic switch based on if you're running in node or not, however, some environments run in node, then output their logs to a format that keeps the escape characters, but doesn't parse them.
Suggested implementation:
Since testing-lilbrary doesn't have a direct command line interface, options are limited. There is some precedence for using an environment variable as is there for a global configuration.
Either would work, but the ideal would be to solve this problem once and move on. As a result, I'd suggest exposing configuration for pretty-format globally. This has two major downsides: it adds complexity (e.g. how do we merge configs?) and it ties us more strongly to
pretty-format
.In this example, I create a custom
DEBUG_HIGHLIGHTING
environment variable, and use it to configure prettyFormat.Describe alternatives you've considered:
Unfortunately, so far as I am aware, there is no alternative w/o some code change. Wrapping
prettyDOM
in your own wrapper that reads an environment variable isn't viable b/c test failures will not use your wrapped prettyDOM, making it a half solution at best.That said, here are two other alternatives to global options configuration:
Environment variable
This would behave much like DEBUG_PRINT_LIMIT does today, in that it would only really have a use in command-line invocations. (Yes, you can use this in the browser, but would have to fake
process.env
first.) However, it would be quite easy to use on the command line:Configure property
Instead of configuring the entire prettyFormat config, just expose highlighting. It's simpler and doesn't tie us to
pretty-format
, but means we may revisit this topic when someone wants to globally customize anything else.In this example, I name the property
colors
to show that we could theoretically stay away from the language used bypretty-format
.