Skip to content

Commit

Permalink
Updated review
Browse files Browse the repository at this point in the history
  • Loading branch information
wardpeet committed Jan 9, 2017
1 parent 5aeabec commit b466513
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 16 deletions.
6 changes: 1 addition & 5 deletions lighthouse-core/gather/gatherers/offline.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class Offline extends Gatherer {

afterPass(options, tracingData) {
const navigationRecord = tracingData.networkRecords.filter(record => {
return cleanHash(new URL(record._url)) === cleanHash(new URL(options.url)) &&
return new URL(record._url).stripHash().href === new URL(options.url).stripHash().href &&
record._fetchedViaServiceWorker;
}).pop(); // Take the last record that matches.

Expand All @@ -36,8 +36,4 @@ class Offline extends Gatherer {
}
}

function cleanHash(url) {
return url.href.removeURLFragment();
}

module.exports = Offline;
10 changes: 10 additions & 0 deletions lighthouse-core/lib/url-shim.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,14 @@ URL.hostsMatch = function hostsMatch(urlA, urlB) {
}
};

/**
* Removes hash from URL
* @return {URL} Url object chaining
*/
URL.prototype.stripHash = function stripHash() {
this.hash = '';

return this;
};

module.exports = URL;
24 changes: 13 additions & 11 deletions lighthouse-core/test/gather/gatherers/offline-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,19 @@ describe('Offline gatherer', () => {
url: 'https://do-not-match.com/',
driver: mockDriver
};
return offlineGather.afterPass(options, tracingData).then(artifact => {
assert.strictEqual(artifact, -1);
});
const optionsWithQueryString = {
url: 'https://ifixit-pwa.appspot.com/?history',
driver: mockDriver
};

return Promise.all([
offlineGather.afterPass(options, tracingData).then(artifact => {
assert.strictEqual(artifact, -1);
}),
offlineGather.afterPass(optionsWithQueryString, tracingData).then(artifact => {
assert.strictEqual(artifact, -1);
}),
]);
});

it('returns an artifact set to 200 when offline loading succeeds', () => {
Expand All @@ -52,21 +62,13 @@ describe('Offline gatherer', () => {
url: 'https://ifixit-pwa.appspot.com/#/history',
driver: mockDriver
};
const optionsWithQueryString = {
url: 'https://ifixit-pwa.appspot.com/?history',
driver: mockDriver
};

return Promise.all([
offlineGather.afterPass(options, tracingData).then(artifact => {
assert.strictEqual(artifact, 200);
}),
offlineGather.afterPass(optionsWithFragment, tracingData).then(artifact => {
assert.strictEqual(artifact, 200);
}),
offlineGather.afterPass(optionsWithQueryString, tracingData).then(artifact => {
assert.strictEqual(artifact, -1);
}),
]);
});
});

0 comments on commit b466513

Please sign in to comment.