From 5cc3990d468f9ee80c30732f463a9167b5269911 Mon Sep 17 00:00:00 2001 From: Connor Clark Date: Mon, 14 Oct 2019 17:14:30 -0700 Subject: [PATCH] core: rename Element to LHElement (#9832) --- lighthouse-core/gather/driver.js | 16 ++++++++-------- .../lib/{element.js => lh-element.js} | 4 ++-- lighthouse-core/test/gather/driver-test.js | 6 +++--- .../lib/{element-test.js => lh-element-test.js} | 16 ++++++++-------- 4 files changed, 21 insertions(+), 21 deletions(-) rename lighthouse-core/lib/{element.js => lh-element.js} (97%) rename lighthouse-core/test/lib/{element-test.js => lh-element-test.js} (82%) diff --git a/lighthouse-core/gather/driver.js b/lighthouse-core/gather/driver.js index 7d45562a2a6d..bc36000375ba 100644 --- a/lighthouse-core/gather/driver.js +++ b/lighthouse-core/gather/driver.js @@ -7,7 +7,7 @@ const NetworkRecorder = require('../lib/network-recorder.js'); const emulation = require('../lib/emulation.js'); -const Element = require('../lib/element.js'); +const LHElement = require('../lib/lh-element.js'); const LHError = require('../lib/lh-error.js'); const NetworkRequest = require('../lib/network-request.js'); const EventEmitter = require('events').EventEmitter; @@ -1228,7 +1228,7 @@ class Driver { /** * @param {string} selector Selector to find in the DOM - * @return {Promise} The found element, or null, resolved in a promise + * @return {Promise} The found element, or null, resolved in a promise */ async querySelector(selector) { const documentResponse = await this.sendCommand('DOM.getDocument'); @@ -1242,12 +1242,12 @@ class Driver { if (targetNode.nodeId === 0) { return null; } - return new Element(targetNode, this); + return new LHElement(targetNode, this); } /** * @param {string} selector Selector to find in the DOM - * @return {Promise>} The found elements, or [], resolved in a promise + * @return {Promise>} The found elements, or [], resolved in a promise */ async querySelectorAll(selector) { const documentResponse = await this.sendCommand('DOM.getDocument'); @@ -1258,11 +1258,11 @@ class Driver { selector, }); - /** @type {Array} */ + /** @type {Array} */ const elementList = []; targetNodeList.nodeIds.forEach(nodeId => { if (nodeId !== 0) { - elementList.push(new Element({nodeId}, this)); + elementList.push(new LHElement({nodeId}, this)); } }); return elementList; @@ -1272,13 +1272,13 @@ class Driver { * Returns the flattened list of all DOM elements within the document. * @param {boolean=} pierce Whether to pierce through shadow trees and iframes. * True by default. - * @return {Promise>} The found elements, or [], resolved in a promise + * @return {Promise>} The found elements, or [], resolved in a promise */ getElementsInDocument(pierce = true) { return this.getNodesInDocument(pierce) .then(nodes => nodes .filter(node => node.nodeType === 1) - .map(node => new Element({nodeId: node.nodeId}, this)) + .map(node => new LHElement({nodeId: node.nodeId}, this)) ); } diff --git a/lighthouse-core/lib/element.js b/lighthouse-core/lib/lh-element.js similarity index 97% rename from lighthouse-core/lib/element.js rename to lighthouse-core/lib/lh-element.js index e17a5e9fc4cb..5b9d34c01d5b 100644 --- a/lighthouse-core/lib/element.js +++ b/lighthouse-core/lib/lh-element.js @@ -7,7 +7,7 @@ const Driver = require('../gather/driver.js'); // eslint-disable-line no-unused-vars -class Element { +class LHElement { /** * @param {{nodeId: number}} element * @param {Driver} driver @@ -68,4 +68,4 @@ class Element { } } -module.exports = Element; +module.exports = LHElement; diff --git a/lighthouse-core/test/gather/driver-test.js b/lighthouse-core/test/gather/driver-test.js index d78ba2c9757a..8b87bf6f2fcc 100644 --- a/lighthouse-core/test/gather/driver-test.js +++ b/lighthouse-core/test/gather/driver-test.js @@ -7,7 +7,7 @@ const Driver = require('../../gather/driver.js'); const Connection = require('../../gather/connections/connection.js'); -const Element = require('../../lib/element.js'); +const LHElement = require('../../lib/lh-element.js'); const EventEmitter = require('events').EventEmitter; const {protocolGetVersionResponse} = require('./fake-driver.js'); const {createMockSendCommandFn, createMockOnceFn} = require('./mock-commands.js'); @@ -108,7 +108,7 @@ describe('.querySelector(All)', () => { .mockResponse('DOM.querySelector', {nodeId: 231}); const result = await driver.querySelector('meta head'); - expect(result).toBeInstanceOf(Element); + expect(result).toBeInstanceOf(LHElement); }); it('returns [] when DOM.querySelectorAll finds no node', async () => { @@ -127,7 +127,7 @@ describe('.querySelector(All)', () => { const result = await driver.querySelectorAll('#no.matches'); expect(result).toHaveLength(1); - expect(result[0]).toBeInstanceOf(Element); + expect(result[0]).toBeInstanceOf(LHElement); }); }); diff --git a/lighthouse-core/test/lib/element-test.js b/lighthouse-core/test/lib/lh-element-test.js similarity index 82% rename from lighthouse-core/test/lib/element-test.js rename to lighthouse-core/test/lib/lh-element-test.js index c97f66eb94bc..b2f20428356d 100644 --- a/lighthouse-core/test/lib/element-test.js +++ b/lighthouse-core/test/lib/lh-element-test.js @@ -5,7 +5,7 @@ */ 'use strict'; -const Element = require('../../lib/element.js'); +const LHElement = require('../../lib/lh-element.js'); const assert = require('assert'); class DriverStub { @@ -28,7 +28,7 @@ class DriverStub { } /* global describe, it, beforeEach */ -describe('Element', () => { +describe('LHElement', () => { let stubbedDriver; let stubbedElement; @@ -39,38 +39,38 @@ describe('Element', () => { it('throws when no driver or element is passed', () => { assert.throws(() => { - const _ = new Element(); + const _ = new LHElement(); }); }); it('throws when no driver is passed', () => { assert.throws(() => { - const _ = new Element(stubbedElement, undefined); + const _ = new LHElement(stubbedElement, undefined); }); }); it('throws when no element is passed', () => { assert.throws(() => { - const _ = new Element(undefined, stubbedDriver); + const _ = new LHElement(undefined, stubbedDriver); }); }); it('returns null from getAttribute when no attribute found', () => { - const element = new Element(stubbedElement, stubbedDriver); + const element = new LHElement(stubbedElement, stubbedDriver); return element.getAttribute('notanattribute').then(value => { assert.equal(value, null); }); }); it('returns attribute value from getAttribute', () => { - const element = new Element(stubbedElement, stubbedDriver); + const element = new LHElement(stubbedElement, stubbedDriver); return element.getAttribute('rel').then(value => { assert.equal(value, 'manifest'); }); }); it('returns property value from getProperty', () => { - const element = new Element(stubbedElement, stubbedDriver); + const element = new LHElement(stubbedElement, stubbedDriver); return element.getProperty('test').then(value => { assert.equal(value, '123'); });