Skip to content

Commit 1dcae57

Browse files
sreepurnajastievanlucas
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 b4e7260 commit 1dcae57

31 files changed

+50
-53
lines changed

test/message/error_exit.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ require('../common');
2424
const assert = require('assert');
2525

2626
process.on('exit', function(code) {
27-
console.error('Exiting with code=%d', code);
27+
console.error(`Exiting with code=${code}`);
2828
});
2929

3030
assert.strictEqual(1, 2);

test/message/max_tick_depth.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ require('../common');
2525
process.maxTickDepth = 10;
2626
let i = 20;
2727
process.nextTick(function f() {
28-
console.error('tick %d', i);
28+
console.error(`tick ${i}`);
2929
if (i-- > 0)
3030
process.nextTick(f);
3131
});

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const fork = require('child_process').fork;
2626
const net = require('net');
2727

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

3131
const worker = fork(__filename, ['child']);
3232
let called = false;
@@ -50,7 +50,7 @@ if (process.argv[2] !== 'child') {
5050
assert.ok(called);
5151
});
5252
} else {
53-
console.error('[%d] worker', process.pid);
53+
console.error(`[${process.pid}] worker`);
5454

5555
let socket;
5656
let cbcalls = 0;

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ server.listen(0, next);
6262

6363
function next() {
6464
const port = this.address().port;
65-
console.log('listening on localhost:%d', port);
65+
console.log(`listening on localhost:${port}`);
6666

6767
let requests = 0;
6868
let responses = 0;
@@ -87,7 +87,7 @@ function next() {
8787
dom.add(req);
8888
req.on('response', function(res) {
8989
responses++;
90-
console.error('requests=%d responses=%d', requests, responses);
90+
console.error(`requests=${requests} responses=${responses}`);
9191
if (responses === requests) {
9292
console.error('done, closing server');
9393
// no more coming.

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ process.on('exit', function() {
4141
removeTestFile();
4242
if (cb_occurred !== cb_expected) {
4343
console.log(' Test callback events missing or out of order:');
44-
console.log(' expected: %j', cb_expected);
45-
console.log(' occurred: %j', cb_occurred);
44+
console.log(` expected: ${cb_expected}`);
45+
console.log(` occurred: ${cb_occurred}`);
4646
assert.strictEqual(
4747
cb_occurred, cb_expected,
4848
`events missing or out of order: "${cb_occurred}" !== "${cb_expected}"`);
@@ -78,7 +78,7 @@ file.on('drain', function() {
7878
if (countDrains === 1) {
7979
console.error('drain=1, write again');
8080
assert.strictEqual(fs.readFileSync(filepath, 'utf8'), EXPECTED);
81-
console.error('ondrain write ret=%j', file.write(EXPECTED));
81+
console.error(`ondrain write ret= ${file.write(EXPECTED)}`);
8282
cb_occurred += 'write ';
8383
} else if (countDrains === 2) {
8484
console.error('second drain, end');
@@ -102,7 +102,7 @@ file.on('error', function(err) {
102102

103103
for (let i = 0; i < 11; i++) {
104104
const ret = file.write(String(i));
105-
console.error('%d %j', i, ret);
105+
console.error(`${i} ${ret}`);
106106

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

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ const fileDataExpected_3 = 'abcdefghij\u2026\u2026qrstuvwxyz';
4242
process.on('exit', function() {
4343
if (cb_occurred !== cb_expected) {
4444
console.log(' Test callback events missing or out of order:');
45-
console.log(' expected: %j', cb_expected);
46-
console.log(' occurred: %j', cb_occurred);
45+
console.log(` expected: ${cb_expected}`);
46+
console.log(` occurred: ${cb_occurred}`);
4747
assert.strictEqual(
4848
cb_occurred, cb_expected,
4949
`events missing or out of order: "${cb_occurred}" !== "${cb_expected}"`);

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

+1-1
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

+2-2
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

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ server.listen(0, options.host, function() {
9090
});
9191

9292
process.on('exit', function() {
93-
console.error('done=%j sent=%j', requests_done, requests_sent);
93+
console.error(`done=${requests_done} sent=${requests_sent}`);
9494
assert.strictEqual(requests_done, requests_sent,
9595
'timeout on http request called too much');
9696
});

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -58,19 +58,19 @@ function write(out) {
5858
// that 'finish' isn't emitted until the stream is fully flushed.
5959
out.on('finish', function() {
6060
finishEvent = true;
61-
console.error('%s finish event', name);
61+
console.error(`${name} finish event`);
6262
process.nextTick(function() {
6363
assert(endCb, `${name} got finish event before endcb!`);
64-
console.log('ok - %s finishEvent', name);
64+
console.log(`ok - ${name} finishEvent`);
6565
});
6666
});
6767

6868
out.end(buf, function() {
6969
endCb = true;
70-
console.error('%s endCb', name);
70+
console.error(`${name} endCb`);
7171
process.nextTick(function() {
7272
assert(finishEvent, `${name} got endCb event before finishEvent!`);
73-
console.log('ok - %s endCb', name);
73+
console.log(`ok - ${name} endCb`);
7474
});
7575
});
7676
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ function test(cb) {
8585
conn.end('hello from parent\n');
8686
}).listen(0, function() {
8787
const port = this.address().port;
88-
console.error('server listening on %d', port);
88+
console.error(`server listening on ${port}`);
8989

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

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ function makeConnection(index) {
5555
}
5656

5757
c.on('close', function() {
58-
console.error('closed %d', index);
58+
console.error(`closed ${index}`);
5959
closes++;
6060

6161
if (closes < N / 2) {
@@ -97,7 +97,7 @@ function makeConnection(index) {
9797
if (common.isSunOS && (e.code === 'ECONNREFUSED')) {
9898
c.connect(server.address().port);
9999
}
100-
console.error('error %d: %s', index, e);
100+
console.error(`error ${index}: ${e}`);
101101
});
102102
}
103103

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ function parent() {
9393
assert.strictEqual(
9494
code, exit,
9595
`wrong exit for ${arg}\nexpected:${exit} but got:${code}`);
96-
console.log('ok - %s exited with %d', arg, exit);
96+
console.log(`ok - ${arg} exited with ${exit}`);
9797
});
9898
};
9999

test/parallel/test-punycode.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -200,10 +200,7 @@ const tests = [
200200
let errors = 0;
201201
const handleError = (error, name) => {
202202
console.error(
203-
'FAIL: %s expected %j, got %j',
204-
name,
205-
error.expected,
206-
error.actual
203+
`FAIL: ${name} expected ${error.expected}, got ${error.actual}`
207204
);
208205
errors++;
209206
};

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ function parent() {
3838

3939
child.stderr.setEncoding('utf8');
4040
child.stderr.on('data', function(c) {
41-
console.error('%j', c);
41+
console.error(`${c}`);
4242
throw new Error('should not get stderr data');
4343
});
4444

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,9 @@ w.on('finish', common.mustCall(function() {
111111
// lacking that piece.
112112
assert.strictEqual(written[0], 'asdfasdfas');
113113
let asdf = 'd';
114-
console.error('0: %s', written[0]);
114+
console.error(`0: ${written[0]}`);
115115
for (let i = 1; i < written.length; i++) {
116-
console.error('%s: %s', i.toString(32), written[i]);
116+
console.error(`${i.toString(32)}: ${written[i]}`);
117117
assert.strictEqual(written[i].slice(0, 4), '1234');
118118
for (let j = 4; j < written[i].length; j++) {
119119
const c = written[i].charAt(j);

test/parallel/test-stream-writev.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ function run() {
4545
}
4646

4747
function test(decode, uncork, multi, next) {
48-
console.log('# decode=%j uncork=%j multi=%j', decode, uncork, multi);
48+
console.log(`# decode=${decode} uncork=${uncork} multi=${multi}`);
4949
let counter = 0;
5050
let expectCount = 0;
5151
function cnt(msg) {

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ r.on('readable', function() {
4343
console.error('>> readable');
4444
let ret;
4545
do {
46-
console.error(' > read(%d)', READSIZE);
46+
console.error(` > read(${READSIZE})`);
4747
ret = r.read(READSIZE);
48-
console.error(' < %j (%d remain)', ret && ret.length, rs.length);
48+
console.error(` < ${ret && ret.length} (${rs.length} remain)`);
4949
} while (ret && ret.length === READSIZE);
5050

5151
console.error('<< after read()',
@@ -68,7 +68,7 @@ function push() {
6868
return r.push(null);
6969
}
7070

71-
console.error(' push #%d', pushes);
71+
console.error(` push #${pushes}`);
7272
if (r.push(Buffer.allocUnsafe(PUSHSIZE)))
7373
setTimeout(push, 1);
7474
}

test/parallel/test-stream2-push.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ const expectWritten =
8989
'asdfgasdfgasdfgasdfg' ];
9090

9191
writer._write = function(chunk, encoding, cb) {
92-
console.error('WRITE %s', chunk);
92+
console.error(`WRITE ${chunk}`);
9393
written.push(chunk);
9494
process.nextTick(cb);
9595
};

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ test.on('readable', function() {
5151
const res = test.read(b);
5252
if (res) {
5353
bytesread += res.length;
54-
console.error('br=%d len=%d', bytesread, len);
54+
console.error(`br=${bytesread} len=${len}`);
5555
setTimeout(next, 1);
5656
}
5757
test.read(0);

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ function read100() {
6060
}
6161

6262
function readn(n, then) {
63-
console.error('read %d', n);
63+
console.error(`read ${n}`);
6464
expectEndingData -= n;
6565
(function read() {
6666
const c = r.read(n);

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,6 @@ runTest(0);
142142

143143

144144
process.on('exit', function() {
145-
console.log('successful tests: %d', successfulTests);
145+
console.log(`successful tests: ${successfulTests}`);
146146
assert.strictEqual(successfulTests, testCases.length);
147147
});

test/parallel/test-tls-pause.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ server.listen(0, function() {
5757
function send() {
5858
console.error('sending');
5959
const ret = client.write(Buffer.allocUnsafe(bufSize));
60-
console.error('write => %j', ret);
60+
console.error(`write => ${ret}`);
6161
if (false !== ret) {
6262
console.error('write again');
6363
sent += bufSize;

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ function runTest(port, testIndex) {
259259
const tcase = testCases[testIndex];
260260
if (!tcase) return;
261261

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

264264
const cas = tcase.CAs.map(loadPEM);
265265

test/pummel/test-exec.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ exec('thisisnotavalidcommand', function(err, stdout, stderr) {
7979
const sleeperStart = new Date();
8080
exec(SLEEP3_COMMAND, { timeout: 50 }, function(err, stdout, stderr) {
8181
const diff = (new Date()) - sleeperStart;
82-
console.log('\'sleep 3\' with timeout 50 took %d ms', diff);
82+
console.log(`'sleep 3' with timeout 50 took ${diff} ms`);
8383
assert.ok(diff < 500);
8484
assert.ok(err);
8585
assert.ok(err.killed);
@@ -94,7 +94,7 @@ const killMeTwice = exec(SLEEP3_COMMAND, { timeout: 1000 },
9494
killMeTwiceCallback);
9595

9696
process.nextTick(function() {
97-
console.log('kill pid %d', killMeTwice.pid);
97+
console.log(`kill pid ${killMeTwice.pid}`);
9898
// make sure there is no race condition in starting the process
9999
// the PID SHOULD exist directly following the exec() call.
100100
assert.strictEqual('number', typeof killMeTwice._handle.pid);
@@ -113,7 +113,7 @@ function killMeTwiceCallback(err, stdout, stderr) {
113113
assert.strictEqual(stderr, '');
114114

115115
// the timeout should still be in effect
116-
console.log('\'sleep 3\' was already killed. Took %d ms', diff);
116+
console.log(`'sleep 3' was already killed. Took ${diff} ms`);
117117
assert.ok(diff < 1500);
118118
}
119119

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const N = 500000;
2929

3030
const server = net.Server(function(socket) {
3131
socket.on('data', function(d) {
32-
console.error('got %d bytes', d.length);
32+
console.error(`got ${d.length} bytes`);
3333
});
3434

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

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,11 @@ const server = https.Server(serverOptions, function(req, res) {
102102
});
103103

104104
server.listen(common.PORT, function() {
105-
console.log('expecting %d bytes', bytesExpected);
105+
console.log(`expecting ${bytesExpected} bytes`);
106106
makeRequest();
107107
});
108108

109109
process.on('exit', function() {
110-
console.error('got %d bytes', uploadCount);
110+
console.error(`got ${uploadCount} bytes`);
111111
assert.strictEqual(uploadCount, bytesExpected);
112112
});

test/pummel/test-tls-throttle.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ server.listen(common.PORT, function() {
7272

7373

7474
function displayCounts() {
75-
console.log('body.length: %d', body.length);
76-
console.log(' recvCount: %d', recvCount);
75+
console.log(`body.length: ${body.length}`);
76+
console.log(` recvCount: ${recvCount}`);
7777
}
7878

7979

test/pummel/test-vm-memleak.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,6 @@ function testContextLeak() {
5757
}
5858

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

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ require('../fixtures/a.js');
5252
require('./../fixtures/a.js');
5353
require('http');
5454

55-
console.log('counterBefore = %d', counter);
55+
console.log(`counterBefore = ${counter}`);
5656
const counterBefore = counter;
5757

5858
// Now load the module a bunch of times with equivalent paths.
@@ -68,7 +68,7 @@ for (let i = 0; i < 100; i++) {
6868
require('http');
6969
}
7070

71-
console.log('counterAfter = %d', counter);
71+
console.log(`counterAfter = ${counter}`);
7272
const counterAfter = counter;
7373

7474
assert.strictEqual(counterBefore, counterAfter);

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ function parent() {
3838

3939
child.on('close', function() {
4040
assert.strictEqual(err, `child ${c}\nfoo\nbar\nbaz\n`);
41-
console.log('ok %d child #%d', ++i, c);
41+
console.log(`ok ${++i} child #${c}`);
4242
if (i === children.length)
4343
console.log(`1..${i}`);
4444
});

0 commit comments

Comments
 (0)