diff --git a/src/connection.ts b/src/connection.ts index 4241efc85..d342dd419 100644 --- a/src/connection.ts +++ b/src/connection.ts @@ -1052,7 +1052,7 @@ class Connection extends EventEmitter { throw new TypeError('The "config" argument is required and must be of type Object.'); } - if (typeof config.server !== 'string') { + if (typeof config.server !== 'string' && !config.options.connector) { throw new TypeError('The "config.server" property is required and must be of type string.'); } @@ -1900,7 +1900,7 @@ class Connection extends EventEmitter { initialiseConnection() { const signal = this.createConnectTimer(); - if (this.config.options.port) { + if (this.config.options.port || this.config.options.connector) { return this.connectOnPort(this.config.options.port, this.config.options.multiSubnetFailover, signal, this.config.options.connector); } else { return instanceLookup({ diff --git a/test/unit/custom-connector.js b/test/unit/custom-connector.js index 36e49d19d..fb23984bc 100644 --- a/test/unit/custom-connector.js +++ b/test/unit/custom-connector.js @@ -28,7 +28,6 @@ describe('custom connector', function() { const host = server.address().address; const port = server.address().port; const connection = new Connection({ - server: host, options: { connector: async () => { customConnectorCalled = true; @@ -37,7 +36,6 @@ describe('custom connector', function() { port, }); }, - port }, });