Skip to content

Commit 34509b1

Browse files
jeffposnickbrendankenny
authored andcommitted
Attempt to fix the tests
1 parent 2b39d27 commit 34509b1

File tree

3 files changed

+10
-28
lines changed

3 files changed

+10
-28
lines changed

lighthouse-core/gather/gatherers/offline.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,8 @@ class Offline extends Gatherer {
5959
// If options.url is just an origin without a path, the Chrome will
6060
// implicitly add in a path of '/'.
6161
return (record._url === options.url || record._url === options.url + '/') &&
62-
record._initiator.type === 'other' &&
6362
record._fetchedViaServiceWorker;
64-
})[0];
63+
}).pop(); // Take the last record that matches.
6564

6665
this.artifact = navigationRecord ? navigationRecord.statusCode : -1;
6766
}

lighthouse-core/test/fixtures/traces/network-records.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

lighthouse-core/test/gather/gatherers/offline-test.js

Lines changed: 8 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -19,40 +19,22 @@
1919

2020
const OfflineGather = require('../../../gather/gatherers/offline');
2121
const assert = require('assert');
22+
const tracingData = require('../../fixtures/traces/network-records.json');
2223
let offlineGather;
2324

24-
describe('HTTP Redirect gatherer', () => {
25+
describe('Offline gatherer', () => {
2526
// Reset the Gatherer before each test.
2627
beforeEach(() => {
2728
offlineGather = new OfflineGather();
2829
});
2930

30-
it('returns an artifact', () => {
31-
return offlineGather.afterPass({
32-
driver: {
33-
sendCommand() {
34-
return Promise.resolve();
35-
},
36-
evaluateAsync() {
37-
return Promise.resolve({offlineResponseCode: 200});
38-
}
39-
}
40-
}).then(_ => {
41-
assert.deepEqual(offlineGather.artifact, {offlineResponseCode: 200});
42-
});
31+
it('returns an artifact set to -1 when offline loading fails', () => {
32+
offlineGather.afterPass({url: 'https://do-not-match.com'}, tracingData);
33+
assert.deepEqual(offlineGather.artifact, -1);
4334
});
4435

45-
it('handles driver sendCommand() failure', () => {
46-
return offlineGather.afterPass({
47-
driver: {
48-
sendCommand() {
49-
return Promise.reject('such a fail');
50-
}
51-
}
52-
}).then(_ => {
53-
assert(false);
54-
}).catch(_ => {
55-
assert.deepEqual(offlineGather.artifact, {offlineResponseCode: -1});
56-
});
36+
it('returns an artifact set to 200 when offline loading succeeds', () => {
37+
offlineGather.afterPass({url: 'https://ifixit-pwa.appspot.com'}, tracingData);
38+
assert.deepEqual(offlineGather.artifact, 200);
5739
});
5840
});

0 commit comments

Comments
 (0)