Skip to content

Commit 35b55bf

Browse files
vsemozhetbytMylesBorins
authored andcommitted
test: reduce string concatenations
Backport-PR-URL: #13835 PR-URL: #12735 Refs: #12455 Reviewed-By: Refael Ackermann <[email protected]> Reviewed-By: Gibson Fahnestock <[email protected]>
1 parent bff589b commit 35b55bf

File tree

334 files changed

+957
-1026
lines changed

Some content is hidden

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

334 files changed

+957
-1026
lines changed

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

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

1919
const lines = [
2020
// This line shouldn't cause an assertion error.
21-
'require(\'' + buildPath + '\')' +
21+
`require('${buildPath}')` +
2222
// Log output to double check callback ran.
2323
'.method(function() { console.log(\'cb_ran\'); });',
2424
];

test/common/index.js

+6-7
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ exports.refreshTmpDir = function() {
9090

9191
if (process.env.TEST_THREAD_ID) {
9292
exports.PORT += process.env.TEST_THREAD_ID * 100;
93-
exports.tmpDirName += '.' + process.env.TEST_THREAD_ID;
93+
exports.tmpDirName += `.${process.env.TEST_THREAD_ID}`;
9494
}
9595
exports.tmpDir = path.join(testRoot, exports.tmpDirName);
9696

@@ -189,10 +189,10 @@ Object.defineProperty(exports, 'hasFipsCrypto', {
189189
if (exports.isWindows) {
190190
exports.PIPE = '\\\\.\\pipe\\libuv-test';
191191
if (process.env.TEST_THREAD_ID) {
192-
exports.PIPE += '.' + process.env.TEST_THREAD_ID;
192+
exports.PIPE += `.${process.env.TEST_THREAD_ID}`;
193193
}
194194
} else {
195-
exports.PIPE = exports.tmpDir + '/test.sock';
195+
exports.PIPE = `${exports.tmpDir}/test.sock`;
196196
}
197197

198198
const ifaces = os.networkInterfaces();
@@ -228,10 +228,9 @@ exports.childShouldThrowAndAbort = function() {
228228
exports.ddCommand = function(filename, kilobytes) {
229229
if (exports.isWindows) {
230230
const p = path.resolve(exports.fixturesDir, 'create-file.js');
231-
return '"' + process.argv[0] + '" "' + p + '" "' +
232-
filename + '" ' + (kilobytes * 1024);
231+
return `"${process.argv[0]}" "${p}" "${filename}" ${kilobytes * 1024}`;
233232
} else {
234-
return 'dd if=/dev/zero of="' + filename + '" bs=1024 count=' + kilobytes;
233+
return `dd if=/dev/zero of="${filename}" bs=1024 count=${kilobytes}`;
235234
}
236235
};
237236

@@ -478,7 +477,7 @@ exports.skip = function(msg) {
478477
function ArrayStream() {
479478
this.run = function(data) {
480479
data.forEach((line) => {
481-
this.emit('data', line + '\n');
480+
this.emit('data', `${line}\n`);
482481
});
483482
};
484483
}

test/debugger/helper-debugger-repl.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ let quit;
1313

1414
function startDebugger(scriptToDebug) {
1515
scriptToDebug = process.env.NODE_DEBUGGER_TEST_SCRIPT ||
16-
common.fixturesDir + '/' + scriptToDebug;
16+
`${common.fixturesDir}/${scriptToDebug}`;
1717

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

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

2222
child.stdout.setEncoding('utf-8');
2323
child.stdout.on('data', function(data) {
@@ -32,10 +32,10 @@ function startDebugger(scriptToDebug) {
3232
child.on('line', function(line) {
3333
line = line.replace(/^(debug> *)+/, '');
3434
console.log(line);
35-
assert.ok(expected.length > 0, 'Got unexpected line: ' + line);
35+
assert.ok(expected.length > 0, `Got unexpected line: ${line}`);
3636

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

4040
if (expected[0].lines.length === 0) {
4141
const callback = expected[0].callback;
@@ -62,7 +62,7 @@ function startDebugger(scriptToDebug) {
6262
console.error('dying badly buffer=%j', buffer);
6363
let err = 'Timeout';
6464
if (expected.length > 0 && expected[0].lines) {
65-
err = err + '. Expected: ' + expected[0].lines.shift();
65+
err = `${err}. Expected: ${expected[0].lines.shift()}`;
6666
}
6767

6868
child.on('close', function() {
@@ -91,8 +91,8 @@ function startDebugger(scriptToDebug) {
9191
function addTest(input, output) {
9292
function next() {
9393
if (expected.length > 0) {
94-
console.log('debug> ' + expected[0].input);
95-
child.stdin.write(expected[0].input + '\n');
94+
console.log(`debug> ${expected[0].input}`);
95+
child.stdin.write(`${expected[0].input}\n`);
9696

9797
if (!expected[0].lines) {
9898
const callback = expected[0].callback;
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22
const common = require('../common');
3-
const script = common.fixturesDir + '/breakpoints_utf8.js';
3+
const script = `${common.fixturesDir}/breakpoints_utf8.js`;
44
process.env.NODE_DEBUGGER_TEST_SCRIPT = script;
55

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

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

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

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

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

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

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

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

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

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

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

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

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

test/gc/test-http-client.js

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

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

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

test/gc/test-net-timeout.js

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

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

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

test/inspector/inspector-helper.js

+10-12
Original file line numberDiff line numberDiff line change
@@ -167,13 +167,15 @@ TestSession.prototype.processMessage_ = function(message) {
167167
assert.strictEqual(id, this.expectedId_);
168168
this.expectedId_++;
169169
if (this.responseCheckers_[id]) {
170-
assert(message['result'], JSON.stringify(message) + ' (response to ' +
171-
JSON.stringify(this.messages_[id]) + ')');
170+
const messageJSON = JSON.stringify(message);
171+
const idJSON = JSON.stringify(this.messages_[id]);
172+
assert(message['result'], `${messageJSON} (response to ${idJSON})`);
172173
this.responseCheckers_[id](message['result']);
173174
delete this.responseCheckers_[id];
174175
}
175-
assert(!message['error'], JSON.stringify(message) + ' (replying to ' +
176-
JSON.stringify(this.messages_[id]) + ')');
176+
const messageJSON = JSON.stringify(message);
177+
const idJSON = JSON.stringify(this.messages_[id]);
178+
assert(!message['error'], `${messageJSON} (replying to ${idJSON})`);
177179
delete this.messages_[id];
178180
if (id === this.lastId_) {
179181
this.lastMessageResponseCallback_ && this.lastMessageResponseCallback_();
@@ -211,12 +213,8 @@ TestSession.prototype.sendInspectorCommands = function(commands) {
211213
};
212214
this.sendAll_(commands, () => {
213215
timeoutId = setTimeout(() => {
214-
let s = '';
215-
for (const id in this.messages_) {
216-
s += id + ', ';
217-
}
218-
common.fail('Messages without response: ' +
219-
s.substring(0, s.length - 2));
216+
common.fail(`Messages without response: ${
217+
Object.keys(this.messages_).join(', ')}`);
220218
}, TIMEOUT);
221219
});
222220
});
@@ -239,7 +237,7 @@ TestSession.prototype.expectMessages = function(expects) {
239237
if (!(expects instanceof Array)) expects = [ expects ];
240238

241239
const callback = this.createCallbackWithTimeout_(
242-
'Matching response was not received:\n' + expects[0]);
240+
`Matching response was not received:\n${expects[0]}`);
243241
this.messagefilter_ = (message) => {
244242
if (expects[0](message))
245243
expects.shift();
@@ -254,7 +252,7 @@ TestSession.prototype.expectMessages = function(expects) {
254252
TestSession.prototype.expectStderrOutput = function(regexp) {
255253
this.harness_.addStderrFilter(
256254
regexp,
257-
this.createCallbackWithTimeout_('Timed out waiting for ' + regexp));
255+
this.createCallbackWithTimeout_(`Timed out waiting for ${regexp}`));
258256
return this;
259257
};
260258

test/inspector/test-inspector.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ function checkVersion(err, response) {
1818
assert.ifError(err);
1919
assert.ok(response);
2020
const expected = {
21-
'Browser': 'node.js/' + process.version,
21+
'Browser': `node.js/${process.version}`,
2222
'Protocol-Version': '1.1',
2323
};
2424
assert.strictEqual(JSON.stringify(response),
@@ -35,7 +35,7 @@ function expectMainScriptSource(result) {
3535
const expected = helper.mainScriptSource();
3636
const source = result['scriptSource'];
3737
assert(source && (source.includes(expected)),
38-
'Script source is wrong: ' + source);
38+
`Script source is wrong: ${source}`);
3939
}
4040

4141
function setupExpectBreakOnLine(line, url, session, scopeIdCallback) {

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
@@ -541,7 +541,7 @@ req.oncomplete = function(err, domains) {
541541
};
542542

543543
process.on('exit', function() {
544-
console.log(completed + ' tests completed');
544+
console.log(`${completed} tests completed`);
545545
assert.strictEqual(running, false);
546546
assert.strictEqual(expected, completed);
547547
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/parallel/test-assert.js

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

140140
// having an identical prototype property
141141
const nbRoot = {
142-
toString: function() { return this.first + ' ' + this.last; }
142+
toString: function() { return `${this.first} ${this.last}`; }
143143
};
144144

145145
function nameBuilder(first, last) {

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ process.on('SIGINT', () => process.exit());
9191
// Run from closed net server above.
9292
function checkTLS() {
9393
const options = {
94-
key: fs.readFileSync(common.fixturesDir + '/keys/ec-key.pem'),
95-
cert: fs.readFileSync(common.fixturesDir + '/keys/ec-cert.pem')
94+
key: fs.readFileSync(`${common.fixturesDir}/keys/ec-key.pem`),
95+
cert: fs.readFileSync(`${common.fixturesDir}/keys/ec-cert.pem`)
9696
};
9797
const server = tls.createServer(options, noop)
9898
.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
@@ -8,12 +8,12 @@ function pwd(callback) {
88

99
child.stdout.setEncoding('utf8');
1010
child.stdout.on('data', function(s) {
11-
console.log('stdout: ' + JSON.stringify(s));
11+
console.log(`stdout: ${JSON.stringify(s)}`);
1212
output += s;
1313
});
1414

1515
child.on('exit', common.mustCall(function(c) {
16-
console.log('exit: ' + c);
16+
console.log(`exit: ${c}`);
1717
assert.strictEqual(0, c);
1818
}));
1919

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ let response = '';
1818
child.stdout.setEncoding('utf8');
1919

2020
child.stdout.on('data', function(chunk) {
21-
console.log('stdout: ' + chunk);
21+
console.log(`stdout: ${chunk}`);
2222
response += chunk;
2323
});
2424

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

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

3636
// pipe echo | grep
3737
echo.stdout.on('data', function(data) {
38-
console.error('grep stdin write ' + data.length);
38+
console.error(`grep stdin write ${data.length}`);
3939
if (!grep.stdin.write(data)) {
4040
echo.stdout.pause();
4141
}
@@ -65,7 +65,7 @@ sed.on('exit', function() {
6565

6666
// pipe grep | sed
6767
grep.stdout.on('data', function(data) {
68-
console.error('grep stdout ' + data.length);
68+
console.error(`grep stdout ${data.length}`);
6969
if (!sed.stdin.write(data)) {
7070
grep.stdout.pause();
7171
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ let response = '';
2424
child.stdout.setEncoding('utf8');
2525

2626
child.stdout.on('data', function(chunk) {
27-
console.log('stdout: ' + chunk);
27+
console.log(`stdout: ${chunk}`);
2828
response += chunk;
2929
});
3030

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ let child;
1010
function after(err, stdout, stderr) {
1111
if (err) {
1212
error_count++;
13-
console.log('error!: ' + err.code);
14-
console.log('stdout: ' + JSON.stringify(stdout));
15-
console.log('stderr: ' + JSON.stringify(stderr));
13+
console.log(`error!: ${err.code}`);
14+
console.log(`stdout: ${JSON.stringify(stdout)}`);
15+
console.log(`stderr: ${JSON.stringify(stderr)}`);
1616
assert.strictEqual(false, err.killed);
1717
} else {
1818
success_count++;

test/parallel/test-child-process-fork-close.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const common = require('../common');
33
const assert = require('assert');
44
const fork = require('child_process').fork;
55

6-
const cp = fork(common.fixturesDir + '/child-process-message-and-exit.js');
6+
const cp = fork(`${common.fixturesDir}/child-process-message-and-exit.js`);
77

88
let gotMessage = false;
99
let gotExit = false;

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const assert = require('assert');
44
const fork = require('child_process').fork;
55
const args = ['foo', 'bar'];
66

7-
const n = fork(common.fixturesDir + '/child-process-spawn-node.js', args);
7+
const n = fork(`${common.fixturesDir}/child-process-spawn-node.js`, args);
88
assert.deepStrictEqual(args, ['foo', 'bar']);
99

1010
n.on('message', function(m) {

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
const common = require('../common');
33
const child_process = require('child_process');
44

5-
child_process.fork(common.fixturesDir + '/empty.js'); // should not hang
5+
child_process.fork(`${common.fixturesDir}/empty.js`); // should not hang

0 commit comments

Comments
 (0)