Skip to content

Instantly share code, notes, and snippets.

@tekwiz
Last active December 30, 2016 16:13
Show Gist options
  • Save tekwiz/895da8b3ac53ec40c945d7aedc9f7d70 to your computer and use it in GitHub Desktop.
Save tekwiz/895da8b3ac53ec40c945d7aedc9f7d70 to your computer and use it in GitHub Desktop.
Node.js 6 global console scope issue

Node.js 6 global console scope issue

The assignment to console.debug on console-scope-test.js:13 seems to be overriding the assignment on console-scope-test2.js:9, but the strict-equals assertions seem inconsistent.

Run:

NODE_DEBUG=scope1,scope2 node console-scope-test.js

Outputs:

LOAD scope1
LOAD scope2
SCOPE1 8060: Starting the main (scope1)...
SCOPE1 8060: Starting some fake work (scope2)...
SCOPE1 8060: Finished some fake work (scope2).
SCOPE1 8060: Finished in main (scope1).
'use strict';
process.stdout.write('LOAD scope1\n');
const assert = require('assert'),
console = require('console'),
util = require('util'),
scope2 = require('./console-scope-test2');
assert.deepStrictEqual(console, scope2.console);
assert.strictEqual(console.debug, scope2.console.debug);
assert.strictEqual(console.debug, scope2.debug);
console.debug = util.debuglog('scope1');
assert.deepStrictEqual(console, scope2.console);
assert.strictEqual(console.debug, scope2.console.debug);
assert.notStrictEqual(console.debug, scope2.debug); // ??? - Why does this pass when the previous line passes?
function main() {
console.debug('Starting the main (scope1)...');
scope2.fakeWork(() => {
assert.deepStrictEqual(console, scope2.console);
assert.strictEqual(console.debug, scope2.console.debug);
assert.notStrictEqual(console.debug, scope2.debug); // ??? - Why does this pass when the previous line passes?
console.debug('Finished in main (scope1).');
});
}
main();
assert.deepStrictEqual(console, scope2.console);
assert.strictEqual(console.debug, scope2.console.debug);
assert.notStrictEqual(console.debug, scope2.debug); // ??? - Why does this pass when the previous line passes?
'use strict';
process.stdout.write('LOAD scope2\n');
const console = require('console'),
util = require('util');
exports.console = console;
console.debug = util.debuglog('scope2');
exports.debug = console.debug;
exports.fakeWork = function fakeWork(callback) {
console.debug('Starting some fake work (scope2)...'); // ??? - outputs with SCOPE1 prefix
setTimeout(() => {
console.debug('Finished some fake work (scope2).'); // ??? - outputs with SCOPE1 prefix
process.nextTick(callback);
}, 500);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment