test: refactor the code in test-util-debug.js
* use const and let instead of var * use assert.strictEqual instead of assert.equal * use arrow functions * removed unwanted console log PR-URL: https://github.com/nodejs/node/pull/10531 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
This commit is contained in:
parent
c1b12a2896
commit
8839d504cc
@ -17,44 +17,43 @@ function parent() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function test(environ, shouldWrite) {
|
function test(environ, shouldWrite) {
|
||||||
var expectErr = '';
|
let expectErr = '';
|
||||||
if (shouldWrite) {
|
if (shouldWrite) {
|
||||||
expectErr = 'TUD %PID%: this { is: \'a\' } /debugging/\n' +
|
expectErr = 'TUD %PID%: this { is: \'a\' } /debugging/\n' +
|
||||||
'TUD %PID%: number=1234 string=asdf obj={"foo":"bar"}\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;
|
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 })
|
env: Object.assign(process.env, { NODE_DEBUG: environ })
|
||||||
});
|
});
|
||||||
|
|
||||||
expectErr = expectErr.split('%PID%').join(child.pid);
|
expectErr = expectErr.split('%PID%').join(child.pid);
|
||||||
|
|
||||||
var err = '';
|
let err = '';
|
||||||
child.stderr.setEncoding('utf8');
|
child.stderr.setEncoding('utf8');
|
||||||
child.stderr.on('data', function(c) {
|
child.stderr.on('data', (c) => {
|
||||||
err += c;
|
err += c;
|
||||||
});
|
});
|
||||||
|
|
||||||
var out = '';
|
let out = '';
|
||||||
child.stdout.setEncoding('utf8');
|
child.stdout.setEncoding('utf8');
|
||||||
child.stdout.on('data', function(c) {
|
child.stdout.on('data', (c) => {
|
||||||
out += c;
|
out += c;
|
||||||
});
|
});
|
||||||
|
|
||||||
child.on('close', common.mustCall(function(c) {
|
child.on('close', common.mustCall((c) => {
|
||||||
assert(!c);
|
assert(!c);
|
||||||
assert.equal(err, expectErr);
|
assert.strictEqual(err, expectErr);
|
||||||
assert.equal(out, expectOut);
|
assert.strictEqual(out, expectOut);
|
||||||
console.log('ok %j %j', environ, shouldWrite);
|
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function child() {
|
function child() {
|
||||||
const util = require('util');
|
const util = require('util');
|
||||||
var debug = util.debuglog('tud');
|
const debug = util.debuglog('tud');
|
||||||
debug('this', { is: 'a' }, /debugging/);
|
debug('this', { is: 'a' }, /debugging/);
|
||||||
debug('number=%d string=%s obj=%j', 1234, 'asdf', { foo: 'bar' });
|
debug('number=%d string=%s obj=%j', 1234, 'asdf', { foo: 'bar' });
|
||||||
console.log('ok');
|
console.log('ok');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user