Skip to content

Commit

Permalink
core(http-status-code): navigation only (#13005)
Browse files Browse the repository at this point in the history
  • Loading branch information
adamraine authored Sep 2, 2021
1 parent 2959e00 commit ce87060
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 22 deletions.
8 changes: 2 additions & 6 deletions lighthouse-core/audits/seo/http-status-code.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class HTTPStatusCode extends Audit {
failureTitle: str_(UIStrings.failureTitle),
description: str_(UIStrings.description),
requiredArtifacts: ['devtoolsLogs', 'URL', 'GatherContext'],
supportedModes: ['navigation'],
};
}

Expand All @@ -47,12 +48,7 @@ class HTTPStatusCode extends Audit {
const devtoolsLog = artifacts.devtoolsLogs[Audit.DEFAULT_PASS];
const URL = artifacts.URL;
const networkRecords = await NetworkRecords.request(devtoolsLog, context);
const mainResource = NetworkAnalyzer.findOptionalMainDocument(networkRecords, URL.finalUrl);

if (!mainResource) {
if (artifacts.GatherContext.gatherMode === 'timespan') return {notApplicable: true, score: 1};
throw new Error(`Unable to locate main resource`);
}
const mainResource = NetworkAnalyzer.findMainDocument(networkRecords, URL.finalUrl);

const statusCode = mainResource.statusCode;

Expand Down
13 changes: 0 additions & 13 deletions lighthouse-core/test/audits/seo/http-status-code-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,4 @@ describe('SEO: HTTP code audit', () => {
const resultPromise = HTTPStatusCodeAudit.audit(artifacts, {computedCache: new Map()});
await expect(resultPromise).rejects.toThrow();
});

it('notApplicable when main resource cannot be found in timespan', async () => {
const finalUrl = 'https://example.com';

const artifacts = {
GatherContext: {gatherMode: 'timespan'},
devtoolsLogs: {[HTTPStatusCodeAudit.DEFAULT_PASS]: []},
URL: {finalUrl},
};

const results = await HTTPStatusCodeAudit.audit(artifacts, {computedCache: new Map()});
expect(results.notApplicable).toBe(true);
});
});
6 changes: 3 additions & 3 deletions lighthouse-core/test/fraggle-rock/api-test-pptr.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ describe('Fraggle Rock API', () => {
notApplicableAudits,
} = getAuditsBreakdown(lhr);
// TODO(FR-COMPAT): This assertion can be removed when full compatibility is reached.
expect(auditResults.length).toMatchInlineSnapshot(`50`);
expect(auditResults.length).toMatchInlineSnapshot(`48`);

expect(notApplicableAudits.length).toMatchInlineSnapshot(`7`);
expect(notApplicableAudits.map(audit => audit.id)).not.toContain('server-response-time');
Expand Down Expand Up @@ -172,9 +172,9 @@ describe('Fraggle Rock API', () => {
if (!result) throw new Error('Lighthouse failed to produce a result');

const {auditResults, erroredAudits, notApplicableAudits} = getAuditsBreakdown(result.lhr);
expect(auditResults.length).toMatchInlineSnapshot(`50`);
expect(auditResults.length).toMatchInlineSnapshot(`48`);

expect(notApplicableAudits.length).toMatchInlineSnapshot(`22`);
expect(notApplicableAudits.length).toMatchInlineSnapshot(`21`);
expect(notApplicableAudits.map(audit => audit.id)).toContain('server-response-time');

// TODO(FR-COMPAT): Reduce this number by handling the error, making N/A, or removing timespan support.
Expand Down

0 comments on commit ce87060

Please sign in to comment.