Skip to content

Commit 8b76c3e

Browse files
committed
test: reduce string concatenations
PR-URL: #12735 Refs: #12455 Reviewed-By: Refael Ackermann <[email protected]> Reviewed-By: Gibson Fahnestock <[email protected]>
1 parent 6bcf65d commit 8b76c3e

File tree

350 files changed

+1001
-1075
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

350 files changed

+1001
-1075
lines changed

test/addons/repl-domain-abort/test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ process.on('exit', function() {
3939

4040
const lines = [
4141
// This line shouldn't cause an assertion error.
42-
'require(\'' + buildPath + '\')' +
42+
`require('${buildPath}')` +
4343
// Log output to double check callback ran.
4444
'.method(function() { console.log(\'cb_ran\'); });',
4545
];

test/common/index.js

+9-11
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,8 @@ exports.isLinux = process.platform === 'linux';
5555
exports.isOSX = process.platform === 'darwin';
5656

5757
exports.enoughTestMem = os.totalmem() > 0x40000000; /* 1 Gb */
58-
exports.bufferMaxSizeMsg = new RegExp('^RangeError: "size" argument' +
59-
' must not be larger than ' +
60-
buffer.kMaxLength + '$');
58+
exports.bufferMaxSizeMsg = new RegExp(
59+
`^RangeError: "size" argument must not be larger than ${buffer.kMaxLength}$`);
6160
const cpus = os.cpus();
6261
exports.enoughTestCpu = Array.isArray(cpus) &&
6362
(cpus.length > 1 || cpus[0].speed > 999);
@@ -118,7 +117,7 @@ exports.refreshTmpDir = function() {
118117

119118
if (process.env.TEST_THREAD_ID) {
120119
exports.PORT += process.env.TEST_THREAD_ID * 100;
121-
exports.tmpDirName += '.' + process.env.TEST_THREAD_ID;
120+
exports.tmpDirName += `.${process.env.TEST_THREAD_ID}`;
122121
}
123122
exports.tmpDir = path.join(testRoot, exports.tmpDirName);
124123

@@ -217,10 +216,10 @@ Object.defineProperty(exports, 'hasFipsCrypto', {
217216
if (exports.isWindows) {
218217
exports.PIPE = '\\\\.\\pipe\\libuv-test';
219218
if (process.env.TEST_THREAD_ID) {
220-
exports.PIPE += '.' + process.env.TEST_THREAD_ID;
219+
exports.PIPE += `.${process.env.TEST_THREAD_ID}`;
221220
}
222221
} else {
223-
exports.PIPE = exports.tmpDir + '/test.sock';
222+
exports.PIPE = `${exports.tmpDir}/test.sock`;
224223
}
225224

226225
const ifaces = os.networkInterfaces();
@@ -256,10 +255,9 @@ exports.childShouldThrowAndAbort = function() {
256255
exports.ddCommand = function(filename, kilobytes) {
257256
if (exports.isWindows) {
258257
const p = path.resolve(exports.fixturesDir, 'create-file.js');
259-
return '"' + process.argv[0] + '" "' + p + '" "' +
260-
filename + '" ' + (kilobytes * 1024);
258+
return `"${process.argv[0]}" "${p}" "${filename}" ${kilobytes * 1024}`;
261259
} else {
262-
return 'dd if=/dev/zero of="' + filename + '" bs=1024 count=' + kilobytes;
260+
return `dd if=/dev/zero of="${filename}" bs=1024 count=${kilobytes}`;
263261
}
264262
};
265263

@@ -495,7 +493,7 @@ exports.canCreateSymLink = function() {
495493
let output = '';
496494

497495
try {
498-
output = execSync(whoamiPath + ' /priv', { timout: 1000 });
496+
output = execSync(`${whoamiPath} /priv`, { timout: 1000 });
499497
} catch (e) {
500498
err = true;
501499
} finally {
@@ -522,7 +520,7 @@ exports.skip = function(msg) {
522520
function ArrayStream() {
523521
this.run = function(data) {
524522
data.forEach((line) => {
525-
this.emit('data', line + '\n');
523+
this.emit('data', `${line}\n`);
526524
});
527525
};
528526
}

test/debugger/helper-debugger-repl.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ let quit;
3434

3535
function startDebugger(scriptToDebug) {
3636
scriptToDebug = process.env.NODE_DEBUGGER_TEST_SCRIPT ||
37-
common.fixturesDir + '/' + scriptToDebug;
37+
`${common.fixturesDir}/${scriptToDebug}`;
3838

39-
child = spawn(process.execPath, ['debug', '--port=' + port, scriptToDebug]);
39+
child = spawn(process.execPath, ['debug', `--port=${port}`, scriptToDebug]);
4040

41-
console.error('./node', 'debug', '--port=' + port, scriptToDebug);
41+
console.error('./node', 'debug', `--port=${port}`, scriptToDebug);
4242

4343
child.stdout.setEncoding('utf-8');
4444
child.stdout.on('data', function(data) {
@@ -53,10 +53,10 @@ function startDebugger(scriptToDebug) {
5353
child.on('line', function(line) {
5454
line = line.replace(/^(debug> *)+/, '');
5555
console.log(line);
56-
assert.ok(expected.length > 0, 'Got unexpected line: ' + line);
56+
assert.ok(expected.length > 0, `Got unexpected line: ${line}`);
5757

5858
const expectedLine = expected[0].lines.shift();
59-
assert.ok(line.match(expectedLine) !== null, line + ' != ' + expectedLine);
59+
assert.ok(line.match(expectedLine) !== null, `${line} != ${expectedLine}`);
6060

6161
if (expected[0].lines.length === 0) {
6262
const callback = expected[0].callback;
@@ -83,7 +83,7 @@ function startDebugger(scriptToDebug) {
8383
console.error('dying badly buffer=%j', buffer);
8484
let err = 'Timeout';
8585
if (expected.length > 0 && expected[0].lines) {
86-
err = err + '. Expected: ' + expected[0].lines.shift();
86+
err = `${err}. Expected: ${expected[0].lines.shift()}`;
8787
}
8888

8989
child.on('close', function() {
@@ -112,8 +112,8 @@ function startDebugger(scriptToDebug) {
112112
function addTest(input, output) {
113113
function next() {
114114
if (expected.length > 0) {
115-
console.log('debug> ' + expected[0].input);
116-
child.stdin.write(expected[0].input + '\n');
115+
console.log(`debug> ${expected[0].input}`);
116+
child.stdin.write(`${expected[0].input}\n`);
117117

118118
if (!expected[0].lines) {
119119
const callback = expected[0].callback;

test/debugger/test-debugger-repl-utf8.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
'use strict';
2323
const common = require('../common');
24-
const script = common.fixturesDir + '/breakpoints_utf8.js';
24+
const script = `${common.fixturesDir}/breakpoints_utf8.js`;
2525
process.env.NODE_DEBUGGER_TEST_SCRIPT = script;
2626

2727
require('./test-debugger-repl.js');

test/gc/test-http-client-connaborted.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ let done = 0;
1515
let count = 0;
1616
let countGC = 0;
1717

18-
console.log('We should do ' + todo + ' requests');
18+
console.log(`We should do ${todo} requests`);
1919

2020
const server = http.createServer(serverHandler);
2121
server.listen(0, getall);

test/gc/test-http-client-onerror.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ let done = 0;
1717
let count = 0;
1818
let countGC = 0;
1919

20-
console.log('We should do ' + todo + ' requests');
20+
console.log(`We should do ${todo} requests`);
2121

2222
const server = http.createServer(serverHandler);
2323
server.listen(0, runTest);

test/gc/test-http-client-timeout.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ let done = 0;
1919
let count = 0;
2020
let countGC = 0;
2121

22-
console.log('We should do ' + todo + ' requests');
22+
console.log(`We should do ${todo} requests`);
2323

2424
const server = http.createServer(serverHandler);
2525
server.listen(0, getall);

test/gc/test-http-client.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ let done = 0;
1515
let count = 0;
1616
let countGC = 0;
1717

18-
console.log('We should do ' + todo + ' requests');
18+
console.log(`We should do ${todo} requests`);
1919

2020
const server = http.createServer(serverHandler);
2121
server.listen(0, getall);

test/gc/test-net-timeout.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ let done = 0;
2626
let count = 0;
2727
let countGC = 0;
2828

29-
console.log('We should do ' + todo + ' requests');
29+
console.log(`We should do ${todo} requests`);
3030

3131
const server = net.createServer(serverHandler);
3232
server.listen(0, getall);

test/inspector/inspector-helper.js

+10-12
Original file line numberDiff line numberDiff line change
@@ -169,13 +169,15 @@ TestSession.prototype.processMessage_ = function(message) {
169169
assert.strictEqual(id, this.expectedId_);
170170
this.expectedId_++;
171171
if (this.responseCheckers_[id]) {
172-
assert(message['result'], JSON.stringify(message) + ' (response to ' +
173-
JSON.stringify(this.messages_[id]) + ')');
172+
const messageJSON = JSON.stringify(message);
173+
const idJSON = JSON.stringify(this.messages_[id]);
174+
assert(message['result'], `${messageJSON} (response to ${idJSON})`);
174175
this.responseCheckers_[id](message['result']);
175176
delete this.responseCheckers_[id];
176177
}
177-
assert(!message['error'], JSON.stringify(message) + ' (replying to ' +
178-
JSON.stringify(this.messages_[id]) + ')');
178+
const messageJSON = JSON.stringify(message);
179+
const idJSON = JSON.stringify(this.messages_[id]);
180+
assert(!message['error'], `${messageJSON} (replying to ${idJSON})`);
179181
delete this.messages_[id];
180182
if (id === this.lastId_) {
181183
this.lastMessageResponseCallback_ && this.lastMessageResponseCallback_();
@@ -213,12 +215,8 @@ TestSession.prototype.sendInspectorCommands = function(commands) {
213215
};
214216
this.sendAll_(commands, () => {
215217
timeoutId = setTimeout(() => {
216-
let s = '';
217-
for (const id in this.messages_) {
218-
s += id + ', ';
219-
}
220-
assert.fail('Messages without response: ' +
221-
s.substring(0, s.length - 2));
218+
assert.fail(`Messages without response: ${
219+
Object.keys(this.messages_).join(', ')}`);
222220
}, TIMEOUT);
223221
});
224222
});
@@ -241,7 +239,7 @@ TestSession.prototype.expectMessages = function(expects) {
241239
if (!(expects instanceof Array)) expects = [ expects ];
242240

243241
const callback = this.createCallbackWithTimeout_(
244-
'Matching response was not received:\n' + expects[0]);
242+
`Matching response was not received:\n${expects[0]}`);
245243
this.messagefilter_ = (message) => {
246244
if (expects[0](message))
247245
expects.shift();
@@ -256,7 +254,7 @@ TestSession.prototype.expectMessages = function(expects) {
256254
TestSession.prototype.expectStderrOutput = function(regexp) {
257255
this.harness_.addStderrFilter(
258256
regexp,
259-
this.createCallbackWithTimeout_('Timed out waiting for ' + regexp));
257+
this.createCallbackWithTimeout_(`Timed out waiting for ${regexp}`));
260258
return this;
261259
};
262260

test/inspector/test-inspector.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ function checkVersion(err, response) {
1919
assert.ifError(err);
2020
assert.ok(response);
2121
const expected = {
22-
'Browser': 'node.js/' + process.version,
22+
'Browser': `node.js/${process.version}`,
2323
'Protocol-Version': '1.1',
2424
};
2525
assert.strictEqual(JSON.stringify(response),
@@ -36,7 +36,7 @@ function expectMainScriptSource(result) {
3636
const expected = helper.mainScriptSource();
3737
const source = result['scriptSource'];
3838
assert(source && (source.includes(expected)),
39-
'Script source is wrong: ' + source);
39+
`Script source is wrong: ${source}`);
4040
}
4141

4242
function setupExpectBreakOnLine(line, url, session, scopeIdCallback) {
@@ -187,7 +187,7 @@ function testI18NCharacters(session) {
187187
{
188188
'method': 'Debugger.evaluateOnCallFrame', 'params': {
189189
'callFrameId': '{"ordinal":0,"injectedScriptId":1}',
190-
'expression': 'console.log("' + chars + '")',
190+
'expression': `console.log("${chars}")`,
191191
'objectGroup': 'console',
192192
'includeCommandLineAPI': true,
193193
'silent': false,

test/internet/test-dns-cares-domains.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ methods.forEach(function(method) {
2121
const d = domain.create();
2222
d.run(function() {
2323
dns[method]('google.com', function() {
24-
assert.strictEqual(process.domain, d, method + ' retains domain');
24+
assert.strictEqual(process.domain, d, `${method} retains domain`);
2525
});
2626
});
2727
});

test/internet/test-dns-ipv6.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ TEST(function test_lookup_all_ipv6(done) {
164164

165165
ips.forEach((ip) => {
166166
assert.ok(isIPv6(ip.address),
167-
'Invalid IPv6: ' + ip.address.toString());
167+
`Invalid IPv6: ${ip.address.toString()}`);
168168
assert.strictEqual(ip.family, 6);
169169
});
170170

test/internet/test-dns.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@ req.oncomplete = function(err, domains) {
545545
};
546546

547547
process.on('exit', function() {
548-
console.log(completed + ' tests completed');
548+
console.log(`${completed} tests completed`);
549549
assert.strictEqual(running, false);
550550
assert.strictEqual(expected, completed);
551551
assert.ok(getaddrinfoCallbackCalled);

test/internet/test-tls-add-ca-cert.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const fs = require('fs');
1313
const tls = require('tls');
1414

1515
function filenamePEM(n) {
16-
return require('path').join(common.fixturesDir, 'keys', n + '.pem');
16+
return require('path').join(common.fixturesDir, 'keys', `${n}.pem`);
1717
}
1818

1919
function loadPEM(n) {

test/known_issues/test-cwd-enoent-file.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ if (process.argv[2] === 'child') {
1919
// Do nothing.
2020
} else {
2121
common.refreshTmpDir();
22-
const dir = fs.mkdtempSync(common.tmpDir + '/');
22+
const dir = fs.mkdtempSync(`${common.tmpDir}/`);
2323
process.chdir(dir);
2424
fs.rmdirSync(dir);
2525
assert.throws(process.cwd,

test/parallel/test-assert.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ assert.doesNotThrow(makeBlock(a.deepEqual, a1, a2));
177177

178178
// having an identical prototype property
179179
const nbRoot = {
180-
toString: function() { return this.first + ' ' + this.last; }
180+
toString: function() { return `${this.first} ${this.last}`; }
181181
};
182182

183183
function nameBuilder(first, last) {

test/parallel/test-async-wrap-check-providers.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ process.on('SIGINT', () => process.exit());
9494
// Run from closed net server above.
9595
function checkTLS() {
9696
const options = {
97-
key: fs.readFileSync(common.fixturesDir + '/keys/ec-key.pem'),
98-
cert: fs.readFileSync(common.fixturesDir + '/keys/ec-cert.pem')
97+
key: fs.readFileSync(`${common.fixturesDir}/keys/ec-key.pem`),
98+
cert: fs.readFileSync(`${common.fixturesDir}/keys/ec-cert.pem`)
9999
};
100100
const server = tls.createServer(options, common.noop)
101101
.listen(0, function() {

test/parallel/test-buffer-badhex.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,6 @@ const Buffer = require('buffer').Buffer;
4444
const hex = buf.toString('hex');
4545
assert.deepStrictEqual(Buffer.from(hex, 'hex'), buf);
4646

47-
const badHex = hex.slice(0, 256) + 'xx' + hex.slice(256, 510);
47+
const badHex = `${hex.slice(0, 256)}xx${hex.slice(256, 510)}`;
4848
assert.deepStrictEqual(Buffer.from(badHex, 'hex'), buf.slice(0, 128));
4949
}

test/parallel/test-buffer-includes.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ const longBufferString = Buffer.from(longString);
199199
let pattern = 'ABACABADABACABA';
200200
for (let i = 0; i < longBufferString.length - pattern.length; i += 7) {
201201
const includes = longBufferString.includes(pattern, i);
202-
assert(includes, 'Long ABACABA...-string at index ' + i);
202+
assert(includes, `Long ABACABA...-string at index ${i}`);
203203
}
204204
assert(longBufferString.includes('AJABACA'), 'Long AJABACA, First J');
205205
assert(longBufferString.includes('AJABACA', 511), 'Long AJABACA, Second J');

test/parallel/test-buffer-indexof.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ let pattern = 'ABACABADABACABA';
255255
for (let i = 0; i < longBufferString.length - pattern.length; i += 7) {
256256
const index = longBufferString.indexOf(pattern, i);
257257
assert.strictEqual((i + 15) & ~0xf, index,
258-
'Long ABACABA...-string at index ' + i);
258+
`Long ABACABA...-string at index ${i}`);
259259
}
260260
assert.strictEqual(510, longBufferString.indexOf('AJABACA'),
261261
'Long AJABACA, First J');

test/parallel/test-child-process-buffering.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ function pwd(callback) {
2929

3030
child.stdout.setEncoding('utf8');
3131
child.stdout.on('data', function(s) {
32-
console.log('stdout: ' + JSON.stringify(s));
32+
console.log(`stdout: ${JSON.stringify(s)}`);
3333
output += s;
3434
});
3535

3636
child.on('exit', common.mustCall(function(c) {
37-
console.log('exit: ' + c);
37+
console.log(`exit: ${c}`);
3838
assert.strictEqual(0, c);
3939
}));
4040

test/parallel/test-child-process-default-options.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ let response = '';
3939
child.stdout.setEncoding('utf8');
4040

4141
child.stdout.on('data', function(chunk) {
42-
console.log('stdout: ' + chunk);
42+
console.log(`stdout: ${chunk}`);
4343
response += chunk;
4444
});
4545

test/parallel/test-child-process-double-pipe.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ if (common.isWindows) {
5656

5757
// pipe echo | grep
5858
echo.stdout.on('data', function(data) {
59-
console.error('grep stdin write ' + data.length);
59+
console.error(`grep stdin write ${data.length}`);
6060
if (!grep.stdin.write(data)) {
6161
echo.stdout.pause();
6262
}
@@ -86,7 +86,7 @@ sed.on('exit', function() {
8686

8787
// pipe grep | sed
8888
grep.stdout.on('data', function(data) {
89-
console.error('grep stdout ' + data.length);
89+
console.error(`grep stdout ${data.length}`);
9090
if (!sed.stdin.write(data)) {
9191
grep.stdout.pause();
9292
}

test/parallel/test-child-process-env.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ let response = '';
4545
child.stdout.setEncoding('utf8');
4646

4747
child.stdout.on('data', function(chunk) {
48-
console.log('stdout: ' + chunk);
48+
console.log(`stdout: ${chunk}`);
4949
response += chunk;
5050
});
5151

0 commit comments

Comments
 (0)