Skip to content

Remove lodash dependency #923

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

Merged
merged 2 commits into from
Apr 21, 2022
Merged
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/neo4j-driver/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion packages/neo4j-driver/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
5 changes: 2 additions & 3 deletions packages/neo4j-driver/test/session.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
3 changes: 1 addition & 2 deletions packages/neo4j-driver/test/spatial-types.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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())
}
)
Expand Down
14 changes: 8 additions & 6 deletions packages/neo4j-driver/test/stress-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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)
}

Expand Down Expand Up @@ -455,9 +456,9 @@ function verifyRecord (record) {
return new Error(`Unexpected labels in node: ${JSON.stringify(node)}`)
}

const propertyKeys = _.keys(node.properties)
const propertyKeys = Object.keys(node.properties)
if (
!_.isEmpty(propertyKeys) &&
propertyKeys.length > 0 &&
!arraysEqual(['name', 'salary'], propertyKeys)
) {
return new Error(
Expand Down Expand Up @@ -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 {
Expand Down
21 changes: 12 additions & 9 deletions packages/neo4j-driver/test/stress.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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)
}

Expand Down Expand Up @@ -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 = Object.keys(node.properties)
if (
!_.isEmpty(propertyKeys) &&
propertyKeys.length > 0 &&
!arraysEqual(['name', 'salary'], propertyKeys)
) {
return new Error(
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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 {
Expand Down
36 changes: 26 additions & 10 deletions packages/neo4j-driver/test/temporal-types.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
)
}

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down
20 changes: 16 additions & 4 deletions packages/neo4j-driver/test/types.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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)
}