From 8da8d783a1c95e2e0bcf2f8bb2f1018f5a7dfc8a Mon Sep 17 00:00:00 2001 From: Jonathan Stewmon Date: Sat, 8 Jun 2019 15:22:34 -0500 Subject: [PATCH] fix(cluster): reorder defaults arguments to prioritize user options (#889) --- lib/cluster/index.ts | 1 + test/unit/cluster.js | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/cluster/index.ts b/lib/cluster/index.ts index f0c6f515..b40b4659 100644 --- a/lib/cluster/index.ts +++ b/lib/cluster/index.ts @@ -68,6 +68,7 @@ class Cluster extends EventEmitter { this.startupNodes = startupNodes this.options = defaults(this.options, options, DEFAULT_CLUSTER_OPTIONS) + this.options = defaults({}, options, DEFAULT_CLUSTER_OPTIONS, this.options) // validate options if (typeof this.options.scaleReads !== 'function' && diff --git a/test/unit/cluster.js b/test/unit/cluster.js index a11e3e40..43f04eb5 100644 --- a/test/unit/cluster.js +++ b/test/unit/cluster.js @@ -15,11 +15,16 @@ describe('cluster', function () { it('should support frozen options', function () { var options = Object.freeze({ maxRedirections: 1000 }); var cluster = new Cluster([{ port: 7777 }], options); - expect(cluster.options).to.have.property('showFriendlyErrorStack', false); + expect(cluster.options).to.have.property('maxRedirections', 1000); expect(cluster.options).to.have.property('showFriendlyErrorStack', false); expect(cluster.options).to.have.property('scaleReads', 'master'); }); + it('should allow overriding Commander options', function () { + const cluster = new Cluster([{ port: 7777 }], {showFriendlyErrorStack: true}); + expect(cluster.options).to.have.property('showFriendlyErrorStack', true); + }) + it('throws when scaleReads is invalid', function () { expect(function () { new Cluster([{}], { scaleReads: 'invalid' });