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

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

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

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

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

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

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

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

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

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

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

0 commit comments

Comments
 (0)