Skip to content

Commit 2004efd

Browse files
sreepurnajastiMylesBorins
authored andcommitted
test: improve to use template string
PR-URL: #18097 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Gireesh Punathil <[email protected]>
1 parent 8f9362d commit 2004efd

31 files changed

+50
-53
lines changed

test/message/error_exit.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ require('../common');
33
const assert = require('assert');
44

55
process.on('exit', function(code) {
6-
console.error('Exiting with code=%d', code);
6+
console.error(`Exiting with code=${code}`);
77
});
88

99
assert.strictEqual(1, 2);

test/message/max_tick_depth.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ require('../common');
44
process.maxTickDepth = 10;
55
let i = 20;
66
process.nextTick(function f() {
7-
console.error('tick %d', i);
7+
console.error(`tick ${i}`);
88
if (i-- > 0)
99
process.nextTick(f);
1010
});

test/parallel/test-cluster-net-send.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const fork = require('child_process').fork;
55
const net = require('net');
66

77
if (process.argv[2] !== 'child') {
8-
console.error('[%d] master', process.pid);
8+
console.error(`[${process.pid}] master`);
99

1010
const worker = fork(__filename, ['child']);
1111
let called = false;
@@ -29,7 +29,7 @@ if (process.argv[2] !== 'child') {
2929
assert.ok(called);
3030
});
3131
} else {
32-
console.error('[%d] worker', process.pid);
32+
console.error(`[${process.pid}] worker`);
3333

3434
let socket;
3535
let cbcalls = 0;

test/parallel/test-domain-http-server.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ server.listen(0, next);
4141

4242
function next() {
4343
const port = this.address().port;
44-
console.log('listening on localhost:%d', port);
44+
console.log(`listening on localhost:${port}`);
4545

4646
let requests = 0;
4747
let responses = 0;
@@ -66,7 +66,7 @@ function next() {
6666
dom.add(req);
6767
req.on('response', function(res) {
6868
responses++;
69-
console.error('requests=%d responses=%d', requests, responses);
69+
console.error(`requests=${requests} responses=${responses}`);
7070
if (responses === requests) {
7171
console.error('done, closing server');
7272
// no more coming.

test/parallel/test-file-write-stream2.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ process.on('exit', function() {
2020
removeTestFile();
2121
if (cb_occurred !== cb_expected) {
2222
console.log(' Test callback events missing or out of order:');
23-
console.log(' expected: %j', cb_expected);
24-
console.log(' occurred: %j', cb_occurred);
23+
console.log(` expected: ${cb_expected}`);
24+
console.log(` occurred: ${cb_occurred}`);
2525
assert.strictEqual(
2626
cb_occurred, cb_expected,
2727
`events missing or out of order: "${cb_occurred}" !== "${cb_expected}"`);
@@ -57,7 +57,7 @@ file.on('drain', function() {
5757
if (countDrains === 1) {
5858
console.error('drain=1, write again');
5959
assert.strictEqual(fs.readFileSync(filepath, 'utf8'), EXPECTED);
60-
console.error('ondrain write ret=%j', file.write(EXPECTED));
60+
console.error(`ondrain write ret= ${file.write(EXPECTED)}`);
6161
cb_occurred += 'write ';
6262
} else if (countDrains === 2) {
6363
console.error('second drain, end');
@@ -81,7 +81,7 @@ file.on('error', function(err) {
8181

8282
for (let i = 0; i < 11; i++) {
8383
const ret = file.write(String(i));
84-
console.error('%d %j', i, ret);
84+
console.error(`${i} ${ret}`);
8585

8686
// return false when i hits 10
8787
assert.strictEqual(ret, i !== 10);

test/parallel/test-file-write-stream3.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ const fileDataExpected_3 = 'abcdefghij\u2026\u2026qrstuvwxyz';
2121
process.on('exit', function() {
2222
if (cb_occurred !== cb_expected) {
2323
console.log(' Test callback events missing or out of order:');
24-
console.log(' expected: %j', cb_expected);
25-
console.log(' occurred: %j', cb_occurred);
24+
console.log(` expected: ${cb_expected}`);
25+
console.log(` occurred: ${cb_occurred}`);
2626
assert.strictEqual(
2727
cb_occurred, cb_expected,
2828
`events missing or out of order: "${cb_occurred}" !== "${cb_expected}"`);

test/parallel/test-fs-read-stream-fd-leak.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ fs.close = function() {
2424
};
2525

2626
function testLeak(endFn, callback) {
27-
console.log('testing for leaks from fs.createReadStream().%s()...', endFn);
27+
console.log(`testing for leaks from fs.createReadStream().${endFn}()...`);
2828

2929
let i = 0;
3030
let check = 0;

test/parallel/test-fs-write-string-coerce.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ fs.open(fn, 'w', 0o644, common.mustCall(function(err, fd) {
1919
assert.strictEqual(Buffer.byteLength(expected), written);
2020
fs.closeSync(fd);
2121
const found = fs.readFileSync(fn, 'utf8');
22-
console.log('expected: "%s"', expected);
23-
console.log('found: "%s"', found);
22+
console.log(`expected: "${expected}"`);
23+
console.log(`found: "${found}"`);
2424
fs.unlinkSync(fn);
2525
assert.strictEqual(expected, found);
2626
}));

test/parallel/test-http-client-timeout-agent.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ server.listen(0, options.host, function() {
6969
});
7070

7171
process.on('exit', function() {
72-
console.error('done=%j sent=%j', requests_done, requests_sent);
72+
console.error(`done=${requests_done} sent=${requests_sent}`);
7373
assert.strictEqual(requests_done, requests_sent,
7474
'timeout on http request called too much');
7575
});

test/parallel/test-http-outgoing-finish.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,19 @@ function write(out) {
3737
// that 'finish' isn't emitted until the stream is fully flushed.
3838
out.on('finish', function() {
3939
finishEvent = true;
40-
console.error('%s finish event', name);
40+
console.error(`${name} finish event`);
4141
process.nextTick(function() {
4242
assert(endCb, `${name} got finish event before endcb!`);
43-
console.log('ok - %s finishEvent', name);
43+
console.log(`ok - ${name} finishEvent`);
4444
});
4545
});
4646

4747
out.end(buf, function() {
4848
endCb = true;
49-
console.error('%s endCb', name);
49+
console.error(`${name} endCb`);
5050
process.nextTick(function() {
5151
assert(finishEvent, `${name} got endCb event before finishEvent!`);
52-
console.log('ok - %s endCb', name);
52+
console.log(`ok - ${name} endCb`);
5353
});
5454
});
5555
}

test/parallel/test-listen-fd-cluster.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ function test(cb) {
6464
conn.end('hello from parent\n');
6565
}).listen(0, function() {
6666
const port = this.address().port;
67-
console.error('server listening on %d', port);
67+
console.error(`server listening on ${port}`);
6868

6969
const spawn = require('child_process').spawn;
7070
const master = spawn(process.execPath, [__filename, 'master'], {

test/parallel/test-net-server-max-connections.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ function makeConnection(index) {
3434
}
3535

3636
c.on('close', function() {
37-
console.error('closed %d', index);
37+
console.error(`closed ${index}`);
3838
closes++;
3939

4040
if (closes < N / 2) {
@@ -76,7 +76,7 @@ function makeConnection(index) {
7676
if (common.isSunOS && (e.code === 'ECONNREFUSED')) {
7777
c.connect(server.address().port);
7878
}
79-
console.error('error %d: %s', index, e);
79+
console.error(`error ${index}: ${e}`);
8080
});
8181
}
8282

test/parallel/test-process-exit-code.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ function parent() {
7272
assert.strictEqual(
7373
code, exit,
7474
`wrong exit for ${arg}\nexpected:${exit} but got:${code}`);
75-
console.log('ok - %s exited with %d', arg, exit);
75+
console.log(`ok - ${arg} exited with ${exit}`);
7676
});
7777
};
7878

test/parallel/test-punycode.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,10 +179,7 @@ const tests = [
179179
let errors = 0;
180180
const handleError = (error, name) => {
181181
console.error(
182-
'FAIL: %s expected %j, got %j',
183-
name,
184-
error.expected,
185-
error.actual
182+
`FAIL: ${name} expected ${error.expected}, got ${error.actual}`
186183
);
187184
errors++;
188185
};

test/parallel/test-repl-syntax-error-handling.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ function parent() {
1717

1818
child.stderr.setEncoding('utf8');
1919
child.stderr.on('data', function(c) {
20-
console.error('%j', c);
20+
console.error(`${c}`);
2121
throw new Error('should not get stderr data');
2222
});
2323

test/parallel/test-stream-unshift-read-race.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,9 @@ w.on('finish', common.mustCall(function() {
8282
// lacking that piece.
8383
assert.strictEqual(written[0], 'asdfasdfas');
8484
let asdf = 'd';
85-
console.error('0: %s', written[0]);
85+
console.error(`0: ${written[0]}`);
8686
for (let i = 1; i < written.length; i++) {
87-
console.error('%s: %s', i.toString(32), written[i]);
87+
console.error(`${i.toString(32)}: ${written[i]}`);
8888
assert.strictEqual(written[i].slice(0, 4), '1234');
8989
for (let j = 4; j < written[i].length; j++) {
9090
const c = written[i].charAt(j);

test/parallel/test-stream-writev.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ function run() {
2424
}
2525

2626
function test(decode, uncork, multi, next) {
27-
console.log('# decode=%j uncork=%j multi=%j', decode, uncork, multi);
27+
console.log(`# decode=${decode} uncork=${uncork} multi=${multi}`);
2828
let counter = 0;
2929
let expectCount = 0;
3030
function cnt(msg) {

test/parallel/test-stream2-large-read-stall.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ r.on('readable', function() {
2222
console.error('>> readable');
2323
let ret;
2424
do {
25-
console.error(' > read(%d)', READSIZE);
25+
console.error(` > read(${READSIZE})`);
2626
ret = r.read(READSIZE);
27-
console.error(' < %j (%d remain)', ret && ret.length, rs.length);
27+
console.error(` < ${ret && ret.length} (${rs.length} remain)`);
2828
} while (ret && ret.length === READSIZE);
2929

3030
console.error('<< after read()',
@@ -47,7 +47,7 @@ function push() {
4747
return r.push(null);
4848
}
4949

50-
console.error(' push #%d', pushes);
50+
console.error(` push #${pushes}`);
5151
if (r.push(Buffer.allocUnsafe(PUSHSIZE)))
5252
setTimeout(push, 1);
5353
}

test/parallel/test-stream2-push.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ const expectWritten =
7070
'asdfgasdfgasdfgasdfg' ];
7171

7272
writer._write = function(chunk, encoding, cb) {
73-
console.error('WRITE %s', chunk);
73+
console.error(`WRITE ${chunk}`);
7474
written.push(chunk);
7575
process.nextTick(cb);
7676
};

test/parallel/test-stream2-readable-non-empty-end.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ test.on('readable', function() {
3030
const res = test.read(b);
3131
if (res) {
3232
bytesread += res.length;
33-
console.error('br=%d len=%d', bytesread, len);
33+
console.error(`br=${bytesread} len=${len}`);
3434
setTimeout(next, 1);
3535
}
3636
test.read(0);

test/parallel/test-stream3-pause-then-read.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ function read100() {
3939
}
4040

4141
function readn(n, then) {
42-
console.error('read %d', n);
42+
console.error(`read ${n}`);
4343
expectEndingData -= n;
4444
(function read() {
4545
const c = r.read(n);

test/parallel/test-tls-client-verify.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,6 @@ runTest(0);
122122

123123

124124
process.on('exit', function() {
125-
console.log('successful tests: %d', successfulTests);
125+
console.log(`successful tests: ${successfulTests}`);
126126
assert.strictEqual(successfulTests, testCases.length);
127127
});

test/parallel/test-tls-pause.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ server.listen(0, function() {
3636
function send() {
3737
console.error('sending');
3838
const ret = client.write(Buffer.allocUnsafe(bufSize));
39-
console.error('write => %j', ret);
39+
console.error(`write => ${ret}`);
4040
if (false !== ret) {
4141
console.error('write again');
4242
sent += bufSize;

test/parallel/test-tls-server-verify.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ function runTest(port, testIndex) {
238238
const tcase = testCases[testIndex];
239239
if (!tcase) return;
240240

241-
console.error(`${prefix}Running '%s'`, tcase.title);
241+
console.error(`${prefix}Running '${tcase.title}'`);
242242

243243
const cas = tcase.CAs.map(loadPEM);
244244

test/pummel/test-exec.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ exec('thisisnotavalidcommand', function(err, stdout, stderr) {
5858
const sleeperStart = new Date();
5959
exec(SLEEP3_COMMAND, { timeout: 50 }, function(err, stdout, stderr) {
6060
const diff = (new Date()) - sleeperStart;
61-
console.log('\'sleep 3\' with timeout 50 took %d ms', diff);
61+
console.log(`'sleep 3' with timeout 50 took ${diff} ms`);
6262
assert.ok(diff < 500);
6363
assert.ok(err);
6464
assert.ok(err.killed);
@@ -72,7 +72,7 @@ const startSleep3 = new Date();
7272
const killMeTwice = exec(SLEEP3_COMMAND, {timeout: 1000}, killMeTwiceCallback);
7373

7474
process.nextTick(function() {
75-
console.log('kill pid %d', killMeTwice.pid);
75+
console.log(`kill pid ${killMeTwice.pid}`);
7676
// make sure there is no race condition in starting the process
7777
// the PID SHOULD exist directly following the exec() call.
7878
assert.strictEqual('number', typeof killMeTwice._handle.pid);
@@ -91,7 +91,7 @@ function killMeTwiceCallback(err, stdout, stderr) {
9191
assert.strictEqual(stderr, '');
9292

9393
// the timeout should still be in effect
94-
console.log('\'sleep 3\' was already killed. Took %d ms', diff);
94+
console.log(`'sleep 3' was already killed. Took ${diff} ms`);
9595
assert.ok(diff < 1500);
9696
}
9797

test/pummel/test-net-write-callbacks.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const N = 500000;
88

99
const server = net.Server(function(socket) {
1010
socket.on('data', function(d) {
11-
console.error('got %d bytes', d.length);
11+
console.error(`got ${d.length} bytes`);
1212
});
1313

1414
socket.on('end', function() {

test/pummel/test-regress-GH-892.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,11 @@ const server = https.Server(serverOptions, function(req, res) {
8282
});
8383

8484
server.listen(common.PORT, function() {
85-
console.log('expecting %d bytes', bytesExpected);
85+
console.log(`expecting ${bytesExpected} bytes`);
8686
makeRequest();
8787
});
8888

8989
process.on('exit', function() {
90-
console.error('got %d bytes', uploadCount);
90+
console.error(`got ${uploadCount} bytes`);
9191
assert.strictEqual(uploadCount, bytesExpected);
9292
});

test/pummel/test-tls-throttle.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ server.listen(common.PORT, function() {
5151

5252

5353
function displayCounts() {
54-
console.log('body.length: %d', body.length);
55-
console.log(' recvCount: %d', recvCount);
54+
console.log(`body.length: ${body.length}`);
55+
console.log(` recvCount: ${recvCount}`);
5656
}
5757

5858

test/pummel/test-vm-memleak.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,6 @@ function testContextLeak() {
3636
}
3737

3838
process.on('exit', function() {
39-
console.error('max mem: %dmb', Math.round(maxMem / (1024 * 1024)));
39+
console.error(`max mem: ${Math.round(maxMem / (1024 * 1024))}mb`);
4040
assert.ok(maxMem < 64 * 1024 * 1024);
4141
});

test/sequential/test-require-cache-without-stat.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ require('../fixtures/a.js');
3131
require('./../fixtures/a.js');
3232
require('http');
3333

34-
console.log('counterBefore = %d', counter);
34+
console.log(`counterBefore = ${counter}`);
3535
const counterBefore = counter;
3636

3737
// Now load the module a bunch of times with equivalent paths.
@@ -47,7 +47,7 @@ for (let i = 0; i < 100; i++) {
4747
require('http');
4848
}
4949

50-
console.log('counterAfter = %d', counter);
50+
console.log(`counterAfter = ${counter}`);
5151
const counterAfter = counter;
5252

5353
assert.strictEqual(counterBefore, counterAfter);

test/sequential/test-stream2-stderr-sync.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ function parent() {
1717

1818
child.on('close', function() {
1919
assert.strictEqual(err, `child ${c}\nfoo\nbar\nbaz\n`);
20-
console.log('ok %d child #%d', ++i, c);
20+
console.log(`ok ${++i} child #${c}`);
2121
if (i === children.length)
2222
console.log(`1..${i}`);
2323
});

0 commit comments

Comments
 (0)