util: fix debuglog.enabled not being present with callback logger · nodejs/node@6133a82

Original file line numberDiff line numberDiff line change

@@ -57,7 +57,7 @@ function parent() {

5757
5858

function test(environ, shouldWrite, section, forceColors = false) {

5959

let expectErr = '';

60-

const expectOut = shouldWrite ? 'enabled\n' : 'disabled\n';

60+

const expectOut = shouldWrite ? 'outer enabled\ninner enabled\n' : 'outer disabled\ninner disabled\n';

6161
6262

const spawn = require('child_process').spawn;

6363

const child = spawn(process.execPath, [__filename, 'child', section], {

@@ -117,11 +117,18 @@ function child(section) {

117117

Object.defineProperty(process.stderr, 'hasColors', {

118118

value: tty.WriteStream.prototype.hasColors

119119

});

120+
121+

let innerDebug = null;

120122

// eslint-disable-next-line no-restricted-syntax

121123

const debug = util.debuglog(section, common.mustCall((cb) => {

122124

assert.strictEqual(typeof cb, 'function');

125+

innerDebug = cb;

123126

}));

124127

debug('this', { is: 'a' }, /debugging/);

125128

debug('num=%d str=%s obj=%j', 1, 'a', { foo: 'bar' });

126-

console.log(debug.enabled ? 'enabled' : 'disabled');

129+

console.log(debug.enabled ? 'outer enabled' : 'outer disabled');

130+

console.log(innerDebug.enabled ? 'inner enabled' : 'inner disabled');

131+
132+

assert.strictEqual(typeof Object.getOwnPropertyDescriptor(debug, 'enabled').get, 'function');

133+

assert.strictEqual(typeof Object.getOwnPropertyDescriptor(innerDebug, 'enabled').get, 'function');

127134

}