Skip to content

Commit

Permalink
ignore URL fragment when asserting page loaded (#1677)
Browse files Browse the repository at this point in the history
  • Loading branch information
brendankenny authored and paulirish committed Feb 10, 2017
1 parent 9ac57cb commit 85f9b43
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
6 changes: 5 additions & 1 deletion lighthouse-core/gather/gather-runner.js
Expand Up @@ -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.
Expand Down Expand Up @@ -135,7 +136,10 @@ class GatherRunner {
* @param {!Array<WebInspector.NetworkRequest>} 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);
Expand Down
12 changes: 10 additions & 2 deletions lighthouse-core/test/gather/gather-runner-test.js
Expand Up @@ -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']};

Expand All @@ -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);
});
Expand Down Expand Up @@ -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, {
Expand All @@ -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');
});
Expand Down Expand Up @@ -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'}];
Expand Down

0 comments on commit 85f9b43

Please sign in to comment.