Skip to content

Commit 5b74e63

Browse files
vsemozhetbytMylesBorins
authored andcommitted
test: reduce string concatenations
Backport-PR-URL: #13835 PR-URL: #12735 Refs: #12455 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>
1 parent c902265 commit 5b74e63

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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 6 additions & 7 deletions
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

Lines changed: 8 additions & 8 deletions
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;
Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 10 additions & 12 deletions
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

0 commit comments

Comments
 (0)