| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -179,6 +179,7 @@ function setup(root) { | |||
| 179 | 179 | topLevel: 0, | |
| 180 | 180 | suites: 0, | |
| 181 | 181 | }, | |
| 182 | + shouldColorizeTestFiles: false, | ||
| 182 | 183 | }; | |
| 183 | 184 | root.startTime = hrtime(); | |
| 184 | 185 | return root; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -347,6 +347,9 @@ function runTestFile(path, root, inspectPort, filesWatcher, testNamePatterns) { | |||
| 347 | 347 | stdio.push('ipc'); | |
| 348 | 348 | env.WATCH_REPORT_DEPENDENCIES = '1'; | |
| 349 | 349 | } | |
| 350 | + if (root.harness.shouldColorizeTestFiles) { | ||
| 351 | + env.FORCE_COLOR = '1'; | ||
| 352 | + } | ||
| 350 | 353 | ||
| 351 | 354 | const child = spawn(process.execPath, args, { signal: t.signal, encoding: 'utf8', env, stdio }); | |
| 352 | 355 | runningProcesses.set(path, child); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -16,7 +16,7 @@ const { createWriteStream } = require('fs'); | |||
| 16 | 16 | const { pathToFileURL } = require('internal/url'); | |
| 17 | 17 | const { createDeferredPromise } = require('internal/util'); | |
| 18 | 18 | const { getOptionValue } = require('internal/options'); | |
| 19 | - const { green, red, white } = require('internal/util/colors'); | ||
| 19 | + const { green, red, white, shouldColorize } = require('internal/util/colors'); | ||
| 20 | 20 | ||
| 21 | 21 | const { | |
| 22 | 22 | codes: { | |
@@ -115,9 +115,10 @@ function tryBuiltinReporter(name) { | |||
| 115 | 115 | return require(builtinPath); | |
| 116 | 116 | } | |
| 117 | 117 | ||
| 118 | - async function getReportersMap(reporters, destinations) { | ||
| 118 | + async function getReportersMap(reporters, destinations, rootTest) { | ||
| 119 | 119 | return SafePromiseAllReturnArrayLike(reporters, async (name, i) => { | |
| 120 | 120 | const destination = kBuiltinDestinations.get(destinations[i]) ?? createWriteStream(destinations[i]); | |
| 121 | + rootTest.harness.shouldColorizeTestFiles ||= shouldColorize(destination); | ||
| 121 | 122 | ||
| 122 | 123 | // Load the test reporter passed to --test-reporter | |
| 123 | 124 | let reporter = tryBuiltinReporter(name); | |
@@ -154,7 +155,7 @@ async function getReportersMap(reporters, destinations) { | |||
| 154 | 155 | ||
| 155 | 156 | async function setupTestReporters(rootTest) { | |
| 156 | 157 | const { reporters, destinations } = parseCommandLine(); | |
| 157 | - const reportersMap = await getReportersMap(reporters, destinations); | ||
| 158 | + const reportersMap = await getReportersMap(reporters, destinations, rootTest); | ||
| 158 | 159 | for (let i = 0; i < reportersMap.length; i++) { | |
| 159 | 160 | const { reporter, destination } = reportersMap[i]; | |
| 160 | 161 | compose(rootTest.reporter, reporter).pipe(destination); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,7 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + | ||
| 3 | + const test = require('node:test'); | ||
| 4 | + console.log({ foo: 'bar' }); | ||
| 5 | + test('passing test', () => { | ||
| 6 | + console.log(1); | ||
| 7 | + }); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,11 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + const common = require('../../../common'); | ||
| 3 | + const { once } = require('node:events'); | ||
| 4 | + const { spawn } = require('node:child_process'); | ||
| 5 | + const fixtures = require('../../../common/fixtures'); | ||
| 6 | + | ||
| 7 | + (async function run() { | ||
| 8 | + const test = fixtures.path('test-runner/output/arbitrary-output-colored-1.js'); | ||
| 9 | + await once(spawn(process.execPath, ['--test', test], { stdio: 'inherit', env: { FORCE_COLOR: 1 } }), 'exit'); | ||
| 10 | + await once(spawn(process.execPath, ['--test', '--test-reporter', 'tap', test], { stdio: 'inherit', env: { FORCE_COLOR: 1 } }), 'exit'); | ||
| 11 | + })().then(common.mustCall()); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,28 @@ | |||
| 1 | + { foo: [32m'bar'[39m } | ||
| 2 | + [33m1[39m | ||
| 3 | + [32m✔ passing test [90m(*ms)[39m[39m | ||
| 4 | + [34mℹ tests 1[39m | ||
| 5 | + [34mℹ suites 0[39m | ||
| 6 | + [34mℹ pass 1[39m | ||
| 7 | + [34mℹ fail 0[39m | ||
| 8 | + [34mℹ cancelled 0[39m | ||
| 9 | + [34mℹ skipped 0[39m | ||
| 10 | + [34mℹ todo 0[39m | ||
| 11 | + [34mℹ duration_ms *[39m | ||
| 12 | + TAP version 13 | ||
| 13 | + # { foo: [32m'bar'[39m } | ||
| 14 | + # [33m1[39m | ||
| 15 | + # Subtest: passing test | ||
| 16 | + ok 1 - passing test | ||
| 17 | + --- | ||
| 18 | + duration_ms: * | ||
| 19 | + ... | ||
| 20 | + 1..1 | ||
| 21 | + # tests 1 | ||
| 22 | + # suites 0 | ||
| 23 | + # pass 1 | ||
| 24 | + # fail 0 | ||
| 25 | + # cancelled 0 | ||
| 26 | + # skipped 0 | ||
| 27 | + # todo 0 | ||
| 28 | + # duration_ms * | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3,6 +3,10 @@ import * as fixtures from '../common/fixtures.mjs'; | |||
| 3 | 3 | import * as snapshot from '../common/assertSnapshot.js'; | |
| 4 | 4 | import { describe, it } from 'node:test'; | |
| 5 | 5 | ||
| 6 | + const skipForceColors = | ||
| 7 | + process.config.variables.icu_gyp_path !== 'tools/icu/icu-generic.gyp' || | ||
| 8 | + process.config.variables.node_shared_openssl; | ||
| 9 | + | ||
| 6 | 10 | function replaceTestDuration(str) { | |
| 7 | 11 | return str | |
| 8 | 12 | .replaceAll(/duration_ms: 0(\r?\n)/g, 'duration_ms: ZERO$1') | |
@@ -46,8 +50,14 @@ const tests = [ | |||
| 46 | 50 | { name: 'test-runner/output/unresolved_promise.js' }, | |
| 47 | 51 | { name: 'test-runner/output/default_output.js', transform: specTransform, tty: true }, | |
| 48 | 52 | { name: 'test-runner/output/arbitrary-output.js' }, | |
| 53 | + !skipForceColors ? { | ||
| 54 | + name: 'test-runner/output/arbitrary-output-colored.js', | ||
| 55 | + transform: snapshot.transform(specTransform, replaceTestDuration), tty: true | ||
| 56 | + } : false, | ||
| 49 | 57 | { name: 'test-runner/output/dot_output_custom_columns.js', transform: specTransform, tty: true }, | |
| 50 | - ].map(({ name, tty, transform }) => ({ | ||
| 58 | + ] | ||
| 59 | + .filter(Boolean) | ||
| 60 | + .map(({ name, tty, transform }) => ({ | ||
| 51 | 61 | name, | |
| 52 | 62 | fn: common.mustCall(async () => { | |
| 53 | 63 | await snapshot.spawnAndAssert(fixtures.path(name), transform ?? defaultTransform, { tty }); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments