-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Description
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 reports code appears correct, but I tracked the problem down to a combination of two places in lib/mocha.js:
- in
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. - In
Mocha.prototype.runthere is the line:
exports.reporters.Base.useColors = options.useColors;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 reports modules. So this one always overrides what is set in reporters modules, and always sets it to true, unless you explicitly call -C/--no-colors.
A correction would be to change that last line to:
if (exports.reporters.Base.useColors == undefined) exports.reporters.Base.useColors = options.useColors;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