Skip to content

Commit

Permalink
handle driver.getObjectProperty results with no value property (#1892)
Browse files Browse the repository at this point in the history
also handle errors thrown in driver.getObjectProperty
  • Loading branch information
brendankenny authored and paulirish committed Mar 27, 2017
1 parent 909a463 commit e822cbe
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
6 changes: 3 additions & 3 deletions lighthouse-core/gather/driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ class Driver {
* @return {!Promise<string>} The property value, or null, if property not found
*/
getObjectProperty(objectId, propName) {
return new Promise(resolve => {
return new Promise((resolve, reject) => {
this.sendCommand('Runtime.getProperties', {
objectId,
accessorPropertiesOnly: true,
Expand All @@ -507,12 +507,12 @@ class Driver {
const propertyForName = properties.result
.find(property => property.name === propName);

if (propertyForName) {
if (propertyForName && propertyForName.value) {
resolve(propertyForName.value.value);
} else {
resolve(null);
}
});
}).catch(reject);
});
}

Expand Down
10 changes: 9 additions & 1 deletion lighthouse-core/test/gather/driver-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ connection.sendCommand = function(command, params) {
value: {
value: '123'
}
}, {
name: 'novalue'
}]
});
case 'Page.enable':
Expand Down Expand Up @@ -139,7 +141,13 @@ describe('Browser Driver', () => {
});

it('returns null when getObjectProperty finds no property name', () => {
return driverStub.getObjectProperty('invalid', 'invalid').catch(value => {
return driverStub.getObjectProperty('invalid', 'invalid').then(value => {
assert.deepEqual(value, null);
});
});

it('returns null when getObjectProperty finds property name with no value', () => {
return driverStub.getObjectProperty('test', 'novalue').then(value => {
assert.deepEqual(value, null);
});
});
Expand Down

0 comments on commit e822cbe

Please sign in to comment.