Skip to content

Commit

Permalink
core(fr): convert service-worker gatherer (#12662)
Browse files Browse the repository at this point in the history
  • Loading branch information
adamraine authored Jun 19, 2021
1 parent 13d7ebc commit 0be8d52
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 8 deletions.
3 changes: 3 additions & 0 deletions lighthouse-core/fraggle-rock/config/default-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const artifacts = {
PasswordInputsWithPreventedPaste: '',
ResponseCompression: '',
RobotsTxt: '',
ServiceWorker: '',
ScriptElements: '',
SourceMaps: '',
Stacks: '',
Expand Down Expand Up @@ -94,6 +95,7 @@ const defaultConfig = {
{id: artifacts.PasswordInputsWithPreventedPaste, gatherer: 'dobetterweb/password-inputs-with-prevented-paste'},
{id: artifacts.ResponseCompression, gatherer: 'dobetterweb/response-compression'},
{id: artifacts.RobotsTxt, gatherer: 'seo/robots-txt'},
{id: artifacts.ServiceWorker, gatherer: 'service-worker'},
{id: artifacts.ScriptElements, gatherer: 'script-elements'},
{id: artifacts.SourceMaps, gatherer: 'source-maps'},
{id: artifacts.Stacks, gatherer: 'stacks'},
Expand Down Expand Up @@ -149,6 +151,7 @@ const defaultConfig = {
artifacts.PasswordInputsWithPreventedPaste,
artifacts.ResponseCompression,
artifacts.RobotsTxt,
artifacts.ServiceWorker,
artifacts.ScriptElements,
artifacts.SourceMaps,
artifacts.Stacks,
Expand Down
23 changes: 20 additions & 3 deletions lighthouse-core/gather/gatherers/service-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,33 @@
*/
'use strict';

const Gatherer = require('./gatherer.js');
const FRGatherer = require('../../fraggle-rock/gather/base-gatherer.js');
const serviceWorkers = require('../driver/service-workers.js');

class ServiceWorker extends Gatherer {
class ServiceWorker extends FRGatherer {
/** @type {LH.Gatherer.GathererMeta} */
meta = {
supportedModes: ['navigation'],
}

/**
* @param {LH.Gatherer.PassContext} passContext
* @return {Promise<LH.Artifacts['ServiceWorker']>}
*/
async beforePass(passContext) {
const session = passContext.driver.defaultSession;
return this.getArtifact({...passContext, dependencies: {}});
}

// This gatherer is run in a separate pass for legacy mode.
// Legacy compat code is in `beforePass`.
async afterPass() { }

/**
* @param {LH.Gatherer.FRTransitionalContext} context
* @return {Promise<LH.Artifacts['ServiceWorker']>}
*/
async getArtifact(context) {
const session = context.driver.defaultSession;
const {versions} = await serviceWorkers.getServiceWorkerVersions(session);
const {registrations} = await serviceWorkers.getServiceWorkerRegistrations(session);

Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/test/fraggle-rock/api-test-pptr.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ describe('Fraggle Rock API', () => {
const {lhr} = result;
const {auditResults, failedAudits, erroredAudits} = getAuditsBreakdown(lhr);
// TODO(FR-COMPAT): This assertion can be removed when full compatibility is reached.
expect(auditResults.length).toMatchInlineSnapshot(`151`);
expect(auditResults.length).toMatchInlineSnapshot(`152`);
expect(erroredAudits).toHaveLength(0);

const failedAuditIds = failedAudits.map(audit => audit.id);
Expand Down
4 changes: 2 additions & 2 deletions lighthouse-core/test/fraggle-rock/config/config-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ describe('Fraggle Rock Config', () => {
});

it('should throw on invalid artifact definitions', () => {
const configJson = {artifacts: [{id: 'ServiceWorker', gatherer: 'service-worker'}]};
expect(() => initializeConfig(configJson, {gatherMode})).toThrow(/ServiceWorker gatherer/);
const configJson = {artifacts: [{id: 'HTTPRedirect', gatherer: 'http-redirect'}]};
expect(() => initializeConfig(configJson, {gatherMode})).toThrow(/HTTPRedirect gatherer/);
});

it('should resolve navigation definitions', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe('service worker gatherer', () => {
getServiceWorkerRegistrations.mockResolvedValue({registrations});

const serviceWorkerGatherer = new ServiceWorkerGather();
const artifact = await serviceWorkerGatherer.beforePass({
const artifact = await serviceWorkerGatherer.getArtifact({
driver: {},
url,
});
Expand Down
1 change: 0 additions & 1 deletion types/artifacts.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ declare global {
| 'HTTPRedirect'
| 'Manifest'
| 'MixedContent'
| 'ServiceWorker'
| keyof FRBaseArtifacts
>;

Expand Down

0 comments on commit 0be8d52

Please sign in to comment.