mirror of
https://github.com/appium/appium.git
synced 2026-10-29 04:36:39 +08:00
refactor: Change the setting update validation, so we don't print unnecessary warnings (#372)
This commit is contained in:
@@ -73,23 +73,25 @@ class DeviceSettings {
|
||||
|
||||
// calls updateSettings from implementing driver every time a setting is changed.
|
||||
async update (newSettings) {
|
||||
if (!_.isObject(newSettings)) {
|
||||
throw new Error('Settings update should be called with valid JSON');
|
||||
if (!_.isPlainObject(newSettings)) {
|
||||
throw new Error(`Settings update should be called with valid JSON. Got ` +
|
||||
`${JSON.stringify(newSettings)} instead`);
|
||||
}
|
||||
for (let prop of _.keys(newSettings)) {
|
||||
if (_.isUndefined(this._settings[prop])) {
|
||||
log.warn(`Didn't know about setting '${prop}'. Are you sure you ` +
|
||||
`spelled it correctly? Proceeding anyway. Valid settings: ${_.keys(this._settings)}`);
|
||||
}
|
||||
if (this._settings[prop] !== newSettings[prop]) {
|
||||
// update setting only when there is updateSettings defined.
|
||||
if (this.onSettingsUpdate) {
|
||||
await this.onSettingsUpdate(prop, newSettings[prop], this._settings[prop]);
|
||||
this._settings[prop] = newSettings[prop];
|
||||
} else {
|
||||
log.errorAndThrow('Unable to update settings; onSettingsUpdate method not found');
|
||||
for (const prop of _.keys(newSettings)) {
|
||||
if (!_.isUndefined(this._settings[prop])) {
|
||||
if (this._settings[prop] === newSettings[prop]) {
|
||||
log.debug(`The value of '${prop}' setting did not change. Skipping the update for it`);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
// update setting only when there is updateSettings defined.
|
||||
if (_.isFunction(this.onSettingsUpdate)) {
|
||||
await this.onSettingsUpdate(prop, newSettings[prop], this._settings[prop]);
|
||||
this._settings[prop] = newSettings[prop];
|
||||
} else {
|
||||
log.errorAndThrow(`Unable to update settings; ` +
|
||||
`onSettingsUpdate method not found on '${this.constructor.name}'`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user