Skip to content

Fix browser tests in the lite driver #5

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
May 25, 2023
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/core/src/internal/bolt-agent/node/bolt-agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ interface SystemInfo {
hostArch: string
nodeVersion: string
v8Version: string
platform: NodeJS.Platform
platform: string
release: string
}

Expand Down
3 changes: 3 additions & 0 deletions packages/core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ export interface Config {
logging?: LoggingConfig
resolver?: (address: string) => string[] | Promise<string[]>
userAgent?: string
}

export interface InternalConfig extends Config {
boltAgent?: BoltAgent
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ interface SystemInfo {
hostArch: string
nodeVersion: string
v8Version: string
platform: NodeJS.Platform
platform: string
release: string
}

Expand Down
3 changes: 3 additions & 0 deletions packages/neo4j-driver-deno/lib/core/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ export interface Config {
logging?: LoggingConfig
resolver?: (address: string) => string[] | Promise<string[]>
userAgent?: string
}

export interface InternalConfig extends Config {
boltAgent?: BoltAgent
}

Expand Down
21 changes: 13 additions & 8 deletions packages/neo4j-driver-deno/lib/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ import { DirectConnectionProvider, RoutingConnectionProvider } from './bolt-conn

type AuthToken = coreTypes.AuthToken
type Config = coreTypes.Config
type InternalConfig = coreTypes.InternalConfig
type TrustStrategy = coreTypes.TrustStrategy
type EncryptionLevel = coreTypes.EncryptionLevel
type SessionMode = coreTypes.SessionMode
Expand Down Expand Up @@ -288,6 +289,9 @@ function driver (
assertString(url, 'Bolt URL')
const parsedUrl = urlUtil.parseDatabaseUrl(url)

// enabling set boltAgent
const _config = config as unknown as InternalConfig

// Determine entryption/trust options from the URL.
let routing = false
let encrypted = false
Expand Down Expand Up @@ -323,20 +327,21 @@ function driver (
// Encryption enabled on URL, propagate trust to the config.
if (encrypted) {
// Check for configuration conflict between URL and config.
if ('encrypted' in config || 'trust' in config) {
if ('encrypted' in _config || 'trust' in _config) {
throw new Error(
'Encryption/trust can only be configured either through URL or config, not both'
)
}
config.encrypted = ENCRYPTION_ON
config.trust = trust
_config.encrypted = ENCRYPTION_ON
_config.trust = trust
}

const authTokenManager = createAuthManager(authToken)

// Use default user agent or user agent specified by user.
config.userAgent = config.userAgent ?? USER_AGENT
config.boltAgent = internal.boltAgent.fromVersion('neo4j-javascript/' + VERSION)
_config.userAgent = _config.userAgent ?? USER_AGENT
_config.boltAgent = internal.boltAgent.fromVersion('neo4j-javascript/' + VERSION)

const address = ServerAddress.fromUrl(parsedUrl.hostAndPort)

const meta = {
Expand All @@ -345,13 +350,13 @@ function driver (
routing
}

return new Driver(meta, config, createConnectionProviderFunction())
return new Driver(meta, _config, createConnectionProviderFunction())

function createConnectionProviderFunction (): (id: number, config: Config, log: Logger, hostNameResolver: ConfiguredCustomResolver) => ConnectionProvider {
if (routing) {
return (
id: number,
config: Config,
config: InternalConfig,
log: Logger,
hostNameResolver: ConfiguredCustomResolver
): ConnectionProvider =>
Expand All @@ -373,7 +378,7 @@ function driver (
)
}

return (id: number, config: Config, log: Logger): ConnectionProvider =>
return (id: number, config: InternalConfig, log: Logger): ConnectionProvider =>
new DirectConnectionProvider({
id,
config,
Expand Down
21 changes: 13 additions & 8 deletions packages/neo4j-driver-lite/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ import { DirectConnectionProvider, RoutingConnectionProvider } from 'neo4j-drive

type AuthToken = coreTypes.AuthToken
type Config = coreTypes.Config
type InternalConfig = coreTypes.InternalConfig
type TrustStrategy = coreTypes.TrustStrategy
type EncryptionLevel = coreTypes.EncryptionLevel
type SessionMode = coreTypes.SessionMode
Expand Down Expand Up @@ -287,6 +288,9 @@ function driver (
assertString(url, 'Bolt URL')
const parsedUrl = urlUtil.parseDatabaseUrl(url)

// enabling set boltAgent
const _config = config as unknown as InternalConfig

// Determine entryption/trust options from the URL.
let routing = false
let encrypted = false
Expand Down Expand Up @@ -322,20 +326,21 @@ function driver (
// Encryption enabled on URL, propagate trust to the config.
if (encrypted) {
// Check for configuration conflict between URL and config.
if ('encrypted' in config || 'trust' in config) {
if ('encrypted' in _config || 'trust' in _config) {
throw new Error(
'Encryption/trust can only be configured either through URL or config, not both'
)
}
config.encrypted = ENCRYPTION_ON
config.trust = trust
_config.encrypted = ENCRYPTION_ON
_config.trust = trust
}

const authTokenManager = createAuthManager(authToken)

// Use default user agent or user agent specified by user.
config.userAgent = config.userAgent ?? USER_AGENT
config.boltAgent = internal.boltAgent.fromVersion('neo4j-javascript/' + VERSION)
_config.userAgent = _config.userAgent ?? USER_AGENT
_config.boltAgent = internal.boltAgent.fromVersion('neo4j-javascript/' + VERSION)

const address = ServerAddress.fromUrl(parsedUrl.hostAndPort)

const meta = {
Expand All @@ -344,13 +349,13 @@ function driver (
routing
}

return new Driver(meta, config, createConnectionProviderFunction())
return new Driver(meta, _config, createConnectionProviderFunction())

function createConnectionProviderFunction (): (id: number, config: Config, log: Logger, hostNameResolver: ConfiguredCustomResolver) => ConnectionProvider {
if (routing) {
return (
id: number,
config: Config,
config: InternalConfig,
log: Logger,
hostNameResolver: ConfiguredCustomResolver
): ConnectionProvider =>
Expand All @@ -372,7 +377,7 @@ function driver (
)
}

return (id: number, config: Config, log: Logger): ConnectionProvider =>
return (id: number, config: InternalConfig, log: Logger): ConnectionProvider =>
new DirectConnectionProvider({
id,
config,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ class BrowserEnvironment extends NodeEnvironment {
async setup () {
await super.setup()
this.global.WebSocket = WebSocket
this.global.window = {
navigator: {
userAgent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36'
}
}
}

async teardown () {
Expand Down