Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: convert var->const/let in tests #10685

Merged
merged 2 commits into from
Jan 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
10 changes: 8 additions & 2 deletions test/.eslintrc
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
## Test-specific linter rules

rules:
## common module is mandatory in tests
required-modules: [2, common]
# ECMAScript 6
# http://eslint.org/docs/rules/#ecmascript-6
no-var: 2
prefer-const: 2

# Custom rules in tools/eslint-rules
prefer-assert-iferror: 2
prefer-assert-methods: 2
## common module is mandatory in tests
required-modules: [2, common]
4 changes: 2 additions & 2 deletions test/addons/buffer-free-callback/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ const common = require('../../common');
const binding = require(`./build/${common.buildType}/binding`);

function check(size, alignment, offset) {
var buf = binding.alloc(size, alignment, offset);
var slice = buf.slice(size >>> 1);
let buf = binding.alloc(size, alignment, offset);
let slice = buf.slice(size >>> 1);

buf = null;
binding.check(slice);
Expand Down
6 changes: 3 additions & 3 deletions test/addons/load-long-path/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ common.refreshTmpDir();
// make a path that is more than 260 chars long.
// Any given folder cannot have a name longer than 260 characters,
// so create 10 nested folders each with 30 character long names.
var addonDestinationDir = path.resolve(common.tmpDir);
let addonDestinationDir = path.resolve(common.tmpDir);

for (var i = 0; i < 10; i++) {
for (let i = 0; i < 10; i++) {
addonDestinationDir = path.join(addonDestinationDir, 'x'.repeat(30));
fs.mkdirSync(addonDestinationDir);
}
Expand All @@ -28,7 +28,7 @@ const addonPath = path.join(__dirname,
const addonDestinationPath = path.join(addonDestinationDir, 'binding.node');

// Copy binary to long path destination
var contents = fs.readFileSync(addonPath);
const contents = fs.readFileSync(addonPath);
fs.writeFileSync(addonDestinationPath, contents);

// Attempt to load at long path destination
Expand Down
2 changes: 1 addition & 1 deletion test/addons/make-callback-recurse/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ assert.throws(function() {
results.push(2);

setImmediate(common.mustCall(function() {
for (var i = 0; i < results.length; i++) {
for (let i = 0; i < results.length; i++) {
assert.strictEqual(results[i], i,
`verifyExecutionOrder(${arg}) results: ${results}`);
}
Expand Down
14 changes: 7 additions & 7 deletions test/addons/repl-domain-abort/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,27 @@ const assert = require('assert');
const repl = require('repl');
const stream = require('stream');
const path = require('path');
var buildType = process.config.target_defaults.default_configuration;
var buildPath = path.join(__dirname, 'build', buildType, 'binding');
const buildType = process.config.target_defaults.default_configuration;
let buildPath = path.join(__dirname, 'build', buildType, 'binding');
// On Windows, escape backslashes in the path before passing it to REPL.
if (common.isWindows)
buildPath = buildPath.replace(/\\/g, '/');
var cb_ran = false;
let cb_ran = false;

process.on('exit', function() {
assert(cb_ran);
console.log('ok');
});

var lines = [
const lines = [
// This line shouldn't cause an assertion error.
'require(\'' + buildPath + '\')' +
// Log output to double check callback ran.
'.method(function() { console.log(\'cb_ran\'); });',
];

var dInput = new stream.Readable();
var dOutput = new stream.Writable();
const dInput = new stream.Readable();
const dOutput = new stream.Writable();

dInput._read = function _read(size) {
while (lines.length > 0 && this.push(lines.shift()));
Expand All @@ -38,7 +38,7 @@ dOutput._write = function _write(chunk, encoding, cb) {
cb();
};

var options = {
const options = {
input: dInput,
output: dOutput,
terminal: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ if (!common.enoughTestMem) {
return;
}

let buf;
try {
var buf = Buffer.allocUnsafe(kStringMaxLength);
buf = Buffer.allocUnsafe(kStringMaxLength);
} catch (e) {
// If the exception is not due to memory confinement then rethrow it.
if (e.message !== 'Array buffer allocation failed') throw (e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ if (!common.enoughTestMem) {
// v8::String::kMaxLength defined in v8.h
const kStringMaxLength = process.binding('buffer').kStringMaxLength;

let buf;
try {
var buf = Buffer.allocUnsafe(kStringMaxLength + 1);
buf = Buffer.allocUnsafe(kStringMaxLength + 1);
} catch (e) {
// If the exception is not due to memory confinement then rethrow it.
if (e.message !== 'Array buffer allocation failed') throw (e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ if (!common.enoughTestMem) {
// v8::String::kMaxLength defined in v8.h
const kStringMaxLength = process.binding('buffer').kStringMaxLength;

let buf;
try {
var buf = Buffer.allocUnsafe(kStringMaxLength + 1);
buf = Buffer.allocUnsafe(kStringMaxLength + 1);
} catch (e) {
// If the exception is not due to memory confinement then rethrow it.
if (e.message !== 'Array buffer allocation failed') throw (e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ if (!common.enoughTestMem) {
// v8::String::kMaxLength defined in v8.h
const kStringMaxLength = process.binding('buffer').kStringMaxLength;

let buf;
try {
var buf = Buffer.allocUnsafe(kStringMaxLength + 1);
buf = Buffer.allocUnsafe(kStringMaxLength + 1);
} catch (e) {
// If the exception is not due to memory confinement then rethrow it.
if (e.message !== 'Array buffer allocation failed') throw (e);
Expand All @@ -33,7 +34,7 @@ assert.throws(function() {
buf.toString('latin1');
}, /"toString\(\)" failed/);

var maxString = buf.toString('latin1', 1);
let maxString = buf.toString('latin1', 1);
assert.strictEqual(maxString.length, kStringMaxLength);
// Free the memory early instead of at the end of the next assignment
maxString = undefined;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ if (!common.enoughTestMem) {
// v8::String::kMaxLength defined in v8.h
const kStringMaxLength = process.binding('buffer').kStringMaxLength;

let buf;
try {
var buf = Buffer.allocUnsafe(kStringMaxLength + 1);
buf = Buffer.allocUnsafe(kStringMaxLength + 1);
} catch (e) {
// If the exception is not due to memory confinement then rethrow it.
if (e.message !== 'Array buffer allocation failed') throw (e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ if (!common.enoughTestMem) {
// v8::String::kMaxLength defined in v8.h
const kStringMaxLength = process.binding('buffer').kStringMaxLength;

let buf;
try {
var buf = Buffer.allocUnsafe(kStringMaxLength + 1);
buf = Buffer.allocUnsafe(kStringMaxLength + 1);
} catch (e) {
// If the exception is not due to memory confinement then rethrow it.
if (e.message !== 'Array buffer allocation failed') throw (e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ if (!common.enoughTestMem) {
// v8::String::kMaxLength defined in v8.h
const kStringMaxLength = process.binding('buffer').kStringMaxLength;

let buf;
try {
var buf = Buffer.allocUnsafe(kStringMaxLength + 2);
buf = Buffer.allocUnsafe(kStringMaxLength + 2);
} catch (e) {
// If the exception is not due to memory confinement then rethrow it.
if (e.message !== 'Array buffer allocation failed') throw (e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ if (!common.enoughTestMem) {
// v8::String::kMaxLength defined in v8.h
const kStringMaxLength = process.binding('buffer').kStringMaxLength;

let buf;
try {
var buf = Buffer.allocUnsafe(kStringMaxLength * 2 + 2);
buf = Buffer.allocUnsafe(kStringMaxLength * 2 + 2);
} catch (e) {
// If the exception is not due to memory confinement then rethrow it.
if (e.message !== 'Array buffer allocation failed') throw (e);
Expand Down
2 changes: 1 addition & 1 deletion test/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ exports.hasIPv6 = Object.keys(ifaces).some(function(name) {
* the process aborts.
*/
exports.childShouldThrowAndAbort = function() {
var testCmd = '';
let testCmd = '';
if (!exports.isWindows) {
// Do not create core files, as it can take a lot of disk space on
// continuous testing and developers' machines
Expand Down
28 changes: 14 additions & 14 deletions test/debugger/helper-debugger-repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ const assert = require('assert');
const spawn = require('child_process').spawn;

process.env.NODE_DEBUGGER_TIMEOUT = 2000;
var port = common.PORT;
const port = common.PORT;

var child;
var buffer = '';
var expected = [];
var quit;
let child;
let buffer = '';
const expected = [];
let quit;

function startDebugger(scriptToDebug) {
scriptToDebug = process.env.NODE_DEBUGGER_TEST_SCRIPT ||
Expand All @@ -34,23 +34,23 @@ function startDebugger(scriptToDebug) {
console.log(line);
assert.ok(expected.length > 0, 'Got unexpected line: ' + line);

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

if (expected[0].lines.length === 0) {
var callback = expected[0].callback;
const callback = expected[0].callback;
expected.shift();
callback && callback();
}
});

var childClosed = false;
let childClosed = false;
child.on('close', function(code) {
assert(!code);
childClosed = true;
});

var quitCalled = false;
let quitCalled = false;
quit = function() {
if (quitCalled || childClosed) return;
quitCalled = true;
Expand All @@ -60,7 +60,7 @@ function startDebugger(scriptToDebug) {

setTimeout(function() {
console.error('dying badly buffer=%j', buffer);
var err = 'Timeout';
let err = 'Timeout';
if (expected.length > 0 && expected[0].lines) {
err = err + '. Expected: ' + expected[0].lines.shift();
}
Expand Down Expand Up @@ -95,7 +95,7 @@ function addTest(input, output) {
child.stdin.write(expected[0].input + '\n');

if (!expected[0].lines) {
var callback = expected[0].callback;
const callback = expected[0].callback;
expected.shift();

callback && callback();
Expand All @@ -107,17 +107,17 @@ function addTest(input, output) {
expected.push({input: input, lines: output, callback: next});
}

var handshakeLines = [
const handshakeLines = [
/listening on /,
/connecting.* ok/
];

var initialBreakLines = [
const initialBreakLines = [
/break in .*:1/,
/1/, /2/, /3/
];

var initialLines = handshakeLines.concat(initialBreakLines);
const initialLines = handshakeLines.concat(initialBreakLines);

// Process initial lines
addTest(null, initialLines);
Expand Down
4 changes: 2 additions & 2 deletions test/debugger/test-debugger-repl-restart.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ require('../common');
const repl = require('./helper-debugger-repl.js');

repl.startDebugger('breakpoints.js');
var linesWithBreakpoint = [
const linesWithBreakpoint = [
/1/, /2/, /3/, /4/, /5/, /\* 6/
];
// We slice here, because addTest will change the given array.
repl.addTest('sb(6)', linesWithBreakpoint.slice());

var initialLines = repl.initialLines.slice();
const initialLines = repl.initialLines.slice();
initialLines.splice(2, 0, /Restoring/, /Warning/);

// Restart the debugged script
Expand Down
2 changes: 1 addition & 1 deletion test/debugger/test-debugger-repl-term.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const repl = require('./helper-debugger-repl.js');

repl.startDebugger('breakpoints.js');

var addTest = repl.addTest;
const addTest = repl.addTest;

// next
addTest('n', [
Expand Down
2 changes: 1 addition & 1 deletion test/debugger/test-debugger-repl-utf8.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';
const common = require('../common');
var 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');
2 changes: 1 addition & 1 deletion test/debugger/test-debugger-repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const repl = require('./helper-debugger-repl.js');

repl.startDebugger('breakpoints.js');

var addTest = repl.addTest;
const addTest = repl.addTest;

// Next
addTest('n', [
Expand Down
8 changes: 4 additions & 4 deletions test/gc/test-http-client-connaborted.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ let countGC = 0;

console.log('We should do ' + todo + ' requests');

var server = http.createServer(serverHandler);
const server = http.createServer(serverHandler);
server.listen(0, getall);

function getall() {
Expand All @@ -31,7 +31,7 @@ function getall() {
statusLater();
}

var req = http.get({
const req = http.get({
hostname: 'localhost',
pathname: '/',
port: server.address().port
Expand All @@ -44,14 +44,14 @@ function getall() {
setImmediate(getall);
}

for (var i = 0; i < 10; i++)
for (let i = 0; i < 10; i++)
getall();

function afterGC() {
countGC++;
}

var timer;
let timer;
function statusLater() {
global.gc();
if (timer) clearTimeout(timer);
Expand Down
Loading