diff --git a/lib/internal/bootstrap/browser.js b/lib/internal/bootstrap/browser.js index 68dac3b1ca4b8c..798d21ea16f3dd 100644 --- a/lib/internal/bootstrap/browser.js +++ b/lib/internal/bootstrap/browser.js @@ -78,8 +78,6 @@ function createGlobalConsole(consoleFromVM) { const inspector = require('internal/util/inspector'); // This will be exposed by `require('inspector').console` later. inspector.consoleFromVM = consoleFromVM; - // TODO(joyeecheung): postpone this until the first time inspector - // is activated. inspector.wrapConsole(consoleFromNode, consoleFromVM); const { setConsoleExtensionInstaller } = internalBinding('inspector'); // Setup inspector command line API. diff --git a/lib/internal/util/debuglog.js b/lib/internal/util/debuglog.js index 4b5c7cab44ad77..d3a19b745ed048 100644 --- a/lib/internal/util/debuglog.js +++ b/lib/internal/util/debuglog.js @@ -10,8 +10,6 @@ const { StringPrototypeToUpperCase, } = primordials; -const { inspect, format, formatWithOptions } = require('internal/util/inspect'); - // `debugImpls` and `testEnabled` are deliberately not initialized so any call // to `debuglog()` before `initializeDebugEnv()` is called will throw. let debugImpls; @@ -51,11 +49,14 @@ function debuglogImpl(enabled, set) { if (enabled) { const pid = process.pid; emitWarningIfNeeded(set); - debugImpls[set] = function debug(...args) { - const colors = process.stderr.hasColors && process.stderr.hasColors(); - const msg = formatWithOptions({ colors }, ...args); - const coloredPID = inspect(pid, { colors }); - process.stderr.write(format('%s %s: %s\n', set, coloredPID, msg)); + debugImpls[set] = function debug(maybeFmt, ...args) { + if (typeof maybeFmt === 'string') { + // eslint-disable-next-line + console.error(`%s %o: ${maybeFmt}`, set, pid, ...args); + } else { + // eslint-disable-next-line + console.error('%s %o:', set, pid, maybeFmt, ...args); + } }; } else { debugImpls[set] = noop; diff --git a/test/sequential/test-util-debug.js b/test/sequential/test-util-debug.js index f8be25f6f880b8..e76a585d65c127 100644 --- a/test/sequential/test-util-debug.js +++ b/test/sequential/test-util-debug.js @@ -100,23 +100,46 @@ function test(environ, shouldWrite, section, forceColors = false) { }); child.on('close', common.mustCall((c) => { - assert(!c); - assert.strictEqual(err, expectErr); - assert.strictEqual(out, expectOut); - // Run the test again, this time with colors enabled. - if (!forceColors) { - test(environ, shouldWrite, section, true); + try { + assert(!c); + assert.strictEqual(err, expectErr); + assert.strictEqual(out, expectOut); + // Run the test again, this time with colors enabled. + if (!forceColors) { + test(environ, shouldWrite, section, true); + } + } catch (e) { + console.error('FAILED PERMUTATION:', { environ, shouldWrite, section, forceColors }); + console.error('COMMAND:', Object.entries({ + NODE_DEBUG: environ, + FORCE_COLOR: forceColors ? 'true' : '' + }).reduce( + (acc, [k, v]) => { acc.push(`${k}=${JSON.stringify(v)}`); return acc; }, + [] + ).join(' '), 'node', [__filename, 'child', JSON.stringify(section)].join(' ')); + throw e; } })); } - function child(section) { const tty = require('tty'); // Make sure we check for colors, no matter of the stream's default. + + const forceColors = process.env.FORCE_COLOR === 'true'; Object.defineProperty(process.stderr, 'hasColors', { value: tty.WriteStream.prototype.hasColors }); + Object.defineProperty(process.stderr, 'isTTY', { + value: forceColors, + }); + Object.defineProperty(process.stdout, 'hasColors', { + value: tty.WriteStream.prototype.hasColors + }); + Object.defineProperty(process.stdout, 'isTTY', { + value: forceColors, + }); + // eslint-disable-next-line no-restricted-syntax const debug = util.debuglog(section, common.mustCall((cb) => { assert.strictEqual(typeof cb, 'function');