mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
test: improve to use template string
PR-URL: https://github.com/nodejs/node/pull/18097 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
This commit is contained in:
parent
d3600e513a
commit
e08cf1d230
@ -24,7 +24,7 @@ require('../common');
|
||||
const assert = require('assert');
|
||||
|
||||
process.on('exit', function(code) {
|
||||
console.error('Exiting with code=%d', code);
|
||||
console.error(`Exiting with code=${code}`);
|
||||
});
|
||||
|
||||
assert.strictEqual(1, 2);
|
||||
|
@ -25,7 +25,7 @@ require('../common');
|
||||
process.maxTickDepth = 10;
|
||||
let i = 20;
|
||||
process.nextTick(function f() {
|
||||
console.error('tick %d', i);
|
||||
console.error(`tick ${i}`);
|
||||
if (i-- > 0)
|
||||
process.nextTick(f);
|
||||
});
|
||||
|
@ -26,7 +26,7 @@ const fork = require('child_process').fork;
|
||||
const net = require('net');
|
||||
|
||||
if (process.argv[2] !== 'child') {
|
||||
console.error('[%d] master', process.pid);
|
||||
console.error(`[${process.pid}] master`);
|
||||
|
||||
const worker = fork(__filename, ['child']);
|
||||
let called = false;
|
||||
@ -50,7 +50,7 @@ if (process.argv[2] !== 'child') {
|
||||
assert.ok(called);
|
||||
});
|
||||
} else {
|
||||
console.error('[%d] worker', process.pid);
|
||||
console.error(`[${process.pid}] worker`);
|
||||
|
||||
let socket;
|
||||
let cbcalls = 0;
|
||||
|
@ -62,7 +62,7 @@ server.listen(0, next);
|
||||
|
||||
function next() {
|
||||
const port = this.address().port;
|
||||
console.log('listening on localhost:%d', port);
|
||||
console.log(`listening on localhost:${port}`);
|
||||
|
||||
let requests = 0;
|
||||
let responses = 0;
|
||||
@ -87,7 +87,7 @@ function next() {
|
||||
dom.add(req);
|
||||
req.on('response', function(res) {
|
||||
responses++;
|
||||
console.error('requests=%d responses=%d', requests, responses);
|
||||
console.error(`requests=${requests} responses=${responses}`);
|
||||
if (responses === requests) {
|
||||
console.error('done, closing server');
|
||||
// no more coming.
|
||||
|
@ -41,8 +41,8 @@ process.on('exit', function() {
|
||||
removeTestFile();
|
||||
if (cb_occurred !== cb_expected) {
|
||||
console.log(' Test callback events missing or out of order:');
|
||||
console.log(' expected: %j', cb_expected);
|
||||
console.log(' occurred: %j', cb_occurred);
|
||||
console.log(` expected: ${cb_expected}`);
|
||||
console.log(` occurred: ${cb_occurred}`);
|
||||
assert.strictEqual(
|
||||
cb_occurred, cb_expected,
|
||||
`events missing or out of order: "${cb_occurred}" !== "${cb_expected}"`);
|
||||
@ -78,7 +78,7 @@ file.on('drain', function() {
|
||||
if (countDrains === 1) {
|
||||
console.error('drain=1, write again');
|
||||
assert.strictEqual(fs.readFileSync(filepath, 'utf8'), EXPECTED);
|
||||
console.error('ondrain write ret=%j', file.write(EXPECTED));
|
||||
console.error(`ondrain write ret= ${file.write(EXPECTED)}`);
|
||||
cb_occurred += 'write ';
|
||||
} else if (countDrains === 2) {
|
||||
console.error('second drain, end');
|
||||
@ -102,7 +102,7 @@ file.on('error', function(err) {
|
||||
|
||||
for (let i = 0; i < 11; i++) {
|
||||
const ret = file.write(String(i));
|
||||
console.error('%d %j', i, ret);
|
||||
console.error(`${i} ${ret}`);
|
||||
|
||||
// return false when i hits 10
|
||||
assert.strictEqual(ret, i !== 10);
|
||||
|
@ -42,8 +42,8 @@ const fileDataExpected_3 = 'abcdefghij\u2026\u2026qrstuvwxyz';
|
||||
process.on('exit', function() {
|
||||
if (cb_occurred !== cb_expected) {
|
||||
console.log(' Test callback events missing or out of order:');
|
||||
console.log(' expected: %j', cb_expected);
|
||||
console.log(' occurred: %j', cb_occurred);
|
||||
console.log(` expected: ${cb_expected}`);
|
||||
console.log(` occurred: ${cb_occurred}`);
|
||||
assert.strictEqual(
|
||||
cb_occurred, cb_expected,
|
||||
`events missing or out of order: "${cb_occurred}" !== "${cb_expected}"`);
|
||||
|
@ -24,7 +24,7 @@ fs.close = function() {
|
||||
};
|
||||
|
||||
function testLeak(endFn, callback) {
|
||||
console.log('testing for leaks from fs.createReadStream().%s()...', endFn);
|
||||
console.log(`testing for leaks from fs.createReadStream().${endFn}()...`);
|
||||
|
||||
let i = 0;
|
||||
let check = 0;
|
||||
|
@ -19,8 +19,8 @@ fs.open(fn, 'w', 0o644, common.mustCall(function(err, fd) {
|
||||
assert.strictEqual(Buffer.byteLength(expected), written);
|
||||
fs.closeSync(fd);
|
||||
const found = fs.readFileSync(fn, 'utf8');
|
||||
console.log('expected: "%s"', expected);
|
||||
console.log('found: "%s"', found);
|
||||
console.log(`expected: "${expected}"`);
|
||||
console.log(`found: "${found}"`);
|
||||
fs.unlinkSync(fn);
|
||||
assert.strictEqual(expected, found);
|
||||
}));
|
||||
|
@ -90,7 +90,7 @@ server.listen(0, options.host, function() {
|
||||
});
|
||||
|
||||
process.on('exit', function() {
|
||||
console.error('done=%j sent=%j', requests_done, requests_sent);
|
||||
console.error(`done=${requests_done} sent=${requests_sent}`);
|
||||
assert.strictEqual(requests_done, requests_sent,
|
||||
'timeout on http request called too much');
|
||||
});
|
||||
|
@ -58,19 +58,19 @@ function write(out) {
|
||||
// that 'finish' isn't emitted until the stream is fully flushed.
|
||||
out.on('finish', function() {
|
||||
finishEvent = true;
|
||||
console.error('%s finish event', name);
|
||||
console.error(`${name} finish event`);
|
||||
process.nextTick(function() {
|
||||
assert(endCb, `${name} got finish event before endcb!`);
|
||||
console.log('ok - %s finishEvent', name);
|
||||
console.log(`ok - ${name} finishEvent`);
|
||||
});
|
||||
});
|
||||
|
||||
out.end(buf, function() {
|
||||
endCb = true;
|
||||
console.error('%s endCb', name);
|
||||
console.error(`${name} endCb`);
|
||||
process.nextTick(function() {
|
||||
assert(finishEvent, `${name} got endCb event before finishEvent!`);
|
||||
console.log('ok - %s endCb', name);
|
||||
console.log(`ok - ${name} endCb`);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
@ -85,7 +85,7 @@ function test(cb) {
|
||||
conn.end('hello from parent\n');
|
||||
}).listen(0, function() {
|
||||
const port = this.address().port;
|
||||
console.error('server listening on %d', port);
|
||||
console.error(`server listening on ${port}`);
|
||||
|
||||
const spawn = require('child_process').spawn;
|
||||
const master = spawn(process.execPath, [__filename, 'master'], {
|
||||
|
@ -55,7 +55,7 @@ function makeConnection(index) {
|
||||
}
|
||||
|
||||
c.on('close', function() {
|
||||
console.error('closed %d', index);
|
||||
console.error(`closed ${index}`);
|
||||
closes++;
|
||||
|
||||
if (closes < N / 2) {
|
||||
@ -97,7 +97,7 @@ function makeConnection(index) {
|
||||
if (common.isSunOS && (e.code === 'ECONNREFUSED')) {
|
||||
c.connect(server.address().port);
|
||||
}
|
||||
console.error('error %d: %s', index, e);
|
||||
console.error(`error ${index}: ${e}`);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -93,7 +93,7 @@ function parent() {
|
||||
assert.strictEqual(
|
||||
code, exit,
|
||||
`wrong exit for ${arg}\nexpected:${exit} but got:${code}`);
|
||||
console.log('ok - %s exited with %d', arg, exit);
|
||||
console.log(`ok - ${arg} exited with ${exit}`);
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -200,10 +200,7 @@ const tests = [
|
||||
let errors = 0;
|
||||
const handleError = (error, name) => {
|
||||
console.error(
|
||||
'FAIL: %s expected %j, got %j',
|
||||
name,
|
||||
error.expected,
|
||||
error.actual
|
||||
`FAIL: ${name} expected ${error.expected}, got ${error.actual}`
|
||||
);
|
||||
errors++;
|
||||
};
|
||||
|
@ -38,7 +38,7 @@ function parent() {
|
||||
|
||||
child.stderr.setEncoding('utf8');
|
||||
child.stderr.on('data', function(c) {
|
||||
console.error('%j', c);
|
||||
console.error(`${c}`);
|
||||
throw new Error('should not get stderr data');
|
||||
});
|
||||
|
||||
|
@ -111,9 +111,9 @@ w.on('finish', common.mustCall(function() {
|
||||
// lacking that piece.
|
||||
assert.strictEqual(written[0], 'asdfasdfas');
|
||||
let asdf = 'd';
|
||||
console.error('0: %s', written[0]);
|
||||
console.error(`0: ${written[0]}`);
|
||||
for (let i = 1; i < written.length; i++) {
|
||||
console.error('%s: %s', i.toString(32), written[i]);
|
||||
console.error(`${i.toString(32)}: ${written[i]}`);
|
||||
assert.strictEqual(written[i].slice(0, 4), '1234');
|
||||
for (let j = 4; j < written[i].length; j++) {
|
||||
const c = written[i].charAt(j);
|
||||
|
@ -45,7 +45,7 @@ function run() {
|
||||
}
|
||||
|
||||
function test(decode, uncork, multi, next) {
|
||||
console.log('# decode=%j uncork=%j multi=%j', decode, uncork, multi);
|
||||
console.log(`# decode=${decode} uncork=${uncork} multi=${multi}`);
|
||||
let counter = 0;
|
||||
let expectCount = 0;
|
||||
function cnt(msg) {
|
||||
|
@ -43,9 +43,9 @@ r.on('readable', function() {
|
||||
console.error('>> readable');
|
||||
let ret;
|
||||
do {
|
||||
console.error(' > read(%d)', READSIZE);
|
||||
console.error(` > read(${READSIZE})`);
|
||||
ret = r.read(READSIZE);
|
||||
console.error(' < %j (%d remain)', ret && ret.length, rs.length);
|
||||
console.error(` < ${ret && ret.length} (${rs.length} remain)`);
|
||||
} while (ret && ret.length === READSIZE);
|
||||
|
||||
console.error('<< after read()',
|
||||
@ -68,7 +68,7 @@ function push() {
|
||||
return r.push(null);
|
||||
}
|
||||
|
||||
console.error(' push #%d', pushes);
|
||||
console.error(` push #${pushes}`);
|
||||
if (r.push(Buffer.allocUnsafe(PUSHSIZE)))
|
||||
setTimeout(push, 1);
|
||||
}
|
||||
|
@ -89,7 +89,7 @@ const expectWritten =
|
||||
'asdfgasdfgasdfgasdfg' ];
|
||||
|
||||
writer._write = function(chunk, encoding, cb) {
|
||||
console.error('WRITE %s', chunk);
|
||||
console.error(`WRITE ${chunk}`);
|
||||
written.push(chunk);
|
||||
process.nextTick(cb);
|
||||
};
|
||||
|
@ -51,7 +51,7 @@ test.on('readable', function() {
|
||||
const res = test.read(b);
|
||||
if (res) {
|
||||
bytesread += res.length;
|
||||
console.error('br=%d len=%d', bytesread, len);
|
||||
console.error(`br=${bytesread} len=${len}`);
|
||||
setTimeout(next, 1);
|
||||
}
|
||||
test.read(0);
|
||||
|
@ -60,7 +60,7 @@ function read100() {
|
||||
}
|
||||
|
||||
function readn(n, then) {
|
||||
console.error('read %d', n);
|
||||
console.error(`read ${n}`);
|
||||
expectEndingData -= n;
|
||||
(function read() {
|
||||
const c = r.read(n);
|
||||
|
@ -142,6 +142,6 @@ runTest(0);
|
||||
|
||||
|
||||
process.on('exit', function() {
|
||||
console.log('successful tests: %d', successfulTests);
|
||||
console.log(`successful tests: ${successfulTests}`);
|
||||
assert.strictEqual(successfulTests, testCases.length);
|
||||
});
|
||||
|
@ -57,7 +57,7 @@ server.listen(0, function() {
|
||||
function send() {
|
||||
console.error('sending');
|
||||
const ret = client.write(Buffer.allocUnsafe(bufSize));
|
||||
console.error('write => %j', ret);
|
||||
console.error(`write => ${ret}`);
|
||||
if (false !== ret) {
|
||||
console.error('write again');
|
||||
sent += bufSize;
|
||||
|
@ -259,7 +259,7 @@ function runTest(port, testIndex) {
|
||||
const tcase = testCases[testIndex];
|
||||
if (!tcase) return;
|
||||
|
||||
console.error(`${prefix}Running '%s'`, tcase.title);
|
||||
console.error(`${prefix}Running '${tcase.title}'`);
|
||||
|
||||
const cas = tcase.CAs.map(loadPEM);
|
||||
|
||||
|
@ -79,7 +79,7 @@ exec('thisisnotavalidcommand', function(err, stdout, stderr) {
|
||||
const sleeperStart = new Date();
|
||||
exec(SLEEP3_COMMAND, { timeout: 50 }, function(err, stdout, stderr) {
|
||||
const diff = (new Date()) - sleeperStart;
|
||||
console.log('\'sleep 3\' with timeout 50 took %d ms', diff);
|
||||
console.log(`'sleep 3' with timeout 50 took ${diff} ms`);
|
||||
assert.ok(diff < 500);
|
||||
assert.ok(err);
|
||||
assert.ok(err.killed);
|
||||
@ -94,7 +94,7 @@ const killMeTwice = exec(SLEEP3_COMMAND, { timeout: 1000 },
|
||||
killMeTwiceCallback);
|
||||
|
||||
process.nextTick(function() {
|
||||
console.log('kill pid %d', killMeTwice.pid);
|
||||
console.log(`kill pid ${killMeTwice.pid}`);
|
||||
// make sure there is no race condition in starting the process
|
||||
// the PID SHOULD exist directly following the exec() call.
|
||||
assert.strictEqual('number', typeof killMeTwice._handle.pid);
|
||||
@ -113,7 +113,7 @@ function killMeTwiceCallback(err, stdout, stderr) {
|
||||
assert.strictEqual(stderr, '');
|
||||
|
||||
// the timeout should still be in effect
|
||||
console.log('\'sleep 3\' was already killed. Took %d ms', diff);
|
||||
console.log(`'sleep 3' was already killed. Took ${diff} ms`);
|
||||
assert.ok(diff < 1500);
|
||||
}
|
||||
|
||||
|
@ -29,7 +29,7 @@ const N = 500000;
|
||||
|
||||
const server = net.Server(function(socket) {
|
||||
socket.on('data', function(d) {
|
||||
console.error('got %d bytes', d.length);
|
||||
console.error(`got ${d.length} bytes`);
|
||||
});
|
||||
|
||||
socket.on('end', function() {
|
||||
|
@ -102,11 +102,11 @@ const server = https.Server(serverOptions, function(req, res) {
|
||||
});
|
||||
|
||||
server.listen(common.PORT, function() {
|
||||
console.log('expecting %d bytes', bytesExpected);
|
||||
console.log(`expecting ${bytesExpected} bytes`);
|
||||
makeRequest();
|
||||
});
|
||||
|
||||
process.on('exit', function() {
|
||||
console.error('got %d bytes', uploadCount);
|
||||
console.error(`got ${uploadCount} bytes`);
|
||||
assert.strictEqual(uploadCount, bytesExpected);
|
||||
});
|
||||
|
@ -72,8 +72,8 @@ server.listen(common.PORT, function() {
|
||||
|
||||
|
||||
function displayCounts() {
|
||||
console.log('body.length: %d', body.length);
|
||||
console.log(' recvCount: %d', recvCount);
|
||||
console.log(`body.length: ${body.length}`);
|
||||
console.log(` recvCount: ${recvCount}`);
|
||||
}
|
||||
|
||||
|
||||
|
@ -57,6 +57,6 @@ function testContextLeak() {
|
||||
}
|
||||
|
||||
process.on('exit', function() {
|
||||
console.error('max mem: %dmb', Math.round(maxMem / (1024 * 1024)));
|
||||
console.error(`max mem: ${Math.round(maxMem / (1024 * 1024))}mb`);
|
||||
assert.ok(maxMem < 64 * 1024 * 1024);
|
||||
});
|
||||
|
@ -52,7 +52,7 @@ require('../fixtures/a.js');
|
||||
require('./../fixtures/a.js');
|
||||
require('http');
|
||||
|
||||
console.log('counterBefore = %d', counter);
|
||||
console.log(`counterBefore = ${counter}`);
|
||||
const counterBefore = counter;
|
||||
|
||||
// Now load the module a bunch of times with equivalent paths.
|
||||
@ -68,7 +68,7 @@ for (let i = 0; i < 100; i++) {
|
||||
require('http');
|
||||
}
|
||||
|
||||
console.log('counterAfter = %d', counter);
|
||||
console.log(`counterAfter = ${counter}`);
|
||||
const counterAfter = counter;
|
||||
|
||||
assert.strictEqual(counterBefore, counterAfter);
|
||||
|
@ -38,7 +38,7 @@ function parent() {
|
||||
|
||||
child.on('close', function() {
|
||||
assert.strictEqual(err, `child ${c}\nfoo\nbar\nbaz\n`);
|
||||
console.log('ok %d child #%d', ++i, c);
|
||||
console.log(`ok ${++i} child #${c}`);
|
||||
if (i === children.length)
|
||||
console.log(`1..${i}`);
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user