Skip to content

Commit

Permalink
fix(mocha): force color output for mocha logs
Browse files Browse the repository at this point in the history
As with many CLI tools, mocha supports ANSI colours for its test
reporting but disables them if it's not connected to a TTY (i.e., if
it's not an interactive session, such as when it's run in a CI or if
it's being piped to another script). It doesn't detect a TTY in our case
as we're piping its stdout and stderr through our winston logging
infrastructure rather than outputting to the user's terminal directly.
In order to get colourful output then, let's force it via mocha's
--color option.
  • Loading branch information
ivomurrell committed Mar 27, 2023
1 parent 235a902 commit d0729c5
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion plugins/mocha/src/tasks/mocha.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default class Mocha extends Task<typeof MochaSchema> {
async run(): Promise<void> {
const files = await promisify(glob)(this.options.files)

const args = [this.options.configPath ? `--config=${this.options.configPath}` : '', ...files]
const args = ['--color', this.options.configPath ? `--config=${this.options.configPath}` : '', ...files]
this.logger.info(`running mocha ${args.join(' ')}`)
const child = fork(mochaCLIPath, args, { silent: true })
hookFork(this.logger, 'mocha', child)
Expand Down

0 comments on commit d0729c5

Please sign in to comment.