Skip to content
Permalink
Browse files

test: reduce string concatenations

PR-URL: #12735
Refs: #12455
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>
  • Loading branch information...
vsemozhetbyt committed Apr 28, 2017
1 parent 6bcf65d commit 8b76c3e60c7b5c274c757257580a2c0faae69097
Showing 350 changed files with 1,001 additions and 1,075 deletions.
@@ -39,7 +39,7 @@ process.on('exit', function() {

const lines = [
// This line shouldn't cause an assertion error.
'require(\'' + buildPath + '\')' +
`require('${buildPath}')` +
// Log output to double check callback ran.
'.method(function() { console.log(\'cb_ran\'); });',
];
@@ -55,9 +55,8 @@ exports.isLinux = process.platform === 'linux';
exports.isOSX = process.platform === 'darwin';

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

if (process.env.TEST_THREAD_ID) {
exports.PORT += process.env.TEST_THREAD_ID * 100;
exports.tmpDirName += '.' + process.env.TEST_THREAD_ID;
exports.tmpDirName += `.${process.env.TEST_THREAD_ID}`;
}
exports.tmpDir = path.join(testRoot, exports.tmpDirName);

@@ -217,10 +216,10 @@ Object.defineProperty(exports, 'hasFipsCrypto', {
if (exports.isWindows) {
exports.PIPE = '\\\\.\\pipe\\libuv-test';
if (process.env.TEST_THREAD_ID) {
exports.PIPE += '.' + process.env.TEST_THREAD_ID;
exports.PIPE += `.${process.env.TEST_THREAD_ID}`;
}
} else {
exports.PIPE = exports.tmpDir + '/test.sock';
exports.PIPE = `${exports.tmpDir}/test.sock`;
}

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

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

try {
output = execSync(whoamiPath + ' /priv', { timout: 1000 });
output = execSync(`${whoamiPath} /priv`, { timout: 1000 });
} catch (e) {
err = true;
} finally {
@@ -522,7 +520,7 @@ exports.skip = function(msg) {
function ArrayStream() {
this.run = function(data) {
data.forEach((line) => {
this.emit('data', line + '\n');
this.emit('data', `${line}\n`);
});
};
}
@@ -34,11 +34,11 @@ let quit;

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

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

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

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

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

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

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

if (!expected[0].lines) {
const callback = expected[0].callback;
@@ -21,7 +21,7 @@

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

require('./test-debugger-repl.js');
@@ -15,7 +15,7 @@ let done = 0;
let count = 0;
let countGC = 0;

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

const server = http.createServer(serverHandler);
server.listen(0, getall);
@@ -17,7 +17,7 @@ let done = 0;
let count = 0;
let countGC = 0;

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

const server = http.createServer(serverHandler);
server.listen(0, runTest);
@@ -19,7 +19,7 @@ let done = 0;
let count = 0;
let countGC = 0;

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

const server = http.createServer(serverHandler);
server.listen(0, getall);
@@ -15,7 +15,7 @@ let done = 0;
let count = 0;
let countGC = 0;

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

const server = http.createServer(serverHandler);
server.listen(0, getall);
@@ -26,7 +26,7 @@ let done = 0;
let count = 0;
let countGC = 0;

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

const server = net.createServer(serverHandler);
server.listen(0, getall);
@@ -169,13 +169,15 @@ TestSession.prototype.processMessage_ = function(message) {
assert.strictEqual(id, this.expectedId_);
this.expectedId_++;
if (this.responseCheckers_[id]) {
assert(message['result'], JSON.stringify(message) + ' (response to ' +
JSON.stringify(this.messages_[id]) + ')');
const messageJSON = JSON.stringify(message);
const idJSON = JSON.stringify(this.messages_[id]);
assert(message['result'], `${messageJSON} (response to ${idJSON})`);
this.responseCheckers_[id](message['result']);
delete this.responseCheckers_[id];
}
assert(!message['error'], JSON.stringify(message) + ' (replying to ' +
JSON.stringify(this.messages_[id]) + ')');
const messageJSON = JSON.stringify(message);
const idJSON = JSON.stringify(this.messages_[id]);
assert(!message['error'], `${messageJSON} (replying to ${idJSON})`);
delete this.messages_[id];
if (id === this.lastId_) {
this.lastMessageResponseCallback_ && this.lastMessageResponseCallback_();
@@ -213,12 +215,8 @@ TestSession.prototype.sendInspectorCommands = function(commands) {
};
this.sendAll_(commands, () => {
timeoutId = setTimeout(() => {
let s = '';
for (const id in this.messages_) {
s += id + ', ';
}
assert.fail('Messages without response: ' +
s.substring(0, s.length - 2));
assert.fail(`Messages without response: ${
Object.keys(this.messages_).join(', ')}`);
}, TIMEOUT);
});
});
@@ -241,7 +239,7 @@ TestSession.prototype.expectMessages = function(expects) {
if (!(expects instanceof Array)) expects = [ expects ];

const callback = this.createCallbackWithTimeout_(
'Matching response was not received:\n' + expects[0]);
`Matching response was not received:\n${expects[0]}`);
this.messagefilter_ = (message) => {
if (expects[0](message))
expects.shift();
@@ -256,7 +254,7 @@ TestSession.prototype.expectMessages = function(expects) {
TestSession.prototype.expectStderrOutput = function(regexp) {
this.harness_.addStderrFilter(
regexp,
this.createCallbackWithTimeout_('Timed out waiting for ' + regexp));
this.createCallbackWithTimeout_(`Timed out waiting for ${regexp}`));
return this;
};

@@ -19,7 +19,7 @@ function checkVersion(err, response) {
assert.ifError(err);
assert.ok(response);
const expected = {
'Browser': 'node.js/' + process.version,
'Browser': `node.js/${process.version}`,
'Protocol-Version': '1.1',
};
assert.strictEqual(JSON.stringify(response),
@@ -36,7 +36,7 @@ function expectMainScriptSource(result) {
const expected = helper.mainScriptSource();
const source = result['scriptSource'];
assert(source && (source.includes(expected)),
'Script source is wrong: ' + source);
`Script source is wrong: ${source}`);
}

function setupExpectBreakOnLine(line, url, session, scopeIdCallback) {
@@ -187,7 +187,7 @@ function testI18NCharacters(session) {
{
'method': 'Debugger.evaluateOnCallFrame', 'params': {
'callFrameId': '{"ordinal":0,"injectedScriptId":1}',
'expression': 'console.log("' + chars + '")',
'expression': `console.log("${chars}")`,
'objectGroup': 'console',
'includeCommandLineAPI': true,
'silent': false,
@@ -21,7 +21,7 @@ methods.forEach(function(method) {
const d = domain.create();
d.run(function() {
dns[method]('google.com', function() {
assert.strictEqual(process.domain, d, method + ' retains domain');
assert.strictEqual(process.domain, d, `${method} retains domain`);
});
});
});
@@ -164,7 +164,7 @@ TEST(function test_lookup_all_ipv6(done) {

ips.forEach((ip) => {
assert.ok(isIPv6(ip.address),
'Invalid IPv6: ' + ip.address.toString());
`Invalid IPv6: ${ip.address.toString()}`);
assert.strictEqual(ip.family, 6);
});

@@ -545,7 +545,7 @@ req.oncomplete = function(err, domains) {
};

process.on('exit', function() {
console.log(completed + ' tests completed');
console.log(`${completed} tests completed`);
assert.strictEqual(running, false);
assert.strictEqual(expected, completed);
assert.ok(getaddrinfoCallbackCalled);
@@ -13,7 +13,7 @@ const fs = require('fs');
const tls = require('tls');

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

function loadPEM(n) {
@@ -19,7 +19,7 @@ if (process.argv[2] === 'child') {
// Do nothing.
} else {
common.refreshTmpDir();
const dir = fs.mkdtempSync(common.tmpDir + '/');
const dir = fs.mkdtempSync(`${common.tmpDir}/`);
process.chdir(dir);
fs.rmdirSync(dir);
assert.throws(process.cwd,
@@ -177,7 +177,7 @@ assert.doesNotThrow(makeBlock(a.deepEqual, a1, a2));

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

function nameBuilder(first, last) {
@@ -94,8 +94,8 @@ process.on('SIGINT', () => process.exit());
// Run from closed net server above.
function checkTLS() {
const options = {
key: fs.readFileSync(common.fixturesDir + '/keys/ec-key.pem'),
cert: fs.readFileSync(common.fixturesDir + '/keys/ec-cert.pem')
key: fs.readFileSync(`${common.fixturesDir}/keys/ec-key.pem`),
cert: fs.readFileSync(`${common.fixturesDir}/keys/ec-cert.pem`)
};
const server = tls.createServer(options, common.noop)
.listen(0, function() {
@@ -44,6 +44,6 @@ const Buffer = require('buffer').Buffer;
const hex = buf.toString('hex');
assert.deepStrictEqual(Buffer.from(hex, 'hex'), buf);

const badHex = hex.slice(0, 256) + 'xx' + hex.slice(256, 510);
const badHex = `${hex.slice(0, 256)}xx${hex.slice(256, 510)}`;
assert.deepStrictEqual(Buffer.from(badHex, 'hex'), buf.slice(0, 128));
}
@@ -199,7 +199,7 @@ const longBufferString = Buffer.from(longString);
let pattern = 'ABACABADABACABA';
for (let i = 0; i < longBufferString.length - pattern.length; i += 7) {
const includes = longBufferString.includes(pattern, i);
assert(includes, 'Long ABACABA...-string at index ' + i);
assert(includes, `Long ABACABA...-string at index ${i}`);
}
assert(longBufferString.includes('AJABACA'), 'Long AJABACA, First J');
assert(longBufferString.includes('AJABACA', 511), 'Long AJABACA, Second J');
@@ -255,7 +255,7 @@ let pattern = 'ABACABADABACABA';
for (let i = 0; i < longBufferString.length - pattern.length; i += 7) {
const index = longBufferString.indexOf(pattern, i);
assert.strictEqual((i + 15) & ~0xf, index,
'Long ABACABA...-string at index ' + i);
`Long ABACABA...-string at index ${i}`);
}
assert.strictEqual(510, longBufferString.indexOf('AJABACA'),
'Long AJABACA, First J');
@@ -29,12 +29,12 @@ function pwd(callback) {

child.stdout.setEncoding('utf8');
child.stdout.on('data', function(s) {
console.log('stdout: ' + JSON.stringify(s));
console.log(`stdout: ${JSON.stringify(s)}`);
output += s;
});

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

@@ -39,7 +39,7 @@ let response = '';
child.stdout.setEncoding('utf8');

child.stdout.on('data', function(chunk) {
console.log('stdout: ' + chunk);
console.log(`stdout: ${chunk}`);
response += chunk;
});

@@ -56,7 +56,7 @@ if (common.isWindows) {

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

// pipe grep | sed
grep.stdout.on('data', function(data) {
console.error('grep stdout ' + data.length);
console.error(`grep stdout ${data.length}`);
if (!sed.stdin.write(data)) {
grep.stdout.pause();
}
@@ -45,7 +45,7 @@ let response = '';
child.stdout.setEncoding('utf8');

child.stdout.on('data', function(chunk) {
console.log('stdout: ' + chunk);
console.log(`stdout: ${chunk}`);
response += chunk;
});

0 comments on commit 8b76c3e

Please sign in to comment.
You can’t perform that action at this time.