From e61a1003617e3a1e8771ad0ef00d08ca294b1fae Mon Sep 17 00:00:00 2001 From: Hitesh Kanwathirtha Date: Fri, 10 Mar 2017 15:34:39 -0800 Subject: [PATCH] napi, test: Fix eslint errors (#139) Fixes eslint errors in the test js files Generally trivial mechanical transformation --- test/addons-abi/1_hello_world/test.js | 8 +-- test/addons-abi/2_function_arguments/test.js | 8 +-- test/addons-abi/3_callbacks/test.js | 18 +++--- test/addons-abi/4_object_factory/test.js | 12 ++-- test/addons-abi/5_function_factory/test.js | 10 ++-- test/addons-abi/6_object_wrap/test.js | 28 ++++----- test/addons-abi/7_factory_wrap/test.js | 22 +++---- test/addons-abi/8_passing_wrapped/test.js | 14 ++--- test/addons-abi/test_array/test.js | 18 +++--- test/addons-abi/test_buffer/test.js | 33 ++++++----- test/addons-abi/test_constructor/test.js | 18 +++--- test/addons-abi/test_exception/test.js | 61 ++++++++++---------- test/addons-abi/test_function/test.js | 15 ++--- test/addons-abi/test_instanceof/test.js | 40 ++++++++----- test/addons-abi/test_number/test.js | 54 ++++++++--------- test/addons-abi/test_object/test.js | 19 +++--- test/addons-abi/test_properties/test.js | 16 ++--- test/addons-abi/test_string/test.js | 38 ++++++------ test/addons-abi/test_symbol/test1.js | 22 +++---- test/addons-abi/test_symbol/test2.js | 12 ++-- test/addons-abi/test_symbol/test3.js | 22 +++---- test/addons-abi/test_typedarray/test.js | 44 +++++++------- 22 files changed, 275 insertions(+), 257 deletions(-) diff --git a/test/addons-abi/1_hello_world/test.js b/test/addons-abi/1_hello_world/test.js index d349dcfbd9a803..c975c48a733f5c 100644 --- a/test/addons-abi/1_hello_world/test.js +++ b/test/addons-abi/1_hello_world/test.js @@ -1,6 +1,6 @@ 'use strict'; -var common = require('../../common'); -var assert = require('assert'); -var addon = require(`./build/${common.buildType}/binding`); +const common = require('../../common'); +const assert = require('assert'); +const addon = require(`./build/${common.buildType}/binding`); -assert.equal(addon.hello(), 'world'); +assert.strictEqual(addon.hello(), 'world'); diff --git a/test/addons-abi/2_function_arguments/test.js b/test/addons-abi/2_function_arguments/test.js index dcdb365bcc0bc9..e70f76b718bd10 100644 --- a/test/addons-abi/2_function_arguments/test.js +++ b/test/addons-abi/2_function_arguments/test.js @@ -1,6 +1,6 @@ 'use strict'; -var common = require('../../common'); -var assert = require('assert'); -var addon = require(`./build/${common.buildType}/binding`); +const common = require('../../common'); +const assert = require('assert'); +const addon = require(`./build/${common.buildType}/binding`); -assert.equal(addon.add(3, 5), 8); +assert.strictEqual(addon.add(3, 5), 8); diff --git a/test/addons-abi/3_callbacks/test.js b/test/addons-abi/3_callbacks/test.js index 4e8f0854136ebb..e7dca7cbd9b907 100644 --- a/test/addons-abi/3_callbacks/test.js +++ b/test/addons-abi/3_callbacks/test.js @@ -1,18 +1,20 @@ 'use strict'; -var common = require('../../common'); -var assert = require('assert'); -var addon = require(`./build/${common.buildType}/binding`); +const common = require('../../common'); +const assert = require('assert'); +const addon = require(`./build/${common.buildType}/binding`); addon.RunCallback(function(msg) { - assert.equal(msg, 'hello world'); + assert.strictEqual(msg, 'hello world'); }); -var global = ( function() { return this; } ).apply(); +const global = function() { return this; }.apply(); function testRecv(desiredRecv) { addon.RunCallbackWithRecv(function() { - assert.equal(this, - ( desiredRecv === undefined || desiredRecv === null ) ? global : desiredRecv ); + assert.strictEqual(this, + (desiredRecv === undefined || + desiredRecv === null) ? + global : desiredRecv); }, desiredRecv); } @@ -20,6 +22,6 @@ testRecv(undefined); testRecv(null); testRecv(5); testRecv(true); -testRecv("Hello"); +testRecv('Hello'); testRecv([]); testRecv({}); diff --git a/test/addons-abi/4_object_factory/test.js b/test/addons-abi/4_object_factory/test.js index 5581dd12ce596b..db666ff7c9122a 100644 --- a/test/addons-abi/4_object_factory/test.js +++ b/test/addons-abi/4_object_factory/test.js @@ -1,8 +1,8 @@ 'use strict'; -var common = require('../../common'); -var assert = require('assert'); -var addon = require(`./build/${common.buildType}/binding`); +const common = require('../../common'); +const assert = require('assert'); +const addon = require(`./build/${common.buildType}/binding`); -var obj1 = addon('hello'); -var obj2 = addon('world'); -assert.equal(obj1.msg + ' ' + obj2.msg, 'hello world'); +const obj1 = addon('hello'); +const obj2 = addon('world'); +assert.strictEqual(obj1.msg + ' ' + obj2.msg, 'hello world'); diff --git a/test/addons-abi/5_function_factory/test.js b/test/addons-abi/5_function_factory/test.js index 954bc0ce020db4..7521824e1e000a 100644 --- a/test/addons-abi/5_function_factory/test.js +++ b/test/addons-abi/5_function_factory/test.js @@ -1,7 +1,7 @@ 'use strict'; -var common = require('../../common'); -var assert = require('assert'); -var addon = require(`./build/${common.buildType}/binding`); +const common = require('../../common'); +const assert = require('assert'); +const addon = require(`./build/${common.buildType}/binding`); -var fn = addon(); -assert.equal(fn(), 'hello world'); // 'hello world' +const fn = addon(); +assert.strictEqual(fn(), 'hello world'); // 'hello world' diff --git a/test/addons-abi/6_object_wrap/test.js b/test/addons-abi/6_object_wrap/test.js index 210fa909d9a32f..4d89da6a4350bd 100644 --- a/test/addons-abi/6_object_wrap/test.js +++ b/test/addons-abi/6_object_wrap/test.js @@ -1,19 +1,19 @@ 'use strict'; -var common = require('../../common'); -var assert = require('assert'); -var addon = require(`./build/${common.buildType}/binding`); +const common = require('../../common'); +const assert = require('assert'); +const addon = require(`./build/${common.buildType}/binding`); -var obj = new addon.MyObject(9); -assert.equal(obj.value, 9); +const obj = new addon.MyObject(9); +assert.strictEqual(obj.value, 9); obj.value = 10; -assert.equal(obj.value, 10); -assert.equal(obj.plusOne(), 11); -assert.equal(obj.plusOne(), 12); -assert.equal(obj.plusOne(), 13); +assert.strictEqual(obj.value, 10); +assert.strictEqual(obj.plusOne(), 11); +assert.strictEqual(obj.plusOne(), 12); +assert.strictEqual(obj.plusOne(), 13); -assert.equal(obj.multiply().value, 13); -assert.equal(obj.multiply(10).value, 130); +assert.strictEqual(obj.multiply().value, 13); +assert.strictEqual(obj.multiply(10).value, 130); -var newobj = obj.multiply(-1); -assert.equal(newobj.value, -13); -assert(obj !== newobj); +const newobj = obj.multiply(-1); +assert.strictEqual(newobj.value, -13); +assert.notStrictEqual(obj, newobj); diff --git a/test/addons-abi/7_factory_wrap/test.js b/test/addons-abi/7_factory_wrap/test.js index e69b03ce9a4fbe..20108e14b629bc 100644 --- a/test/addons-abi/7_factory_wrap/test.js +++ b/test/addons-abi/7_factory_wrap/test.js @@ -1,14 +1,14 @@ 'use strict'; -var common = require('../../common'); -var assert = require('assert'); -var createObject = require(`./build/${common.buildType}/binding`); +const common = require('../../common'); +const assert = require('assert'); +const createObject = require(`./build/${common.buildType}/binding`); -var obj = createObject(10); -assert.equal(obj.plusOne(), 11); -assert.equal(obj.plusOne(), 12); -assert.equal(obj.plusOne(), 13); +const obj = createObject(10); +assert.strictEqual(obj.plusOne(), 11); +assert.strictEqual(obj.plusOne(), 12); +assert.strictEqual(obj.plusOne(), 13); -var obj2 = createObject(20); -assert.equal(obj2.plusOne(), 21); -assert.equal(obj2.plusOne(), 22); -assert.equal(obj2.plusOne(), 23); +const obj2 = createObject(20); +assert.strictEqual(obj2.plusOne(), 21); +assert.strictEqual(obj2.plusOne(), 22); +assert.strictEqual(obj2.plusOne(), 23); diff --git a/test/addons-abi/8_passing_wrapped/test.js b/test/addons-abi/8_passing_wrapped/test.js index ee42f501825178..3d24fa5d9fdaa7 100644 --- a/test/addons-abi/8_passing_wrapped/test.js +++ b/test/addons-abi/8_passing_wrapped/test.js @@ -1,9 +1,9 @@ 'use strict'; -var common = require('../../common'); -var assert = require('assert'); -var addon = require(`./build/${common.buildType}/binding`); +const common = require('../../common'); +const assert = require('assert'); +const addon = require(`./build/${common.buildType}/binding`); -var obj1 = addon.createObject(10); -var obj2 = addon.createObject(20); -var result = addon.add(obj1, obj2); -assert.equal(result, 30); +const obj1 = addon.createObject(10); +const obj2 = addon.createObject(20); +const result = addon.add(obj1, obj2); +assert.strictEqual(result, 30); diff --git a/test/addons-abi/test_array/test.js b/test/addons-abi/test_array/test.js index 7168786993d763..14e6f2895c0807 100644 --- a/test/addons-abi/test_array/test.js +++ b/test/addons-abi/test_array/test.js @@ -1,11 +1,11 @@ 'use strict'; -var common = require('../../common'); -var assert = require('assert'); +const common = require('../../common'); +const assert = require('assert'); // Testing api calls for arrays -var test_array = require(`./build/${common.buildType}/test_array`); +const test_array = require(`./build/${common.buildType}/test_array`); -var array = [ +const array = [ 1, 9, 48, @@ -19,17 +19,17 @@ var array = [ ] ]; -assert.equal(test_array.Test(array, array.length + 1), 'Index out of bound!'); +assert.strictEqual(test_array.Test(array, array.length + 1), + 'Index out of bound!'); try { test_array.Test(array, -2); -} -catch (err) { - assert.equal(err.message, 'Invalid index. Expects a positive integer.'); +} catch (err) { + assert.strictEqual(err.message, 'Invalid index. Expects a positive integer.'); } array.forEach(function(element, index) { - assert.equal(test_array.Test(array, index), element); + assert.strictEqual(test_array.Test(array, index), element); }); diff --git a/test/addons-abi/test_buffer/test.js b/test/addons-abi/test_buffer/test.js index 775694f2fb1cd8..6fb80b02053f9f 100644 --- a/test/addons-abi/test_buffer/test.js +++ b/test/addons-abi/test_buffer/test.js @@ -1,24 +1,25 @@ 'use strict'; // Flags: --expose-gc -var common = require('../../common'); -var binding = require(`./build/${common.buildType}/test_buffer`); -var assert = require( "assert" ); +const common = require('../../common'); +const binding = require(`./build/${common.buildType}/test_buffer`); +const assert = require('assert'); -assert( binding.newBuffer().toString() === binding.theText, - "buffer returned by newBuffer() has wrong contents" ); -assert( binding.newExternalBuffer().toString() === binding.theText, - "buffer returned by newExternalBuffer() has wrong contents" ); -console.log( "gc1" ); +assert.strictEqual(binding.newBuffer().toString(), binding.theText, + 'buffer returned by newBuffer() has wrong contents'); +assert.strictEqual(binding.newExternalBuffer().toString(), binding.theText, + 'buffer returned by newExternalBuffer() has wrong contents'); +console.log('gc1'); global.gc(); -assert( binding.getDeleterCallCount(), 1, "deleter was not called" ); -assert( binding.copyBuffer().toString() === binding.theText, - "buffer returned by copyBuffer() has wrong contents" ); +assert.strictEqual(binding.getDeleterCallCount(), 1, 'deleter was not called'); +assert.strictEqual(binding.copyBuffer().toString(), binding.theText, + 'buffer returned by copyBuffer() has wrong contents'); -var buffer = binding.staticBuffer(); -assert( binding.bufferHasInstance( buffer ), true, "buffer type checking fails" ); -assert( binding.bufferInfo( buffer ), true, "buffer data is accurate" ); +let buffer = binding.staticBuffer(); +assert.strictEqual(binding.bufferHasInstance(buffer), true, + 'buffer type checking fails'); +assert.strictEqual(binding.bufferInfo(buffer), true, 'buffer data is accurate'); buffer = null; global.gc(); -console.log( "gc2" ); -assert( binding.getDeleterCallCount(), 2, "deleter was not called" ); +console.log('gc2'); +assert.strictEqual(binding.getDeleterCallCount(), 2, 'deleter was not called'); diff --git a/test/addons-abi/test_constructor/test.js b/test/addons-abi/test_constructor/test.js index 25733573a96e74..9feae5a1360b2c 100644 --- a/test/addons-abi/test_constructor/test.js +++ b/test/addons-abi/test_constructor/test.js @@ -1,25 +1,25 @@ 'use strict'; -var common = require('../../common'); -var assert = require('assert'); +const common = require('../../common'); +const assert = require('assert'); // Testing api calls for a constructor that defines properties -var TestConstructor = require(`./build/${common.buildType}/test_constructor`); -var test_object = new TestConstructor(); +const TestConstructor = require(`./build/${common.buildType}/test_constructor`); +const test_object = new TestConstructor(); -assert.equal(test_object.echo('hello'), 'hello'); +assert.strictEqual(test_object.echo('hello'), 'hello'); test_object.readwriteValue = 1; -assert.equal(test_object.readwriteValue, 1); +assert.strictEqual(test_object.readwriteValue, 1); test_object.readwriteValue = 2; -assert.equal(test_object.readwriteValue, 2); +assert.strictEqual(test_object.readwriteValue, 2); assert.throws(() => { test_object.readonlyValue = 3; }); assert.ok(test_object.hiddenValue); // All properties except 'hiddenValue' should be enumerable. -var propertyNames = []; -for (var name in test_object) { +const propertyNames = []; +for (const name in test_object) { propertyNames.push(name); } assert.ok(propertyNames.indexOf('echo') >= 0); diff --git a/test/addons-abi/test_exception/test.js b/test/addons-abi/test_exception/test.js index 02ebabd6961650..f8fc05c71f1c42 100644 --- a/test/addons-abi/test_exception/test.js +++ b/test/addons-abi/test_exception/test.js @@ -1,49 +1,52 @@ 'use strict'; -var common = require('../../common'); -var test_exception = require(`./build/${common.buildType}/test_exception`); -var assert = require( "assert" ); -var theError = new Error( "Some error" ); -var throwTheError = function() { - throw theError; +const common = require('../../common'); +const test_exception = require(`./build/${common.buildType}/test_exception`); +const assert = require('assert'); +const theError = new Error('Some error'); +const throwTheError = function() { + throw theError; }; -var caughtError; +let caughtError; -var throwNoError = function() {}; +const throwNoError = function() {}; // Test that the native side successfully captures the exception -var returnedError = test_exception.returnException( throwTheError ); -assert.strictEqual( theError, returnedError, - "Returned error is strictly equal to the thrown error" ); +let returnedError = test_exception.returnException(throwTheError); +assert.strictEqual(theError, returnedError, + 'Returned error is strictly equal to the thrown error'); // Test that the native side passes the exception through try { - test_exception.allowException( throwTheError ); -} catch ( anError ) { - caughtError = anError; + test_exception.allowException(throwTheError); +} catch (anError) { + caughtError = anError; } -assert.strictEqual( caughtError, theError, - "Thrown exception was allowed to pass through unhindered" ); +assert.strictEqual(caughtError, theError, + 'Thrown exception was allowed to pass through unhindered'); caughtError = undefined; -// Test that the exception thrown above was marked as pending before it was handled on the JS side -assert.strictEqual( test_exception.wasPending(), true, - "VM was marked as having an exception pending when it was allowed through" ); +// Test that the exception thrown above was marked as pending +// before it was handled on the JS side +assert.strictEqual(test_exception.wasPending(), true, + 'VM was marked as having an exception pending' + + ' when it was allowed through'); // Test that the native side does not capture a non-existing exception -returnedError = test_exception.returnException( throwNoError ); -assert.strictEqual( undefined, returnedError, - "Returned error is undefined when no exception is thrown" ); +returnedError = test_exception.returnException(throwNoError); +assert.strictEqual(undefined, returnedError, + 'Returned error is undefined when no exception is thrown'); // Test that no exception appears that was not thrown by us try { - test_exception.allowException( throwNoError ); -} catch( anError ) { - caughtError = anError; + test_exception.allowException(throwNoError); +} catch (anError) { + caughtError = anError; } -assert.strictEqual( undefined, caughtError, - "No exception originated on the native side" ); +assert.strictEqual(undefined, caughtError, + 'No exception originated on the native side'); // Test that the exception state remains clear when no exception is thrown -assert.strictEqual( test_exception.wasPending(), false, - "VM was not marked as having an exception pending when none was allowed through" ); +assert.strictEqual(test_exception.wasPending(), false, + 'VM was not marked as having an exception pending' + + ' when none was allowed through'); diff --git a/test/addons-abi/test_function/test.js b/test/addons-abi/test_function/test.js index 7351519a205d1c..bdb9133adf9346 100644 --- a/test/addons-abi/test_function/test.js +++ b/test/addons-abi/test_function/test.js @@ -1,27 +1,28 @@ 'use strict'; -var common = require('../../common'); -var assert = require('assert'); +const common = require('../../common'); +const assert = require('assert'); // testing api calls for function -var test_function = require(`./build/${common.buildType}/test_function`); +const test_function = require(`./build/${common.buildType}/test_function`); function func1() { return 1; } -assert.equal(test_function.Test(func1), 1); +assert.strictEqual(test_function.Test(func1), 1); function func2() { console.log('hello world!'); + return null; } -assert.equal(test_function.Test(func2), null); +assert.strictEqual(test_function.Test(func2), null); function func3(input) { return input + 1; } -assert.equal(test_function.Test(func3, 1), 2); +assert.strictEqual(test_function.Test(func3, 1), 2); function func4(input) { return func3(input); } -assert.equal(test_function.Test(func4, 1), 2); +assert.strictEqual(test_function.Test(func4, 1), 2); diff --git a/test/addons-abi/test_instanceof/test.js b/test/addons-abi/test_instanceof/test.js index 1a9b126a7fb71c..9500d864dd8df6 100644 --- a/test/addons-abi/test_instanceof/test.js +++ b/test/addons-abi/test_instanceof/test.js @@ -1,37 +1,49 @@ -var fs = require( 'fs' ); +'use strict'; +const fs = require('fs'); -var common = require('../../common'); -var assert = require('assert'); -var addon = require(`./build/${common.buildType}/test_instanceof`); -var path = require( 'path' ); +const common = require('../../common'); +const assert = require('assert'); +// addon is referenced through the eval expression in testFile +// eslint-disable-next-line no-unused-vars +const addon = require(`./build/${common.buildType}/test_instanceof`); +const path = require('path'); + +// The following assert functions are referenced by v8's unit tests +// See for instance deps/v8/test/mjsunit/instanceof.js +// eslint-disable-next-line no-unused-vars function assertTrue(assertion) { return assert.strictEqual(true, assertion); } +// eslint-disable-next-line no-unused-vars function assertFalse(assertion) { assert.strictEqual(false, assertion); } +// eslint-disable-next-line no-unused-vars function assertEquals(leftHandSide, rightHandSide) { - assert.equal(leftHandSide, rightHandSide); + assert.strictEqual(leftHandSide, rightHandSide); } +// eslint-disable-next-line no-unused-vars function assertThrows(statement) { assert.throws(function() { eval(statement); }, Error); } -function testFile( fileName ) { - eval( fs.readFileSync( fileName, { encoding: 'utf8' } ) - .replace( /[(]([^\s(]+)\s+instanceof\s+([^)]+)[)]/g, - '( addon.doInstanceOf( $1, $2 ) )' ) ); +function testFile(fileName) { + const contents = fs.readFileSync(fileName, { encoding: 'utf8' }); + eval(contents.replace(/[(]([^\s(]+)\s+instanceof\s+([^)]+)[)]/g, + '(addon.doInstanceOf($1, $2))')); } testFile( - path.join( path.resolve( __dirname, '..', '..', '..', 'deps', 'v8', 'test', 'mjsunit' ), - 'instanceof.js' ) ); + path.join(path.resolve(__dirname, '..', '..', '..', + 'deps', 'v8', 'test', 'mjsunit'), + 'instanceof.js')); testFile( - path.join( path.resolve( __dirname, '..', '..', '..', 'deps', 'v8', 'test', 'mjsunit' ), - 'instanceof-2.js' ) ); + path.join(path.resolve(__dirname, '..', '..', '..', + 'deps', 'v8', 'test', 'mjsunit'), + 'instanceof-2.js')); diff --git a/test/addons-abi/test_number/test.js b/test/addons-abi/test_number/test.js index 76bff04ce10332..885b9b599d9f25 100644 --- a/test/addons-abi/test_number/test.js +++ b/test/addons-abi/test_number/test.js @@ -1,39 +1,39 @@ 'use strict'; -var common = require('../../common'); -var assert = require('assert'); -var test_number = require(`./build/${common.buildType}/test_number`); +const common = require('../../common'); +const assert = require('assert'); +const test_number = require(`./build/${common.buildType}/test_number`); // testing api calls for number -assert.equal(0, test_number.Test(0)); -assert.equal(1, test_number.Test(1)); -assert.equal(-1, test_number.Test(-1)); -assert.equal(100, test_number.Test(100)); -assert.equal(2121, test_number.Test(2121)); -assert.equal(-1233, test_number.Test(-1233)); -assert.equal(986583, test_number.Test(986583)); -assert.equal(-976675, test_number.Test(-976675)); +assert.strictEqual(0, test_number.Test(0)); +assert.strictEqual(1, test_number.Test(1)); +assert.strictEqual(-1, test_number.Test(-1)); +assert.strictEqual(100, test_number.Test(100)); +assert.strictEqual(2121, test_number.Test(2121)); +assert.strictEqual(-1233, test_number.Test(-1233)); +assert.strictEqual(986583, test_number.Test(986583)); +assert.strictEqual(-976675, test_number.Test(-976675)); -var num1 = 98765432213456789876546896323445679887645323232436587988766545658; -assert.equal(num1, test_number.Test(num1)); +const num1 = 98765432213456789876546896323445679887645323232436587988766545658; +assert.strictEqual(num1, test_number.Test(num1)); -var num2 = -4350987086545760976737453646576078997096876957864353245245769809; -assert.equal(num2, test_number.Test(num2)); +const num2 = -4350987086545760976737453646576078997096876957864353245245769809; +assert.strictEqual(num2, test_number.Test(num2)); -var num3 = Number.MAX_SAFE_INTEGER; -assert.equal(num3, test_number.Test(num3)); +const num3 = Number.MAX_SAFE_INTEGER; +assert.strictEqual(num3, test_number.Test(num3)); -var num4 = Number.MAX_SAFE_INTEGER + 10; -assert.equal(num4, test_number.Test(num4)); +const num4 = Number.MAX_SAFE_INTEGER + 10; +assert.strictEqual(num4, test_number.Test(num4)); -var num5 = Number.MAX_VALUE; -assert.equal(num5, test_number.Test(num5)); +const num5 = Number.MAX_VALUE; +assert.strictEqual(num5, test_number.Test(num5)); -var num6 = Number.MAX_VALUE + 10; -assert.equal(num6, test_number.Test(num6)); +const num6 = Number.MAX_VALUE + 10; +assert.strictEqual(num6, test_number.Test(num6)); -var num7 = Number.POSITIVE_INFINITY; -assert.equal(num7, test_number.Test(num7)); +const num7 = Number.POSITIVE_INFINITY; +assert.strictEqual(num7, test_number.Test(num7)); -var num8 = Number.NEGATIVE_INFINITY; -assert.equal(num8, test_number.Test(num8)); +const num8 = Number.NEGATIVE_INFINITY; +assert.strictEqual(num8, test_number.Test(num8)); diff --git a/test/addons-abi/test_object/test.js b/test/addons-abi/test_object/test.js index 4a40c0961f8ec1..115dece4cb6c7d 100644 --- a/test/addons-abi/test_object/test.js +++ b/test/addons-abi/test_object/test.js @@ -1,12 +1,12 @@ 'use strict'; -var common = require('../../common'); -var assert = require('assert'); +const common = require('../../common'); +const assert = require('assert'); // Testing api calls for objects -var test_object = require(`./build/${common.buildType}/test_object`); +const test_object = require(`./build/${common.buildType}/test_object`); -var object = { +const object = { hello: 'world', array: [ 1, 94, 'str', 12.321, { test: 'obj in arr' } @@ -16,7 +16,7 @@ var object = { } }; -assert.equal(test_object.Get(object, 'hello'), 'world'); +assert.strictEqual(test_object.Get(object, 'hello'), 'world'); assert.deepStrictEqual(test_object.Get(object, 'array'), [ 1, 94, 'str', 12.321, { test: 'obj in arr' } ]); assert.deepStrictEqual(test_object.Get(object, 'newObject'), @@ -26,13 +26,13 @@ assert(test_object.Has(object, 'hello')); assert(test_object.Has(object, 'array')); assert(test_object.Has(object, 'newObject')); -var newObject = test_object.New(); +const newObject = test_object.New(); assert(test_object.Has(newObject, 'test_number')); -assert.equal(newObject.test_number, 987654321); -assert.equal(newObject.test_string, 'test string'); +assert.strictEqual(newObject.test_number, 987654321); +assert.strictEqual(newObject.test_string, 'test string'); // test_object.Inflate increases all properties by 1 -var cube = { +const cube = { x: 10, y: 10, z: 10 @@ -43,4 +43,3 @@ assert.deepStrictEqual(test_object.Inflate(cube), {x: 12, y: 12, z: 12}); assert.deepStrictEqual(test_object.Inflate(cube), {x: 13, y: 13, z: 13}); cube.t = 13; assert.deepStrictEqual(test_object.Inflate(cube), {x: 14, y: 14, z: 14, t: 14}); - diff --git a/test/addons-abi/test_properties/test.js b/test/addons-abi/test_properties/test.js index a32dc7bc321a95..8e19903dcfe6e6 100644 --- a/test/addons-abi/test_properties/test.js +++ b/test/addons-abi/test_properties/test.js @@ -1,24 +1,24 @@ 'use strict'; -var common = require('../../common'); -var assert = require('assert'); +const common = require('../../common'); +const assert = require('assert'); // Testing api calls for defining properties -var test_object = require(`./build/${common.buildType}/test_properties`); +const test_object = require(`./build/${common.buildType}/test_properties`); -assert.equal(test_object.echo('hello'), 'hello'); +assert.strictEqual(test_object.echo('hello'), 'hello'); test_object.readwriteValue = 1; -assert.equal(test_object.readwriteValue, 1); +assert.strictEqual(test_object.readwriteValue, 1); test_object.readwriteValue = 2; -assert.equal(test_object.readwriteValue, 2); +assert.strictEqual(test_object.readwriteValue, 2); assert.throws(() => { test_object.readonlyValue = 3; }); assert.ok(test_object.hiddenValue); // All properties except 'hiddenValue' should be enumerable. -var propertyNames = []; -for (var name in test_object) { +const propertyNames = []; +for (const name in test_object) { propertyNames.push(name); } assert.ok(propertyNames.indexOf('echo') >= 0); diff --git a/test/addons-abi/test_string/test.js b/test/addons-abi/test_string/test.js index b489ad3d3708d1..3c9334a5616523 100644 --- a/test/addons-abi/test_string/test.js +++ b/test/addons-abi/test_string/test.js @@ -1,26 +1,26 @@ 'use strict'; -var common = require('../../common'); -var assert = require('assert'); +const common = require('../../common'); +const assert = require('assert'); // testing api calls for string -var test_string = require(`./build/${common.buildType}/test_string`); +const test_string = require(`./build/${common.buildType}/test_string`); -var str1 = 'hello world'; -assert.equal(test_string.Copy(str1), str1); -assert.equal(test_string.Length(str1), 11); -assert.equal(test_string.Utf8Length(str1), 11); +const str1 = 'hello world'; +assert.strictEqual(test_string.Copy(str1), str1); +assert.strictEqual(test_string.Length(str1), 11); +assert.strictEqual(test_string.Utf8Length(str1), 11); -var str2 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; -assert.equal(test_string.Copy(str2), str2); -assert.equal(test_string.Length(str2), 62); -assert.equal(test_string.Utf8Length(str2), 62); +const str2 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; +assert.strictEqual(test_string.Copy(str2), str2); +assert.strictEqual(test_string.Length(str2), 62); +assert.strictEqual(test_string.Utf8Length(str2), 62); -var str3 = '?!@#$%^&*()_+-=[]{}/.,<>\'\"\\'; -assert.equal(test_string.Copy(str3), str3); -assert.equal(test_string.Length(str3), 27); -assert.equal(test_string.Utf8Length(str3), 27); +const str3 = '?!@#$%^&*()_+-=[]{}/.,<>\'"\\'; +assert.strictEqual(test_string.Copy(str3), str3); +assert.strictEqual(test_string.Length(str3), 27); +assert.strictEqual(test_string.Utf8Length(str3), 27); -var str4 = '\u{2003}\u{2101}\u{2001}'; -assert.equal(test_string.Copy(str4), str4); -assert.equal(test_string.Length(str4), 3); -assert.equal(test_string.Utf8Length(str4), 9); +const str4 = '\u{2003}\u{2101}\u{2001}'; +assert.strictEqual(test_string.Copy(str4), str4); +assert.strictEqual(test_string.Length(str4), 3); +assert.strictEqual(test_string.Utf8Length(str4), 9); diff --git a/test/addons-abi/test_symbol/test1.js b/test/addons-abi/test_symbol/test1.js index 77e26983351001..25eb473c4b1b9d 100644 --- a/test/addons-abi/test_symbol/test1.js +++ b/test/addons-abi/test_symbol/test1.js @@ -1,20 +1,20 @@ 'use strict'; -var common = require('../../common'); -var assert = require('assert'); +const common = require('../../common'); +const assert = require('assert'); // testing api calls for symbol -var test_symbol = require(`./build/${common.buildType}/test_symbol`); +const test_symbol = require(`./build/${common.buildType}/test_symbol`); -var sym = test_symbol.New('test'); -assert.equal(sym.toString(), 'Symbol(test)'); +const sym = test_symbol.New('test'); +assert.strictEqual(sym.toString(), 'Symbol(test)'); -var myObj = {}; -var fooSym = test_symbol.New('foo'); -var otherSym = test_symbol.New('bar'); +const myObj = {}; +const fooSym = test_symbol.New('foo'); +const otherSym = test_symbol.New('bar'); myObj['foo'] = 'bar'; myObj[fooSym] = 'baz'; myObj[otherSym] = 'bing'; -assert(myObj.foo === 'bar'); -assert(myObj[fooSym] === 'baz'); -assert(myObj[otherSym] === 'bing'); +assert.strictEqual(myObj.foo, 'bar'); +assert.strictEqual(myObj[fooSym], 'baz'); +assert.strictEqual(myObj[otherSym], 'bing'); diff --git a/test/addons-abi/test_symbol/test2.js b/test/addons-abi/test_symbol/test2.js index c786584a76b2e2..60512431110a5b 100644 --- a/test/addons-abi/test_symbol/test2.js +++ b/test/addons-abi/test_symbol/test2.js @@ -1,15 +1,15 @@ 'use strict'; -var common = require('../../common'); -var assert = require('assert'); +const common = require('../../common'); +const assert = require('assert'); // testing api calls for symbol -var test_symbol = require(`./build/${common.buildType}/test_symbol`); +const test_symbol = require(`./build/${common.buildType}/test_symbol`); -var fooSym = test_symbol.New('foo'); -var myObj = {}; +const fooSym = test_symbol.New('foo'); +const myObj = {}; myObj['foo'] = 'bar'; myObj[fooSym] = 'baz'; Object.keys(myObj); // -> [ 'foo' ] Object.getOwnPropertyNames(myObj); // -> [ 'foo' ] Object.getOwnPropertySymbols(myObj); // -> [ Symbol(foo) ] -assert(Object.getOwnPropertySymbols(myObj)[0] === fooSym); +assert.strictEqual(Object.getOwnPropertySymbols(myObj)[0], fooSym); diff --git a/test/addons-abi/test_symbol/test3.js b/test/addons-abi/test_symbol/test3.js index de76c0b87cb33f..a7c6c18c025480 100644 --- a/test/addons-abi/test_symbol/test3.js +++ b/test/addons-abi/test_symbol/test3.js @@ -1,19 +1,19 @@ 'use strict'; -var common = require('../../common'); -var assert = require('assert'); +const common = require('../../common'); +const assert = require('assert'); // testing api calls for symbol -var test_symbol = require(`./build/${common.buildType}/test_symbol`); +const test_symbol = require(`./build/${common.buildType}/test_symbol`); -assert.notEqual(test_symbol.New(), test_symbol.New()); -assert.notEqual(test_symbol.New('foo'), test_symbol.New('foo')); -assert.notEqual(test_symbol.New('foo'), test_symbol.New('bar')); +assert.notStrictEqual(test_symbol.New(), test_symbol.New()); +assert.notStrictEqual(test_symbol.New('foo'), test_symbol.New('foo')); +assert.notStrictEqual(test_symbol.New('foo'), test_symbol.New('bar')); -var foo1 = test_symbol.New('foo'); -var foo2 = test_symbol.New('foo'); -var object = { +const foo1 = test_symbol.New('foo'); +const foo2 = test_symbol.New('foo'); +const object = { [foo1]: 1, [foo2]: 2, }; -assert(object[foo1] === 1); -assert(object[foo2] === 2); +assert.strictEqual(object[foo1], 1); +assert.strictEqual(object[foo2], 2); diff --git a/test/addons-abi/test_typedarray/test.js b/test/addons-abi/test_typedarray/test.js index d5748da5aaffb3..cc1fcbe3566da3 100644 --- a/test/addons-abi/test_typedarray/test.js +++ b/test/addons-abi/test_typedarray/test.js @@ -1,39 +1,39 @@ 'use strict'; -var common = require('../../common'); -var assert = require('assert'); +const common = require('../../common'); +const assert = require('assert'); // Testing api calls for arrays -var test_typedarray = require(`./build/${common.buildType}/test_typedarray`); +const test_typedarray = require(`./build/${common.buildType}/test_typedarray`); -var byteArray = new Uint8Array(3); +const byteArray = new Uint8Array(3); byteArray[0] = 0; byteArray[1] = 1; byteArray[2] = 2; -assert.equal(byteArray.length, 3); +assert.strictEqual(byteArray.length, 3); -var doubleArray = new Float64Array(3); +const doubleArray = new Float64Array(3); doubleArray[0] = 0.0; doubleArray[1] = 1.1; doubleArray[2] = 2.2; -assert.equal(doubleArray.length, 3); +assert.strictEqual(doubleArray.length, 3); -var byteResult = test_typedarray.Multiply(byteArray, 3); +const byteResult = test_typedarray.Multiply(byteArray, 3); assert.ok(byteResult instanceof Uint8Array); -assert.equal(byteResult.length, 3); -assert.equal(byteResult[0], 0); -assert.equal(byteResult[1], 3); -assert.equal(byteResult[2], 6); +assert.strictEqual(byteResult.length, 3); +assert.strictEqual(byteResult[0], 0); +assert.strictEqual(byteResult[1], 3); +assert.strictEqual(byteResult[2], 6); -var doubleResult = test_typedarray.Multiply(doubleArray, -3); +const doubleResult = test_typedarray.Multiply(doubleArray, -3); assert.ok(doubleResult instanceof Float64Array); -assert.equal(doubleResult.length, 3); -assert.equal(doubleResult[0], 0); -assert.equal(Math.round(10 * doubleResult[1]) / 10, -3.3); -assert.equal(Math.round(10 * doubleResult[2]) / 10, -6.6); +assert.strictEqual(doubleResult.length, 3); +assert.strictEqual(doubleResult[0], 0); +assert.strictEqual(Math.round(10 * doubleResult[1]) / 10, -3.3); +assert.strictEqual(Math.round(10 * doubleResult[2]) / 10, -6.6); -var externalResult = test_typedarray.External(); +const externalResult = test_typedarray.External(); assert.ok(externalResult instanceof Int8Array); -assert.equal(externalResult.length, 3); -assert.equal(externalResult[0], 0); -assert.equal(externalResult[1], 1); -assert.equal(externalResult[2], 2); +assert.strictEqual(externalResult.length, 3); +assert.strictEqual(externalResult[0], 0); +assert.strictEqual(externalResult[1], 1); +assert.strictEqual(externalResult[2], 2);