From 85f9b431839cefa41f917c2e81a47c5feb2deafe Mon Sep 17 00:00:00 2001 From: Brendan Kenny Date: Thu, 9 Feb 2017 16:43:52 -0800 Subject: [PATCH] ignore URL fragment when asserting page loaded (#1677) --- lighthouse-core/gather/gather-runner.js | 6 +++++- lighthouse-core/test/gather/gather-runner-test.js | 12 ++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/lighthouse-core/gather/gather-runner.js b/lighthouse-core/gather/gather-runner.js index 3828531da7b1..7ca6add1350d 100644 --- a/lighthouse-core/gather/gather-runner.js +++ b/lighthouse-core/gather/gather-runner.js @@ -19,6 +19,7 @@ const log = require('../lib/log.js'); const Audit = require('../audits/audit'); const path = require('path'); +const URL = require('../lib/url-shim'); /** * Class that drives browser to load the page and runs gatherer lifecycle hooks. @@ -135,7 +136,10 @@ class GatherRunner { * @param {!Array} networkRecords */ static assertPageLoaded(url, driver, networkRecords) { - const mainRecord = networkRecords.find(record => record.url === url); + const mainRecord = networkRecords.find(record => { + // record.url is actual request url, so needs to be compared without any URL fragment. + return URL.equalWithExcludedFragments(record.url, url); + }); if (driver.online && (!mainRecord || mainRecord.failed)) { const message = mainRecord ? mainRecord.localizedFailDescription : 'timeout reached'; log.error('GatherRunner', message); diff --git a/lighthouse-core/test/gather/gather-runner-test.js b/lighthouse-core/test/gather/gather-runner-test.js index 7ce70edbe3c2..902b9659255f 100644 --- a/lighthouse-core/test/gather/gather-runner-test.js +++ b/lighthouse-core/test/gather/gather-runner-test.js @@ -273,6 +273,7 @@ describe('GatherRunner', function() { }); it('tells the driver to end tracing', () => { + const url = 'https://example.com'; let calledTrace = false; const fakeTraceData = {traceEvents: ['reallyBelievableTraceEvents']}; @@ -290,7 +291,7 @@ describe('GatherRunner', function() { ] }; - return GatherRunner.afterPass({driver, config}, {TestGatherer: []}).then(passData => { + return GatherRunner.afterPass({url, driver, config}, {TestGatherer: []}).then(passData => { assert.equal(calledTrace, true); assert.equal(passData.trace, fakeTraceData); }); @@ -319,6 +320,7 @@ describe('GatherRunner', function() { }); it('tells the driver to end network collection', () => { + const url = 'https://example.com'; let calledNetworkCollect = false; const driver = Object.assign({}, fakeDriver, { @@ -339,7 +341,7 @@ describe('GatherRunner', function() { ] }; - return GatherRunner.afterPass({driver, config}, {TestGatherer: []}).then(vals => { + return GatherRunner.afterPass({url, driver, config}, {TestGatherer: []}).then(vals => { assert.equal(calledNetworkCollect, true); assert.strictEqual(vals.networkRecords.marker, 'mocked'); }); @@ -518,6 +520,12 @@ describe('GatherRunner', function() { GatherRunner.assertPageLoaded(url, {online: true}, records); }); + it('passes when the page is loaded, ignoring any fragment', () => { + const url = 'http://example.com/#/page/list'; + const records = [{url: 'http://example.com'}]; + GatherRunner.assertPageLoaded(url, {online: true}, records); + }); + it('throws when page fails to load', () => { const url = 'http://the-page.com'; const records = [{url, failed: true, localizedFailDescription: 'foobar'}];