Skip to content

Commit

Permalink
test: swap var for let/const throughout
Browse files Browse the repository at this point in the history
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: Сковорода Никита Андреевич <chalkerx@gmail.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
homosaur authored and MylesBorins committed Jan 23, 2017
1 parent 93977a9 commit f97a5e1
Showing 1 changed file with 25 additions and 24 deletions.
49 changes: 25 additions & 24 deletions test/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ exports.rootDir = exports.isWindows ? 'c:\\' : '/';
exports.buildType = process.config.target_defaults.default_configuration;

function rimrafSync(p) {
let st;
try {
var st = fs.lstatSync(p);
st = fs.lstatSync(p);
} catch (e) {
if (e.code === 'ENOENT')
return;
Expand Down Expand Up @@ -93,9 +94,9 @@ if (process.env.TEST_THREAD_ID) {
}
exports.tmpDir = path.join(testRoot, exports.tmpDirName);

var opensslCli = null;
var inFreeBSDJail = null;
var localhostIPv4 = null;
let opensslCli = null;
let inFreeBSDJail = null;
let localhostIPv4 = null;

exports.localIPv6Hosts = ['localhost'];
if (exports.isLinux) {
Expand Down Expand Up @@ -165,8 +166,8 @@ Object.defineProperty(exports, 'opensslCli', {get: function() {

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

var openssl_cmd = child_process.spawnSync(opensslCli, ['version']);
if (openssl_cmd.status !== 0 || openssl_cmd.error !== undefined) {
const opensslCmd = child_process.spawnSync(opensslCli, ['version']);
if (opensslCmd.status !== 0 || opensslCmd.error !== undefined) {
// openssl command cannot be executed
opensslCli = false;
}
Expand Down Expand Up @@ -194,7 +195,7 @@ if (exports.isWindows) {
exports.PIPE = exports.tmpDir + '/test.sock';
}

var ifaces = os.networkInterfaces();
const ifaces = os.networkInterfaces();
exports.hasIPv6 = Object.keys(ifaces).some(function(name) {
return /lo/.test(name) && ifaces[name].some(function(info) {
return info.family === 'IPv6';
Expand All @@ -204,7 +205,7 @@ exports.hasIPv6 = Object.keys(ifaces).some(function(name) {

exports.ddCommand = function(filename, kilobytes) {
if (exports.isWindows) {
var p = path.resolve(exports.fixturesDir, 'create-file.js');
const p = path.resolve(exports.fixturesDir, 'create-file.js');
return '"' + process.argv[0] + '" "' + p + '" "' +
filename + '" ' + (kilobytes * 1024);
} else {
Expand All @@ -214,7 +215,7 @@ exports.ddCommand = function(filename, kilobytes) {


exports.spawnCat = function(options) {
var spawn = require('child_process').spawn;
const spawn = require('child_process').spawn;

if (exports.isWindows) {
return spawn('more', [], options);
Expand All @@ -225,7 +226,7 @@ exports.spawnCat = function(options) {


exports.spawnSyncCat = function(options) {
var spawnSync = require('child_process').spawnSync;
const spawnSync = require('child_process').spawnSync;

if (exports.isWindows) {
return spawnSync('more', [], options);
Expand All @@ -236,7 +237,7 @@ exports.spawnSyncCat = function(options) {


exports.spawnPwd = function(options) {
var spawn = require('child_process').spawn;
const spawn = require('child_process').spawn;

if (exports.isWindows) {
return spawn('cmd.exe', ['/c', 'cd'], options);
Expand Down Expand Up @@ -277,7 +278,7 @@ exports.platformTimeout = function(ms) {
return ms; // ARMv8+
};

var knownGlobals = [
let knownGlobals = [
Buffer,
clearImmediate,
clearInterval,
Expand Down Expand Up @@ -351,9 +352,9 @@ function allowGlobals(...whitelist) {
exports.allowGlobals = allowGlobals;

function leakedGlobals() {
var leaked = [];
const leaked = [];

for (var val in global)
for (const val in global)
if (!knownGlobals.includes(global[val]))
leaked.push(val);

Expand All @@ -366,21 +367,21 @@ exports.globalCheck = true;

process.on('exit', function() {
if (!exports.globalCheck) return;
var leaked = leakedGlobals();
const leaked = leakedGlobals();
if (leaked.length > 0) {
console.error('Unknown globals: %s', leaked);
fail('Unknown global found');
}
});


var mustCallChecks = [];
const mustCallChecks = [];


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

var failed = mustCallChecks.filter(function(context) {
const failed = mustCallChecks.filter(function(context) {
return context.actual !== context.expected;
});

Expand All @@ -399,7 +400,7 @@ function runCallChecks(exitCode) {
exports.mustCall = function(fn, expected) {
if (typeof expected !== 'number') expected = 1;

var context = {
const context = {
expected: expected,
actual: 0,
stack: (new Error()).stack,
Expand All @@ -418,9 +419,9 @@ exports.mustCall = function(fn, expected) {
};

exports.hasMultiLocalhost = function hasMultiLocalhost() {
var TCP = process.binding('tcp_wrap').TCP;
var t = new TCP();
var ret = t.bind('127.0.0.2', exports.PORT);
const TCP = process.binding('tcp_wrap').TCP;
const t = new TCP();
const ret = t.bind('127.0.0.2', exports.PORT);
t.close();
return ret === 0;
};
Expand Down Expand Up @@ -466,7 +467,7 @@ ArrayStream.prototype.write = function() {};
exports.nodeProcessAborted = function nodeProcessAborted(exitCode, signal) {
// Depending on the compiler used, node will exit with either
// exit code 132 (SIGILL), 133 (SIGTRAP) or 134 (SIGABRT).
var expectedExitCodes = [132, 133, 134];
let expectedExitCodes = [132, 133, 134];

// On platforms using KSH as the default shell (like SmartOS),
// when a process aborts, KSH exits with an exit code that is
Expand Down Expand Up @@ -495,8 +496,8 @@ exports.nodeProcessAborted = function nodeProcessAborted(exitCode, signal) {
};

exports.busyLoop = function busyLoop(time) {
var startTime = Timer.now();
var stopTime = startTime + time;
const startTime = Timer.now();
const stopTime = startTime + time;
while (Timer.now() < stopTime) {}
};

Expand Down

0 comments on commit f97a5e1

Please sign in to comment.