forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
napi, test: Fix eslint errors (nodejs#139)
Fixes eslint errors in the test js files Generally trivial mechanical transformation
- Loading branch information
1 parent
1cce8c7
commit e61a100
Showing
22 changed files
with
275 additions
and
257 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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({}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
Oops, something went wrong.