Skip to content

Commit a5a9f2c

Browse files
committed
Supporting browser tests on testkit
Teskit doesn't run Neo4j on the localhost and with the same credentials of boltkit, but it exposes the host and credentials as env variables. So all this configuration being loaded to karma on the config files, parsed in `shared-neo4j` with fallback to the process env (case it's running the usual integration test) and to the default boltkit values. All the integration tests were changed to use the values from the shareNeo4j object.
1 parent ae46eb4 commit a5a9f2c

26 files changed

+317
-129
lines changed

test/bolt-v3.test.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,10 @@ describe('#integration Bolt V3 API', () => {
3737
let originalTimeout
3838

3939
beforeEach(async () => {
40-
driver = neo4j.driver('bolt://localhost', sharedNeo4j.authToken)
40+
driver = neo4j.driver(
41+
`bolt://${sharedNeo4j.hostname}`,
42+
sharedNeo4j.authToken
43+
)
4144
session = driver.session()
4245
originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL
4346
jasmine.DEFAULT_TIMEOUT_INTERVAL = 20000

test/bolt-v4x0.test.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@ describe('#integration Bolt V4.0 API', () => {
2727
let originalTimeout
2828

2929
beforeEach(async () => {
30-
driver = neo4j.driver('bolt://localhost', sharedNeo4j.authToken)
30+
driver = neo4j.driver(
31+
`bolt://${sharedNeo4j.hostname}`,
32+
sharedNeo4j.authToken
33+
)
3134
session = driver.session()
3235
originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL
3336
jasmine.DEFAULT_TIMEOUT_INTERVAL = 20000

test/browser/karma-chrome.conf.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ module.exports = function (config) {
4141
autoWatch: false,
4242
singleRun: true,
4343
concurrency: 1,
44-
browserNoActivityTimeout: 30 * 60 * 1000
44+
browserNoActivityTimeout: 30 * 60 * 1000,
45+
client: {
46+
env: process.env
47+
}
4548
})
4649
}

test/browser/karma-firefox.conf.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ module.exports = function (config) {
5050
'network.websocket.max-connections': 256 // as in Chrome
5151
}
5252
}
53+
},
54+
client: {
55+
env: process.env
5356
}
5457
})
5558
}

test/driver.test.js

Lines changed: 95 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -39,54 +39,76 @@ describe('#unit driver', () => {
3939
})
4040

4141
it('should create an unencrypted, non-routed driver for scheme: bolt', () => {
42-
driver = neo4j.driver('bolt://localhost', sharedNeo4j.authToken)
42+
driver = neo4j.driver(
43+
`bolt://${sharedNeo4j.hostname}`,
44+
sharedNeo4j.authToken
45+
)
4346
expect(driver._isEncrypted()).toBeFalsy()
4447
expect(driver._supportsRouting()).toBeFalsy()
4548
})
4649

4750
it('should create an encrypted, system CAs trusting, non-routed driver for scheme: bolt+s', () => {
48-
driver = neo4j.driver('bolt+s://localhost', sharedNeo4j.authToken)
51+
driver = neo4j.driver(
52+
`bolt+s://${sharedNeo4j.hostname}`,
53+
sharedNeo4j.authToken
54+
)
4955
expect(driver._isEncrypted()).toBeTruthy()
5056
expect(driver._getTrust()).toEqual('TRUST_SYSTEM_CA_SIGNED_CERTIFICATES')
5157
expect(driver._supportsRouting()).toBeFalsy()
5258
})
5359

5460
it('should create an encrypted, all trusting, non-routed driver for scheme: bolt+ssc', () => {
55-
driver = neo4j.driver('bolt+ssc://localhost', sharedNeo4j.authToken)
61+
driver = neo4j.driver(
62+
`bolt+ssc://${sharedNeo4j.hostname}`,
63+
sharedNeo4j.authToken
64+
)
5665
expect(driver._isEncrypted()).toBeTruthy()
5766
expect(driver._getTrust()).toEqual('TRUST_ALL_CERTIFICATES')
5867
expect(driver._supportsRouting()).toBeFalsy()
5968
})
6069

6170
it('should create an unencrypted, routed driver for scheme: neo4j', () => {
62-
driver = neo4j.driver('neo4j://localhost', sharedNeo4j.authToken)
71+
driver = neo4j.driver(
72+
`neo4j://${sharedNeo4j.hostname}`,
73+
sharedNeo4j.authToken
74+
)
6375
expect(driver._isEncrypted()).toBeFalsy()
6476
expect(driver._supportsRouting()).toBeTruthy()
6577
})
6678

6779
it('should create an encrypted, system CAs trusting, routed driver for scheme: neo4j+s', () => {
68-
driver = neo4j.driver('neo4j+s://localhost', sharedNeo4j.authToken)
80+
driver = neo4j.driver(
81+
`neo4j+s://${sharedNeo4j.hostname}`,
82+
sharedNeo4j.authToken
83+
)
6984
expect(driver._isEncrypted()).toBeTruthy()
7085
expect(driver._getTrust()).toEqual('TRUST_SYSTEM_CA_SIGNED_CERTIFICATES')
7186
expect(driver._supportsRouting()).toBeTruthy()
7287
})
7388

7489
it('should create an encrypted, all trusting, routed driver for scheme: neo4j+ssc', () => {
75-
driver = neo4j.driver('neo4j+ssc://localhost', sharedNeo4j.authToken)
90+
driver = neo4j.driver(
91+
`neo4j+ssc://${sharedNeo4j.hostname}`,
92+
sharedNeo4j.authToken
93+
)
7694
expect(driver._isEncrypted()).toBeTruthy()
7795
expect(driver._getTrust()).toEqual('TRUST_ALL_CERTIFICATES')
7896
expect(driver._supportsRouting()).toBeTruthy()
7997
})
8098

8199
it('should throw when encryption in url AND in config', () => {
82100
expect(() =>
83-
neo4j.driver('neo4j+ssc://localhost', sharedNeo4j.authToken, {
84-
encrypted: 'ENCRYPTION_OFF'
85-
})
101+
neo4j.driver(
102+
`neo4j+ssc://${sharedNeo4j.hostname}`,
103+
sharedNeo4j.authToken,
104+
{
105+
encrypted: 'ENCRYPTION_OFF'
106+
}
107+
)
86108
).toThrow()
87109
// Throw even in case where there is no conflict
88110
expect(() =>
89-
neo4j.driver('neo4j+s://localhost', sharedNeo4j.authToken, {
111+
neo4j.driver(`neo4j+s://${sharedNeo4j.hostname}`, sharedNeo4j.authToken, {
90112
encrypted: 'ENCRYPTION_ON'
91113
})
92114
).toThrow()
@@ -98,7 +120,10 @@ describe('#integration driver', () => {
98120
let protocolVersion
99121

100122
beforeAll(async () => {
101-
const tmpDriver = neo4j.driver('bolt://localhost', sharedNeo4j.authToken)
123+
const tmpDriver = neo4j.driver(
124+
`bolt://${sharedNeo4j.hostname}`,
125+
sharedNeo4j.authToken
126+
)
102127
protocolVersion = await sharedNeo4j.cleanupAndGetProtocolVersion(tmpDriver)
103128
await tmpDriver.close()
104129
})
@@ -117,7 +142,11 @@ describe('#integration driver', () => {
117142
connectionAcquisitionTimeout: 0,
118143
encrypted: false
119144
}
120-
driver = neo4j.driver('bolt://localhost', sharedNeo4j.authToken, config)
145+
driver = neo4j.driver(
146+
`bolt://${sharedNeo4j.hostname}`,
147+
sharedNeo4j.authToken,
148+
config
149+
)
121150

122151
function beginTxWithoutCommit (driver) {
123152
const session = driver.session()
@@ -146,7 +175,10 @@ describe('#integration driver', () => {
146175

147176
it('should expose sessions', () => {
148177
// Given
149-
driver = neo4j.driver('bolt://localhost', sharedNeo4j.authToken)
178+
driver = neo4j.driver(
179+
`bolt://${sharedNeo4j.hostname}`,
180+
sharedNeo4j.authToken
181+
)
150182

151183
// When
152184
const session = driver.session()
@@ -177,7 +209,10 @@ describe('#integration driver', () => {
177209
return
178210
}
179211

180-
driver = neo4j.driver('bolt://localhost:80', sharedNeo4j.authToken)
212+
driver = neo4j.driver(
213+
`bolt://${sharedNeo4j.hostname}:80`,
214+
sharedNeo4j.authToken
215+
)
181216

182217
driver
183218
.session()
@@ -206,20 +241,22 @@ describe('#integration driver', () => {
206241

207242
it('should handle wrong scheme', () => {
208243
expect(() =>
209-
neo4j.driver('tank://localhost', sharedNeo4j.authToken)
244+
neo4j.driver(`tank://${sharedNeo4j.hostname}`, sharedNeo4j.authToken)
210245
).toThrow(new Error('Unknown scheme: tank'))
211246
})
212247

213248
it('should handle URL parameter string', () => {
214-
expect(() => neo4j.driver({ uri: 'bolt://localhost' })).toThrowError(
249+
expect(() =>
250+
neo4j.driver({ uri: `bolt://${sharedNeo4j.hostname}` })
251+
).toThrowError(TypeError)
252+
253+
expect(() => neo4j.driver([`bolt:${sharedNeo4j.hostname}`])).toThrowError(
215254
TypeError
216255
)
217256

218-
expect(() => neo4j.driver(['bolt:localhost'])).toThrowError(TypeError)
219-
220257
expect(() => {
221258
const driver = neo4j.driver(
222-
String('bolt://localhost'),
259+
String(`bolt://${sharedNeo4j.hostname}`),
223260
sharedNeo4j.authToken
224261
)
225262
return driver.session()
@@ -228,7 +265,7 @@ describe('#integration driver', () => {
228265

229266
it('should fail early on wrong credentials', async () => {
230267
// Given
231-
driver = neo4j.driver('bolt://localhost', wrongCredentials())
268+
driver = neo4j.driver(`bolt://${sharedNeo4j.hostname}`, wrongCredentials())
232269
const session = driver.session()
233270
const txc = session.beginTransaction()
234271

@@ -242,7 +279,7 @@ describe('#integration driver', () => {
242279
})
243280

244281
it('should fail queries on wrong credentials', done => {
245-
driver = neo4j.driver('bolt://localhost', wrongCredentials())
282+
driver = neo4j.driver(`bolt://${sharedNeo4j.hostname}`, wrongCredentials())
246283

247284
const session = driver.session()
248285
session.run('RETURN 1').catch(error => {
@@ -253,7 +290,10 @@ describe('#integration driver', () => {
253290

254291
it('should indicate success early on correct credentials', done => {
255292
// Given
256-
driver = neo4j.driver('bolt://localhost', sharedNeo4j.authToken)
293+
driver = neo4j.driver(
294+
`bolt://${sharedNeo4j.hostname}`,
295+
sharedNeo4j.authToken
296+
)
257297

258298
// Expect
259299
driver.verifyConnectivity().then(server => {
@@ -265,7 +305,7 @@ describe('#integration driver', () => {
265305
it('should be possible to pass a realm with basic auth tokens', done => {
266306
// Given
267307
driver = neo4j.driver(
268-
'bolt://localhost',
308+
`bolt://${sharedNeo4j.hostname}`,
269309
neo4j.auth.basic(sharedNeo4j.username, sharedNeo4j.password, 'native')
270310
)
271311

@@ -279,7 +319,7 @@ describe('#integration driver', () => {
279319
it('should be possible to create custom auth tokens', done => {
280320
// Given
281321
driver = neo4j.driver(
282-
'bolt://localhost',
322+
`bolt://${sharedNeo4j.hostname}`,
283323
neo4j.auth.custom(
284324
sharedNeo4j.username,
285325
sharedNeo4j.password,
@@ -298,7 +338,7 @@ describe('#integration driver', () => {
298338
it('should be possible to create custom auth tokens with additional parameters', done => {
299339
// Given
300340
driver = neo4j.driver(
301-
'bolt://localhost',
341+
`bolt://${sharedNeo4j.hostname}`,
302342
neo4j.auth.custom(
303343
sharedNeo4j.username,
304344
sharedNeo4j.password,
@@ -321,7 +361,10 @@ describe('#integration driver', () => {
321361
}
322362

323363
// Given
324-
driver = neo4j.driver('neo4j://localhost', sharedNeo4j.authToken)
364+
driver = neo4j.driver(
365+
`neo4j://${sharedNeo4j.hostname}`,
366+
sharedNeo4j.authToken
367+
)
325368
const session = driver.session()
326369

327370
await expectAsync(session.run('RETURN 1')).toBeRejectedWith(
@@ -335,18 +378,18 @@ describe('#integration driver', () => {
335378
})
336379

337380
it('should have correct user agent', async () => {
338-
const directDriver = neo4j.driver('bolt://localhost')
381+
const directDriver = neo4j.driver(`bolt://${sharedNeo4j.hostname}`)
339382
expect(directDriver._userAgent).toBe('neo4j-javascript/0.0.0-dev')
340383
await directDriver.close()
341384

342-
const routingDriver = neo4j.driver('neo4j://localhost')
385+
const routingDriver = neo4j.driver(`neo4j://${sharedNeo4j.hostname}`)
343386
expect(routingDriver._userAgent).toBe('neo4j-javascript/0.0.0-dev')
344387
await routingDriver.close()
345388
})
346389

347390
it('should fail when bolt:// scheme used with routing params', () => {
348391
expect(() =>
349-
neo4j.driver('bolt://localhost:7687/?policy=my_policy')
392+
neo4j.driver(`bolt://${sharedNeo4j.hostname}:7687/?policy=my_policy`)
350393
).toThrow()
351394
})
352395

@@ -369,20 +412,25 @@ describe('#integration driver', () => {
369412

370413
it('should fail when fetch size is negative', () => {
371414
expect(() =>
372-
neo4j.driver('bolt://localhost', sharedNeo4j.authToken, {
415+
neo4j.driver(`bolt://${sharedNeo4j.hostname}`, sharedNeo4j.authToken, {
373416
fetchSize: -77
374417
})
375418
).toThrow()
376419
})
377420

378421
it('should fail when fetch size is 0', () => {
379422
expect(() =>
380-
neo4j.driver('bolt://localhost', sharedNeo4j.authToken, { fetchSize: 0 })
423+
neo4j.driver(`bolt://${sharedNeo4j.hostname}`, sharedNeo4j.authToken, {
424+
fetchSize: 0
425+
})
381426
).toThrow()
382427
})
383428

384429
it('should discard closed connections', async () => {
385-
driver = neo4j.driver('bolt://localhost', sharedNeo4j.authToken)
430+
driver = neo4j.driver(
431+
`bolt://${sharedNeo4j.hostname}`,
432+
sharedNeo4j.authToken
433+
)
386434

387435
const session1 = driver.session()
388436
await session1.run('CREATE () RETURN 42')
@@ -408,9 +456,13 @@ describe('#integration driver', () => {
408456

409457
it('should discard old connections', async () => {
410458
const maxLifetime = 100000
411-
driver = neo4j.driver('bolt://localhost', sharedNeo4j.authToken, {
412-
maxConnectionLifetime: maxLifetime
413-
})
459+
driver = neo4j.driver(
460+
`bolt://${sharedNeo4j.hostname}`,
461+
sharedNeo4j.authToken,
462+
{
463+
maxConnectionLifetime: maxLifetime
464+
}
465+
)
414466

415467
const session1 = driver.session()
416468
await session1.run('CREATE () RETURN 42')
@@ -525,9 +577,13 @@ describe('#integration driver', () => {
525577
}
526578

527579
function testNumberInReturnedRecord (inputNumber, expectedNumber, done) {
528-
driver = neo4j.driver('bolt://localhost', sharedNeo4j.authToken, {
529-
disableLosslessIntegers: true
530-
})
580+
driver = neo4j.driver(
581+
`bolt://${sharedNeo4j.hostname}`,
582+
sharedNeo4j.authToken,
583+
{
584+
disableLosslessIntegers: true
585+
}
586+
)
531587

532588
const session = driver.session()
533589
session
@@ -583,7 +639,7 @@ describe('#integration driver', () => {
583639
expectedValue
584640
) {
585641
const driver = neo4j.driver(
586-
'bolt://localhost',
642+
`bolt://${sharedNeo4j.hostname}`,
587643
sharedNeo4j.authToken,
588644
config
589645
)

test/examples.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ describe('#integration examples', () => {
4545

4646
const user = sharedNeo4j.username
4747
const password = sharedNeo4j.password
48-
const uri = 'bolt://localhost:7687'
48+
const uri = `bolt://${sharedNeo4j.hostname}:7687`
4949

5050
beforeAll(() => {
5151
originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL
@@ -633,7 +633,7 @@ describe('#integration examples', () => {
633633
it('service unavailable example', done => {
634634
const console = consoleOverride
635635
const consoleLoggedMsg = consoleOverridePromise
636-
const uri = 'bolt://localhost:7688' // wrong port
636+
const uri = `bolt://${sharedNeo4j.hostname}:7688` // wrong port
637637
const password = 'wrongPassword'
638638

639639
// tag::service-unavailable[]

0 commit comments

Comments
 (0)