Skip to content

Commit

Permalink
fix(cluster): reorder defaults arguments to prioritize user options (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
jstewmon authored and AVVS committed Jun 8, 2019
1 parent e83226b commit 8da8d78
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/cluster/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' &&
Expand Down
7 changes: 6 additions & 1 deletion test/unit/cluster.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' });
Expand Down

0 comments on commit 8da8d78

Please sign in to comment.