From bf4a116137ede57058ef3c1eab3bdc718ef063b1 Mon Sep 17 00:00:00 2001 From: Antonio Barcelos Date: Thu, 21 Apr 2022 13:05:12 +0200 Subject: [PATCH 1/2] Remove lodash dependency --- packages/neo4j-driver/package-lock.json | 2 +- packages/neo4j-driver/package.json | 1 - packages/neo4j-driver/test/session.test.js | 5 ++- .../neo4j-driver/test/spatial-types.test.js | 3 +- packages/neo4j-driver/test/stress-test.js | 14 ++++---- packages/neo4j-driver/test/stress.test.js | 21 ++++++----- .../neo4j-driver/test/temporal-types.test.js | 36 +++++++++++++------ packages/neo4j-driver/test/types.test.js | 20 ++++++++--- 8 files changed, 66 insertions(+), 36 deletions(-) diff --git a/packages/neo4j-driver/package-lock.json b/packages/neo4j-driver/package-lock.json index 517a80ef4..5955df9db 100644 --- a/packages/neo4j-driver/package-lock.json +++ b/packages/neo4j-driver/package-lock.json @@ -5,6 +5,7 @@ "requires": true, "packages": { "": { + "name": "neo4j-driver", "version": "5.0.0-dev", "license": "Apache-2.0", "dependencies": { @@ -51,7 +52,6 @@ "karma-jasmine": "^4.0.2", "karma-source-map-support": "^1.4.0", "karma-spec-reporter": "^0.0.33", - "lodash": "^4.17.21", "lolex": "^6.0.0", "minimist": "^1.2.6", "mustache": "^4.2.0", diff --git a/packages/neo4j-driver/package.json b/packages/neo4j-driver/package.json index a7f13427e..715d52989 100644 --- a/packages/neo4j-driver/package.json +++ b/packages/neo4j-driver/package.json @@ -73,7 +73,6 @@ "karma-jasmine": "^4.0.2", "karma-source-map-support": "^1.4.0", "karma-spec-reporter": "^0.0.33", - "lodash": "^4.17.21", "lolex": "^6.0.0", "minimist": "^1.2.6", "mustache": "^4.2.0", diff --git a/packages/neo4j-driver/test/session.test.js b/packages/neo4j-driver/test/session.test.js index f20a08952..477960a5c 100644 --- a/packages/neo4j-driver/test/session.test.js +++ b/packages/neo4j-driver/test/session.test.js @@ -20,7 +20,6 @@ import neo4j from '../src' import { READ } from '../src/driver' import sharedNeo4j from './internal/shared-neo4j' -import _ from 'lodash' import testUtils from './internal/test-utils' import { newError, @@ -846,8 +845,8 @@ describe('#integration session', () => { allBookmarks.push(bookmarks) } - expect(_.uniq(allBookmarks).length).toEqual(nodeCount) - allBookmarks.forEach(bookmarks => expect(_.isArray(bookmarks)).toBeTruthy()) + expect(new Set(allBookmarks).size).toEqual(nodeCount) + allBookmarks.forEach(bookmarks => expect(Array.isArray(bookmarks)).toBeTruthy()) const session = driver.session({ defaultAccessMode: READ, diff --git a/packages/neo4j-driver/test/spatial-types.test.js b/packages/neo4j-driver/test/spatial-types.test.js index bdeb24a42..c18505acd 100644 --- a/packages/neo4j-driver/test/spatial-types.test.js +++ b/packages/neo4j-driver/test/spatial-types.test.js @@ -20,7 +20,6 @@ import neo4j, { int } from '../src' import sharedNeo4j from './internal/shared-neo4j' import { isPoint, Point } from 'neo4j-driver-core' -import _ from 'lodash' const WGS_84_2D_CRS_CODE = neo4j.int(4326) const CARTESIAN_2D_CRS_CODE = neo4j.int(7203) @@ -198,7 +197,7 @@ describe('#integration spatial-types', () => { 'RETURN point({x: 42.231, y: 176.938123})', point => { expect(isPoint(point)).toBeTruthy() - expect(_.isNumber(point.srid)).toBeTruthy() + expect(typeof point.srid).toEqual('number') expect(point.srid).toEqual(CARTESIAN_2D_CRS_CODE.toNumber()) } ) diff --git a/packages/neo4j-driver/test/stress-test.js b/packages/neo4j-driver/test/stress-test.js index 06ad8aa92..e2955c533 100644 --- a/packages/neo4j-driver/test/stress-test.js +++ b/packages/neo4j-driver/test/stress-test.js @@ -20,7 +20,6 @@ import neo4j from '../src' import { READ, WRITE } from '../src/driver' import parallelLimit from 'async/parallelLimit' -import _ from 'lodash' import sharedNeo4j from './internal/shared-neo4j' const TEST_MODES = { @@ -158,10 +157,12 @@ function isCluster () { function createCommands (context) { const uniqueCommands = createUniqueCommands(context) - + function sample (arr) { + return arr[Math.floor(Math.random() * arr.length)] + } const commands = [] for (let i = 0; i < TEST_MODE.commandsCount; i++) { - const randomCommand = _.sample(uniqueCommands) + const randomCommand = sample(uniqueCommands) commands.push(randomCommand) } @@ -455,9 +456,9 @@ function verifyRecord (record) { return new Error(`Unexpected labels in node: ${JSON.stringify(node)}`) } - const propertyKeys = _.keys(node.properties) + const propertyKeys = node.labels if ( - !_.isEmpty(propertyKeys) && + propertyKeys.length > 0 && !arraysEqual(['name', 'salary'], propertyKeys) ) { return new Error( @@ -584,7 +585,8 @@ function fromEnvOrDefault (envVariableName, defaultValue = undefined) { } function arraysEqual (array1, array2) { - return _.difference(array1, array2).length === 0 + const resultant = array1.filter(item => !array2.find(item2 => item2.valueOf() === item.valueOf())) + return resultant.length === 0 } class Context { diff --git a/packages/neo4j-driver/test/stress.test.js b/packages/neo4j-driver/test/stress.test.js index 2e1f9dc58..d289c7691 100644 --- a/packages/neo4j-driver/test/stress.test.js +++ b/packages/neo4j-driver/test/stress.test.js @@ -20,7 +20,6 @@ import neo4j from '../src' import { READ, WRITE } from '../src/driver' import parallelLimit from 'async/parallelLimit' -import _ from 'lodash' import sharedNeo4j from './internal/shared-neo4j' describe('#integration stress tests', () => { @@ -120,11 +119,14 @@ describe('#integration stress tests', () => { ) function createCommands (context) { + function sample (arr) { + return arr[Math.floor(Math.random() * arr.length)] + } const uniqueCommands = createUniqueCommands(context) const commands = [] for (let i = 0; i < TEST_MODE.commandsCount; i++) { - const randomCommand = _.sample(uniqueCommands) + const randomCommand = sample(uniqueCommands) commands.push(randomCommand) } @@ -427,9 +429,9 @@ describe('#integration stress tests', () => { return new Error(`Unexpected labels in node: ${JSON.stringify(node)}`) } - const propertyKeys = _.keys(node.properties) + const propertyKeys = node.labels if ( - !_.isEmpty(propertyKeys) && + propertyKeys.length > 0 && !arraysEqual(['name', 'salary'], propertyKeys) ) { return new Error( @@ -550,19 +552,19 @@ describe('#integration stress tests', () => { } function addressesForMultiDb (records, role, db = 'neo4j') { - return _.uniq( + return [...new Set( records .filter(record => record.get('databases')[db] === role) .map(record => record.get('addresses')[0].replace('bolt://', '')) - ) + )] } function addressesWithRole (records, role) { - return _.uniq( + return [...new Set( records .filter(record => record.get('role') === role) .map(record => record.get('addresses')[0].replace('bolt://', '')) - ) + )] } function assertAllAddressesServedReadQueries (addresses, readQueriesByServer) { @@ -641,7 +643,8 @@ describe('#integration stress tests', () => { } function arraysEqual (array1, array2) { - return _.difference(array1, array2).length === 0 + const resultant = array1.filter(item => !array2.find(item2 => item2.valueOf() === item.valueOf())) + return resultant.length === 0 } class Context { diff --git a/packages/neo4j-driver/test/temporal-types.test.js b/packages/neo4j-driver/test/temporal-types.test.js index d074aaee1..9815a90f4 100644 --- a/packages/neo4j-driver/test/temporal-types.test.js +++ b/packages/neo4j-driver/test/temporal-types.test.js @@ -21,7 +21,6 @@ import neo4j from '../src' import sharedNeo4j from './internal/shared-neo4j' import { toNumber, internal } from 'neo4j-driver-core' import timesSeries from 'async/timesSeries' -import _ from 'lodash' import testUtils from './internal/test-utils' const { @@ -1423,11 +1422,11 @@ describe('#integration temporal-types', () => { } async function testSendAndReceiveArrayOfRandomTemporalValues (valueGenerator) { - const arrayLength = _.random( + const arrayLength = random( MIN_TEMPORAL_ARRAY_LENGTH, MAX_TEMPORAL_ARRAY_LENGTH ) - const values = _.range(arrayLength).map(() => valueGenerator()) + const values = range(arrayLength).map(() => valueGenerator()) await testSendReceiveTemporalValue(values) } @@ -1486,12 +1485,12 @@ describe('#integration temporal-types', () => { } function randomDuration () { - const sign = _.sample([-1, 1]) // duration can be negative + const sign = sample([-1, 1]) // duration can be negative return duration( - sign * _.random(0, MAX_DURATION_COMPONENT), - sign * _.random(0, MAX_DURATION_COMPONENT), - sign * _.random(0, MAX_DURATION_COMPONENT), - _.random(0, MAX_NANO_OF_SECOND) + sign * random(0, MAX_DURATION_COMPONENT), + sign * random(0, MAX_DURATION_COMPONENT), + sign * random(0, MAX_DURATION_COMPONENT), + random(0, MAX_NANO_OF_SECOND) ) } @@ -1600,7 +1599,24 @@ describe('#integration temporal-types', () => { } function randomZoneId () { - return _.sample(ZONE_IDS) + return sample(ZONE_IDS) + } + + function random (lower, upper) { + const interval = upper - lower + return lower + Math.floor(Math.random() * interval) + } + + function range (size) { + const arr = [] + for (let i; i < size; i++) { + arr.push(i) + } + return arr + } + + function sample (arr) { + return arr[Math.floor(Math.random() * arr.length)] } function duration (months, days, seconds, nanoseconds) { @@ -1698,7 +1714,7 @@ describe('#integration temporal-types', () => { } function randomInt (lower, upper) { - return neo4j.int(_.random(lower, upper)) + return neo4j.int(random(lower, upper)) } function testStandardDateToLocalTimeConversion (date, nanosecond) { diff --git a/packages/neo4j-driver/test/types.test.js b/packages/neo4j-driver/test/types.test.js index ea2c23d29..4570469d7 100644 --- a/packages/neo4j-driver/test/types.test.js +++ b/packages/neo4j-driver/test/types.test.js @@ -19,7 +19,6 @@ import neo4j from '../src' import sharedNeo4j from './internal/shared-neo4j' -import _ from 'lodash' describe('#integration null value', () => { it('should support null', testValue(null)) @@ -246,13 +245,26 @@ function runReturnQuery (driver, actual, expected) { } function randomByteArrays (count, minLength, maxLength) { - return _.range(count).map(() => { - const length = _.random(minLength, maxLength) + return range(count).map(() => { + const length = random(minLength, maxLength) return randomByteArray(length) }) } function randomByteArray (length) { - const array = _.range(length).map(() => _.random(-128, 127)) + const array = range(length).map(() => random(-128, 127)) return new Int8Array(array) } + +function range (size) { + const arr = [] + for (let i; i < size; i++) { + arr.push(i) + } + return arr +} + +function random (lower, upper) { + const interval = upper - lower + return lower + Math.floor(Math.random() * interval) +} From c64c186616f06c57270c3a5a420b647b2060cd08 Mon Sep 17 00:00:00 2001 From: Antonio Barcelos Date: Thu, 21 Apr 2022 13:12:54 +0200 Subject: [PATCH 2/2] Remove lodash dependency --- packages/neo4j-driver/test/stress-test.js | 2 +- packages/neo4j-driver/test/stress.test.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/neo4j-driver/test/stress-test.js b/packages/neo4j-driver/test/stress-test.js index e2955c533..c48b87ac9 100644 --- a/packages/neo4j-driver/test/stress-test.js +++ b/packages/neo4j-driver/test/stress-test.js @@ -456,7 +456,7 @@ function verifyRecord (record) { return new Error(`Unexpected labels in node: ${JSON.stringify(node)}`) } - const propertyKeys = node.labels + const propertyKeys = Object.keys(node.properties) if ( propertyKeys.length > 0 && !arraysEqual(['name', 'salary'], propertyKeys) diff --git a/packages/neo4j-driver/test/stress.test.js b/packages/neo4j-driver/test/stress.test.js index d289c7691..9127cfe85 100644 --- a/packages/neo4j-driver/test/stress.test.js +++ b/packages/neo4j-driver/test/stress.test.js @@ -429,7 +429,7 @@ describe('#integration stress tests', () => { return new Error(`Unexpected labels in node: ${JSON.stringify(node)}`) } - const propertyKeys = node.labels + const propertyKeys = Object.keys(node.properties) if ( propertyKeys.length > 0 && !arraysEqual(['name', 'salary'], propertyKeys)