From d0729c5e29ad43356106ebd6858745e60e66106e Mon Sep 17 00:00:00 2001 From: Ivo Murrell Date: Mon, 27 Mar 2023 14:07:20 +0100 Subject: [PATCH] fix(mocha): force color output for mocha logs 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. --- plugins/mocha/src/tasks/mocha.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/mocha/src/tasks/mocha.ts b/plugins/mocha/src/tasks/mocha.ts index 6d51c0a18..41cc72c84 100644 --- a/plugins/mocha/src/tasks/mocha.ts +++ b/plugins/mocha/src/tasks/mocha.ts @@ -12,7 +12,7 @@ export default class Mocha extends Task { async run(): Promise { 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)