-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Color codes output to non-ttys #1304
Copy link
Copy link
Closed
Labels
status: accepting prsMocha can use your help with this one!Mocha can use your help with this one!type: buga defect, confirmed by a maintainera defect, confirmed by a maintainer
Metadata
Metadata
Assignees
Labels
status: accepting prsMocha can use your help with this one!Mocha can use your help with this one!type: buga defect, confirmed by a maintainera defect, confirmed by a maintainer
Type
Fields
Give feedbackNo fields configured for issues without a type.
Like the writer of #1296 I am piping the output of Mocha tests to a non-tty (file in this case), and am getting control characters (specifically those for colors) in my text. This is nasty as I am trying to support unicode characters, and that makes life difficult.
The
reportscode appears correct, but I tracked the problem down to a combination of two places inlib/mocha.js:Mocha.prototype.useColorsthe default if there is no setting is to betrue, if you have selected neither-c/--colorsor-C/--no-colorsthis gets called called bymocha.jswithundefinedin the linethis.useColors(options.useColors), sothis.options.useColorsistrue.Mocha.prototype.runthere is the line:Since this does not get run until the Mocha object is instantiated, it is run later than the code in the top-level of the the
reportsmodules. So this one always overrides what is set inreportersmodules, and always sets it totrue, unless you explicitly call-C/--no-colors.A correction would be to change that last line to: