Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fixup: oh no, this is bringing in something like #32308
  • Loading branch information
bmeck committed Mar 7, 2022
commit fdb31dd1e3ed3167252fb43014a814a62cad5761
4 changes: 4 additions & 0 deletions lib/internal/console/constructor.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,10 @@ ObjectDefineProperties(Console.prototype, {
...consolePropAttributes,
value: function(stream) {
let color = this[kColorMode];
if (typeof color === 'function') {
color = color();
process._rawDebug(`COLOR: ${color}`)
}
if (color === 'auto') {
color = stream.isTTY && (
typeof stream.getColorDepth === 'function' ?
Expand Down
9 changes: 8 additions & 1 deletion lib/internal/console/global.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const {
ReflectOwnKeys,
} = primordials;

const console = require('console');
const {
Console,
kBindStreamsLazy,
Expand All @@ -44,8 +45,14 @@ for (const prop of ReflectOwnKeys(Console.prototype)) {
ReflectDefineProperty(globalConsole, prop, desc);
}

const {
getColorDepth
} = require('internal/tty');
globalConsole[kBindStreamsLazy](process);
globalConsole[kBindProperties](true, 'auto');
globalConsole[kBindProperties](true, () => {
process._rawDebug('getColorDepth ' + getColorDepth());
return getColorDepth() > 2 || 'auto';
});

// This is a legacy feature - the Console constructor is exposed on
// the global console instance.
Expand Down
4 changes: 2 additions & 2 deletions lib/internal/util/debuglog.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ function debuglogImpl(enabled, set) {
debugImpls[set] = function debug(maybeFmt, ...args) {
if (typeof maybeFmt === 'string') {
// eslint-disable-next-line
console.debug(`%s %i: ${maybeFmt}`, set, pid, ...args);
console.error(`%s %o: ${maybeFmt}`, set, pid, ...args);
} else {
// eslint-disable-next-line
console.debug('%s %i:', set, pid, maybeFmt, ...args);
console.error('%s %o:', set, pid, maybeFmt, ...args);
}
};
} else {
Expand Down
27 changes: 18 additions & 9 deletions test/embedding/test-embedding.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,40 @@ if (common.isWindows) {
}
binary = path.resolve(__dirname, '..', '..', binary);

const env = {
...process.env,
NODE_DISABLE_COLORS: true
};
const spawnOptions = {
env,
encoding: 'utf8'
};

assert.strictEqual(
child_process.spawnSync(binary, ['console.log(42)'])
.stdout.toString().trim(),
child_process.spawnSync(binary, ['console.log(42)'], spawnOptions)
.stdout.trim(),
'42');

assert.strictEqual(
child_process.spawnSync(binary, ['console.log(embedVars.nön_ascıı)'])
.stdout.toString().trim(),
child_process.spawnSync(binary, ['console.log(embedVars.nön_ascıı)'], spawnOptions)
.stdout.trim(),
'🏳️‍🌈');

assert.strictEqual(
child_process.spawnSync(binary, ['console.log(42)'])
.stdout.toString().trim(),
child_process.spawnSync(binary, ['console.log(42)'], spawnOptions)
.stdout.trim(),
'42');

assert.strictEqual(
child_process.spawnSync(binary, ['throw new Error()']).status,
child_process.spawnSync(binary, ['throw new Error()'], spawnOptions).status,
1);

assert.strictEqual(
child_process.spawnSync(binary, ['process.exitCode = 8']).status,
child_process.spawnSync(binary, ['process.exitCode = 8'], spawnOptions).status,
8);


const fixturePath = JSON.stringify(fixtures.path('exit.js'));
assert.strictEqual(
child_process.spawnSync(binary, [`require(${fixturePath})`, 92]).status,
child_process.spawnSync(binary, [`require(${fixturePath})`, 92], spawnOptions).status,
92);
61 changes: 36 additions & 25 deletions test/sequential/test-util-debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,27 +32,27 @@ else
parent();

function parent() {
test('foo,tud,bar', true, 'tud');
test('foo,tud', true, 'tud');
test('tud,bar', true, 'tud');
// test('foo,tud,bar', true, 'tud');
// test('foo,tud', true, 'tud');
// test('tud,bar', true, 'tud');
test('tud', true, 'tud');
test('foo,bar', false, 'tud');
test('', false, 'tud');
// test('foo,bar', false, 'tud');
// test('', false, 'tud');

test('###', true, '###');
test('hi:)', true, 'hi:)');
test('f$oo', true, 'f$oo');
test('f$oo', false, 'f.oo');
test('no-bar-at-all', false, 'bar');
// test('###', true, '###');
// test('hi:)', true, 'hi:)');
// test('f$oo', true, 'f$oo');
// test('f$oo', false, 'f.oo');
// test('no-bar-at-all', false, 'bar');

test('test-abc', true, 'test-abc');
test('test-a', false, 'test-abc');
test('test-*', true, 'test-abc');
test('test-*c', true, 'test-abc');
test('test-*abc', true, 'test-abc');
test('abc-test', true, 'abc-test');
test('a*-test', true, 'abc-test');
test('*-test', true, 'abc-test');
// test('test-abc', true, 'test-abc');
// test('test-a', false, 'test-abc');
// test('test-*', true, 'test-abc');
// test('test-*c', true, 'test-abc');
// test('test-*abc', true, 'test-abc');
// test('abc-test', true, 'abc-test');
// test('a*-test', true, 'abc-test');
// test('*-test', true, 'abc-test');
}

function test(environ, shouldWrite, section, forceColors = false) {
Expand Down Expand Up @@ -100,17 +100,28 @@ 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' : 'false'
}).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.
Expand Down