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

v4.x backport - test: convert var->const/let in tests #11773

Closed
wants to merge 2 commits into from
Closed
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
  •  
  •  
  •  
5 changes: 5 additions & 0 deletions test/.eslintrc.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
## Test-specific linter rules

rules:
# ECMAScript 6
# http://eslint.org/docs/rules/#ecmascript-6
no-var: 2
prefer-const: 2

## common module is mandatory in tests
required-modules: [2, "common"]

Expand Down
2 changes: 1 addition & 1 deletion test/addons/async-hello-world/test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';
const common = require('../../common');
var assert = require('assert');
const assert = require('assert');
const binding = require(`./build/${common.buildType}/binding`);

binding(5, common.mustCall(function(err, val) {
Expand Down
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) {
var buf = binding.alloc(size);
var slice = buf.slice(size >>> 1);
let buf = binding.alloc(size);
let slice = buf.slice(size >>> 1);

buf = null;
binding.check(slice);
Expand Down
2 changes: 1 addition & 1 deletion test/addons/hello-world-function-export/test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';
const common = require('../../common');
var assert = require('assert');
const assert = require('assert');
const binding = require(`./build/${common.buildType}/binding`);
assert.equal('world', binding());
console.log('binding.hello() =', binding());
2 changes: 1 addition & 1 deletion test/addons/hello-world/test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';
const common = require('../../common');
var assert = require('assert');
const assert = require('assert');
const binding = require(`./build/${common.buildType}/binding`);
assert.equal('world', binding.hello());
console.log('binding.hello() =', binding.hello());
8 changes: 4 additions & 4 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,10 +28,10 @@ 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
var addon = require(addonDestinationPath);
const addon = require(addonDestinationPath);
assert(addon != null);
assert(addon.hello() == 'world');
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_arr.push(2);

setImmediate(common.mustCall(function() {
for (var i = 0; i < results_arr.length; i++) {
for (let i = 0; i < results_arr.length; i++) {
assert.equal(results_arr[i],
i,
`verifyExecutionOrder(${arg}) results: ${results_arr}`);
Expand Down
24 changes: 12 additions & 12 deletions test/addons/repl-domain-abort/test.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
'use strict';
var common = require('../../common');
var assert = require('assert');
var repl = require('repl');
var stream = require('stream');
var path = require('path');
var buildType = process.config.target_defaults.default_configuration;
var buildPath = path.join(__dirname, 'build', buildType, 'binding');
const common = require('../../common');
const assert = require('assert');
const repl = require('repl');
const stream = require('stream');
const path = require('path');
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 = new Buffer(kStringMaxLength);
buf = new Buffer(kStringMaxLength);
} catch (e) {
// If the exception is not due to memory confinement then rethrow it.
if (e.message !== 'Invalid array buffer length') 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 = new Buffer(kStringMaxLength + 1);
buf = new Buffer(kStringMaxLength + 1);
} catch (e) {
// If the exception is not due to memory confinement then rethrow it.
if (e.message !== 'Invalid array buffer length') 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 = new Buffer(kStringMaxLength + 1);
buf = new Buffer(kStringMaxLength + 1);
} catch (e) {
// If the exception is not due to memory confinement then rethrow it.
if (e.message !== 'Invalid array buffer length') 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 = new Buffer(kStringMaxLength + 1);
buf = new Buffer(kStringMaxLength + 1);
} catch (e) {
// If the exception is not due to memory confinement then rethrow it.
if (e.message !== 'Invalid array buffer length') throw (e);
Expand All @@ -33,7 +34,7 @@ assert.throws(function() {
buf.toString('binary');
}, /toString failed/);

var maxString = buf.toString('binary', 1);
let maxString = buf.toString('binary', 1);
assert.equal(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 = new Buffer(kStringMaxLength + 1);
buf = new Buffer(kStringMaxLength + 1);
} catch (e) {
// If the exception is not due to memory confinement then rethrow it.
if (e.message !== 'Invalid array buffer length') 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 = new Buffer(kStringMaxLength + 1);
buf = new Buffer(kStringMaxLength + 1);
} catch (e) {
// If the exception is not due to memory confinement then rethrow it.
if (e.message !== 'Invalid array buffer length') 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 = new Buffer(kStringMaxLength + 2);
buf = new Buffer(kStringMaxLength + 2);
} catch (e) {
// If the exception is not due to memory confinement then rethrow it.
if (e.message !== 'Invalid array buffer length') 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 = new Buffer(kStringMaxLength * 2 + 2);
buf = new Buffer(kStringMaxLength * 2 + 2);
} catch (e) {
// If the exception is not due to memory confinement then rethrow it.
if (e.message !== 'Invalid array buffer length') throw (e);
Expand Down
Loading