Skip to content

Commit

Permalink
Attempt to fix the tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffposnick authored and brendankenny committed Aug 29, 2016
1 parent 6f74703 commit bde0b39
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 28 deletions.
3 changes: 1 addition & 2 deletions lighthouse-core/gather/gatherers/offline.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,8 @@ class Offline extends Gatherer {
// If options.url is just an origin without a path, the Chrome will
// implicitly add in a path of '/'.
return (record._url === options.url || record._url === options.url + '/') &&
record._initiator.type === 'other' &&
record._fetchedViaServiceWorker;
})[0];
}).pop(); // Take the last record that matches.

this.artifact = navigationRecord ? navigationRecord.statusCode : -1;
}
Expand Down
1 change: 1 addition & 0 deletions lighthouse-core/test/fixtures/traces/network-records.json

Large diffs are not rendered by default.

34 changes: 8 additions & 26 deletions lighthouse-core/test/gather/gatherers/offline-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,40 +19,22 @@

const OfflineGather = require('../../../gather/gatherers/offline');
const assert = require('assert');
const tracingData = require('../../fixtures/traces/network-records.json');
let offlineGather;

describe('HTTP Redirect gatherer', () => {
describe('Offline gatherer', () => {
// Reset the Gatherer before each test.
beforeEach(() => {
offlineGather = new OfflineGather();
});

it('returns an artifact', () => {
return offlineGather.afterPass({
driver: {
sendCommand() {
return Promise.resolve();
},
evaluateAsync() {
return Promise.resolve({offlineResponseCode: 200});
}
}
}).then(_ => {
assert.deepEqual(offlineGather.artifact, {offlineResponseCode: 200});
});
it('returns an artifact set to -1 when offline loading fails', () => {
offlineGather.afterPass({url: 'https://do-not-match.com'}, tracingData);
assert.deepEqual(offlineGather.artifact, -1);
});

it('handles driver sendCommand() failure', () => {
return offlineGather.afterPass({
driver: {
sendCommand() {
return Promise.reject('such a fail');
}
}
}).then(_ => {
assert(false);
}).catch(_ => {
assert.deepEqual(offlineGather.artifact, {offlineResponseCode: -1});
});
it('returns an artifact set to 200 when offline loading succeeds', () => {
offlineGather.afterPass({url: 'https://ifixit-pwa.appspot.com'}, tracingData);
assert.deepEqual(offlineGather.artifact, 200);
});
});

0 comments on commit bde0b39

Please sign in to comment.