Skip to content

Commit

Permalink
napi, test: Fix eslint errors (nodejs#139)
Browse files Browse the repository at this point in the history
Fixes eslint errors in the test js files
Generally trivial mechanical transformation
  • Loading branch information
digitalinfinity authored Mar 10, 2017
1 parent 1cce8c7 commit e61a100
Show file tree
Hide file tree
Showing 22 changed files with 275 additions and 257 deletions.
8 changes: 4 additions & 4 deletions test/addons-abi/1_hello_world/test.js
Original file line number Diff line number Diff line change
@@ -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');
8 changes: 4 additions & 4 deletions test/addons-abi/2_function_arguments/test.js
Original file line number Diff line number Diff line change
@@ -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);
18 changes: 10 additions & 8 deletions test/addons-abi/3_callbacks/test.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
'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);
}

testRecv(undefined);
testRecv(null);
testRecv(5);
testRecv(true);
testRecv("Hello");
testRecv('Hello');
testRecv([]);
testRecv({});
12 changes: 6 additions & 6 deletions test/addons-abi/4_object_factory/test.js
Original file line number Diff line number Diff line change
@@ -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');
10 changes: 5 additions & 5 deletions test/addons-abi/5_function_factory/test.js
Original file line number Diff line number Diff line change
@@ -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'
28 changes: 14 additions & 14 deletions test/addons-abi/6_object_wrap/test.js
Original file line number Diff line number Diff line change
@@ -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);
22 changes: 11 additions & 11 deletions test/addons-abi/7_factory_wrap/test.js
Original file line number Diff line number Diff line change
@@ -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);
14 changes: 7 additions & 7 deletions test/addons-abi/8_passing_wrapped/test.js
Original file line number Diff line number Diff line change
@@ -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);
18 changes: 9 additions & 9 deletions test/addons-abi/test_array/test.js
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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);
});


Expand Down
33 changes: 17 additions & 16 deletions test/addons-abi/test_buffer/test.js
Original file line number Diff line number Diff line change
@@ -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');
18 changes: 9 additions & 9 deletions test/addons-abi/test_constructor/test.js
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
61 changes: 32 additions & 29 deletions test/addons-abi/test_exception/test.js
Original file line number Diff line number Diff line change
@@ -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');
15 changes: 8 additions & 7 deletions test/addons-abi/test_function/test.js
Original file line number Diff line number Diff line change
@@ -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);
Loading

0 comments on commit e61a100

Please sign in to comment.