From 4887213f2e5e38e1975fde87cbb881a15b4d14ba Mon Sep 17 00:00:00 2001 From: Giovanni Date: Sat, 15 Jun 2024 10:11:38 +0200 Subject: [PATCH] test_runner: added colors to dot reporter PR-URL: https://github.com/nodejs/node/pull/53450 Fixes: https://github.com/nodejs/node/issues/51770 Reviewed-By: Moshe Atlow Reviewed-By: Chemi Atlow Reviewed-By: Luigi Pinca --- lib/internal/test_runner/reporter/dot.js | 4 ++-- .../test-runner/output/dot_output_custom_columns.js | 3 +++ .../test-runner/output/dot_output_custom_columns.snapshot | 6 +++--- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/internal/test_runner/reporter/dot.js b/lib/internal/test_runner/reporter/dot.js index e9ba0b8dc7bd11..1e581f7a337845 100644 --- a/lib/internal/test_runner/reporter/dot.js +++ b/lib/internal/test_runner/reporter/dot.js @@ -12,10 +12,10 @@ module.exports = async function* dot(source) { const failedTests = []; for await (const { type, data } of source) { if (type === 'test:pass') { - yield '.'; + yield `${colors.green}.${colors.clear}`; } if (type === 'test:fail') { - yield 'X'; + yield `${colors.red}X${colors.clear}`; ArrayPrototypePush(failedTests, data); } if ((type === 'test:fail' || type === 'test:pass') && ++count === columns) { diff --git a/test/fixtures/test-runner/output/dot_output_custom_columns.js b/test/fixtures/test-runner/output/dot_output_custom_columns.js index 875ead9efc22a5..72a734f1e13361 100644 --- a/test/fixtures/test-runner/output/dot_output_custom_columns.js +++ b/test/fixtures/test-runner/output/dot_output_custom_columns.js @@ -1,6 +1,9 @@ // Flags: --test-reporter=dot 'use strict'; process.stdout.columns = 30; +process.env.FORCE_COLOR = '1'; +delete process.env.NODE_DISABLE_COLORS; +delete process.env.NO_COLOR; const test = require('node:test'); const { setTimeout } = require('timers/promises'); diff --git a/test/fixtures/test-runner/output/dot_output_custom_columns.snapshot b/test/fixtures/test-runner/output/dot_output_custom_columns.snapshot index 1aaaf3eb243ae4..b315dd77465a37 100644 --- a/test/fixtures/test-runner/output/dot_output_custom_columns.snapshot +++ b/test/fixtures/test-runner/output/dot_output_custom_columns.snapshot @@ -1,3 +1,3 @@ -.............................. -......................................... -............................. +[32m.c[32m.c[32m.c[32m.c[32m.c[32m.c[32m.c[32m.c[32m.c[32m.c[32m.c[32m.c[32m.c[32m.c[32m.c[32m.c[32m.c[32m.c[32m.c[32m.c[32m.c[32m.c[32m.c[32m.c[32m.c[32m.c[32m.c[32m.c[32m.c[32m.c +[32m.c[32m.c[32m.c[32m.c[32m.c[32m.c[32m.c[32m.c[32m.c[32m.c[32m.c[32m.c[32m.c[32m.c[32m.c[32m.c[32m.c[32m.c[32m.c[32m.c[32m.c[32m.c[32m.c[32m.c[32m.c[32m.c[32m.c[32m.c[32m.c[32m.c[32m.c[32m.c[32m.c[32m.c[32m.c[32m.c[32m.c[32m.c[32m.c[32m.c[32m.c +[32m.c[32m.c[32m.c[32m.c[32m.c[32m.c[32m.c[32m.c[32m.c[32m.c[32m.c[32m.c[32m.c[32m.c[32m.c[32m.c[32m.c[32m.c[32m.c[32m.c[32m.c[32m.c[32m.c[32m.c[32m.c[32m.c[32m.c[32m.c[32m.c