Skip to content

Commit ecd11b6

Browse files
homosaurjasnell
authored andcommitted
test: swap var for let/const throughout
Swap var for let/const throughout the common.js module. Change a snake case variable to camel case starting on line 168. PR-URL: #10177 Reviewed-By: Сковорода Никита Андреевич <[email protected]> Reviewed-By: Sakthipriyan Vairamani <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 1c3c75d commit ecd11b6

File tree

1 file changed

+25
-24
lines changed

1 file changed

+25
-24
lines changed

test/common.js

+25-24
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,9 @@ exports.rootDir = exports.isWindows ? 'c:\\' : '/';
4141
exports.buildType = process.config.target_defaults.default_configuration;
4242

4343
function rimrafSync(p) {
44+
let st;
4445
try {
45-
var st = fs.lstatSync(p);
46+
st = fs.lstatSync(p);
4647
} catch (e) {
4748
if (e.code === 'ENOENT')
4849
return;
@@ -96,9 +97,9 @@ if (process.env.TEST_THREAD_ID) {
9697
}
9798
exports.tmpDir = path.join(testRoot, exports.tmpDirName);
9899

99-
var opensslCli = null;
100-
var inFreeBSDJail = null;
101-
var localhostIPv4 = null;
100+
let opensslCli = null;
101+
let inFreeBSDJail = null;
102+
let localhostIPv4 = null;
102103

103104
exports.localIPv6Hosts = ['localhost'];
104105
if (exports.isLinux) {
@@ -168,8 +169,8 @@ Object.defineProperty(exports, 'opensslCli', {get: function() {
168169

169170
if (exports.isWindows) opensslCli += '.exe';
170171

171-
var openssl_cmd = child_process.spawnSync(opensslCli, ['version']);
172-
if (openssl_cmd.status !== 0 || openssl_cmd.error !== undefined) {
172+
const opensslCmd = child_process.spawnSync(opensslCli, ['version']);
173+
if (opensslCmd.status !== 0 || opensslCmd.error !== undefined) {
173174
// openssl command cannot be executed
174175
opensslCli = false;
175176
}
@@ -197,7 +198,7 @@ if (exports.isWindows) {
197198
exports.PIPE = exports.tmpDir + '/test.sock';
198199
}
199200

200-
var ifaces = os.networkInterfaces();
201+
const ifaces = os.networkInterfaces();
201202
exports.hasIPv6 = Object.keys(ifaces).some(function(name) {
202203
return /lo/.test(name) && ifaces[name].some(function(info) {
203204
return info.family === 'IPv6';
@@ -229,7 +230,7 @@ exports.childShouldThrowAndAbort = function() {
229230

230231
exports.ddCommand = function(filename, kilobytes) {
231232
if (exports.isWindows) {
232-
var p = path.resolve(exports.fixturesDir, 'create-file.js');
233+
const p = path.resolve(exports.fixturesDir, 'create-file.js');
233234
return '"' + process.argv[0] + '" "' + p + '" "' +
234235
filename + '" ' + (kilobytes * 1024);
235236
} else {
@@ -239,7 +240,7 @@ exports.ddCommand = function(filename, kilobytes) {
239240

240241

241242
exports.spawnCat = function(options) {
242-
var spawn = require('child_process').spawn;
243+
const spawn = require('child_process').spawn;
243244

244245
if (exports.isWindows) {
245246
return spawn('more', [], options);
@@ -250,7 +251,7 @@ exports.spawnCat = function(options) {
250251

251252

252253
exports.spawnSyncCat = function(options) {
253-
var spawnSync = require('child_process').spawnSync;
254+
const spawnSync = require('child_process').spawnSync;
254255

255256
if (exports.isWindows) {
256257
return spawnSync('more', [], options);
@@ -261,7 +262,7 @@ exports.spawnSyncCat = function(options) {
261262

262263

263264
exports.spawnPwd = function(options) {
264-
var spawn = require('child_process').spawn;
265+
const spawn = require('child_process').spawn;
265266

266267
if (exports.isWindows) {
267268
return spawn('cmd.exe', ['/d', '/c', 'cd'], options);
@@ -302,7 +303,7 @@ exports.platformTimeout = function(ms) {
302303
return ms; // ARMv8+
303304
};
304305

305-
var knownGlobals = [
306+
let knownGlobals = [
306307
Buffer,
307308
clearImmediate,
308309
clearInterval,
@@ -376,9 +377,9 @@ function allowGlobals(...whitelist) {
376377
exports.allowGlobals = allowGlobals;
377378

378379
function leakedGlobals() {
379-
var leaked = [];
380+
const leaked = [];
380381

381-
for (var val in global)
382+
for (const val in global)
382383
if (!knownGlobals.includes(global[val]))
383384
leaked.push(val);
384385

@@ -391,21 +392,21 @@ exports.globalCheck = true;
391392

392393
process.on('exit', function() {
393394
if (!exports.globalCheck) return;
394-
var leaked = leakedGlobals();
395+
const leaked = leakedGlobals();
395396
if (leaked.length > 0) {
396397
console.error('Unknown globals: %s', leaked);
397398
fail('Unknown global found');
398399
}
399400
});
400401

401402

402-
var mustCallChecks = [];
403+
const mustCallChecks = [];
403404

404405

405406
function runCallChecks(exitCode) {
406407
if (exitCode !== 0) return;
407408

408-
var failed = mustCallChecks.filter(function(context) {
409+
const failed = mustCallChecks.filter(function(context) {
409410
return context.actual !== context.expected;
410411
});
411412

@@ -424,7 +425,7 @@ function runCallChecks(exitCode) {
424425
exports.mustCall = function(fn, expected) {
425426
if (typeof expected !== 'number') expected = 1;
426427

427-
var context = {
428+
const context = {
428429
expected: expected,
429430
actual: 0,
430431
stack: (new Error()).stack,
@@ -443,9 +444,9 @@ exports.mustCall = function(fn, expected) {
443444
};
444445

445446
exports.hasMultiLocalhost = function hasMultiLocalhost() {
446-
var TCP = process.binding('tcp_wrap').TCP;
447-
var t = new TCP();
448-
var ret = t.bind('127.0.0.2', exports.PORT);
447+
const TCP = process.binding('tcp_wrap').TCP;
448+
const t = new TCP();
449+
const ret = t.bind('127.0.0.2', exports.PORT);
449450
t.close();
450451
return ret === 0;
451452
};
@@ -491,7 +492,7 @@ ArrayStream.prototype.write = function() {};
491492
exports.nodeProcessAborted = function nodeProcessAborted(exitCode, signal) {
492493
// Depending on the compiler used, node will exit with either
493494
// exit code 132 (SIGILL), 133 (SIGTRAP) or 134 (SIGABRT).
494-
var expectedExitCodes = [132, 133, 134];
495+
let expectedExitCodes = [132, 133, 134];
495496

496497
// On platforms using KSH as the default shell (like SmartOS),
497498
// when a process aborts, KSH exits with an exit code that is
@@ -520,8 +521,8 @@ exports.nodeProcessAborted = function nodeProcessAborted(exitCode, signal) {
520521
};
521522

522523
exports.busyLoop = function busyLoop(time) {
523-
var startTime = Timer.now();
524-
var stopTime = startTime + time;
524+
const startTime = Timer.now();
525+
const stopTime = startTime + time;
525526
while (Timer.now() < stopTime) {}
526527
};
527528

0 commit comments

Comments
 (0)