fix bug in DeviceSettings where we could mutate external object
MODIFY
lib/basedriver/device-settings.js
lib/basedriver/device-settings.js
@@ -4,7 +4,7 @@ import log from './logger';
class DeviceSettings {
constructor (defaultSettings = {}, onSettingsUpdate = null) {
- this._settings = defaultSettings;
+ this._settings = Object.assign({}, defaultSettings);
this.onSettingsUpdate = onSettingsUpdate;
}

MODIFY
test/basedriver/driver-tests.js
test/basedriver/driver-tests.js
@@ -2,6 +2,7 @@ import _ from 'lodash';
import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
import B from 'bluebird';
+import { DeviceSettings } from '../..';
const should = chai.should();
chai.use(chaiAsPromised);
@@ -335,6 +336,16 @@ function baseDriverUnitTests (DriverClass, defaultCaps = {}) {
});
});
});
+
+ describe('DeviceSettings', () => {
+ it('should not hold on to reference of defaults in constructor', () => {
+ let obj = {foo: 'bar'};
+ let d1 = new DeviceSettings(obj);
+ let d2 = new DeviceSettings(obj);
+ d1._settings.foo = 'baz';
+ d1._settings.should.not.eql(d2._settings);
+ });
+ });
}
export default baseDriverUnitTests;

fix bug in DeviceSettings where we could mutate external object