Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: improve the code in test-util-debug.js #10583

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
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
23 changes: 11 additions & 12 deletions test/sequential/test-util-debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,44 +17,43 @@ function parent() {
}

function test(environ, shouldWrite) {
var expectErr = '';
let expectErr = '';
if (shouldWrite) {
expectErr = 'TUD %PID%: this { is: \'a\' } /debugging/\n' +
'TUD %PID%: number=1234 string=asdf obj={"foo":"bar"}\n';
}
var expectOut = 'ok\n';
const expectOut = 'ok\n';

const spawn = require('child_process').spawn;
var child = spawn(process.execPath, [__filename, 'child'], {
const child = spawn(process.execPath, [__filename, 'child'], {
env: Object.assign(process.env, { NODE_DEBUG: environ })
});

expectErr = expectErr.split('%PID%').join(child.pid);

var err = '';
let err = '';
child.stderr.setEncoding('utf8');
child.stderr.on('data', function(c) {
child.stderr.on('data', (c) => {
err += c;
});

var out = '';
let out = '';
child.stdout.setEncoding('utf8');
child.stdout.on('data', function(c) {
child.stdout.on('data', (c) => {
out += c;
});

child.on('close', common.mustCall(function(c) {
child.on('close', common.mustCall((c) => {
assert(!c);
assert.equal(err, expectErr);
assert.equal(out, expectOut);
console.log('ok %j %j', environ, shouldWrite);
assert.strictEqual(err, expectErr);
assert.strictEqual(out, expectOut);
}));
}


function child() {
const util = require('util');
var debug = util.debuglog('tud');
const debug = util.debuglog('tud');
debug('this', { is: 'a' }, /debugging/);
debug('number=%d string=%s obj=%j', 1234, 'asdf', { foo: 'bar' });
console.log('ok');
Expand Down