diff --git a/core/audits/dobetterweb/doctype.js b/core/audits/dobetterweb/doctype.js index 6421808f12cf..fab965f11239 100644 --- a/core/audits/dobetterweb/doctype.js +++ b/core/audits/dobetterweb/doctype.js @@ -67,10 +67,11 @@ class Doctype extends Audit { const doctypeSystemId = artifacts.Doctype.systemId; const compatMode = artifacts.Doctype.documentCompatMode; + const trace = artifacts.traces?.[Audit.DEFAULT_PASS]; + /** @type {LH.Crdp.Audits.QuirksModeIssueDetails[]} */ let quirksModeIssues = []; - if (artifacts.traces && artifacts.InspectorIssues) { - const trace = artifacts.traces[Audit.DEFAULT_PASS]; + if (trace && artifacts.InspectorIssues) { const processedTrace = await ProcessedTrace.request(trace, context); const mainFrameId = processedTrace.mainFrameInfo.frameId; quirksModeIssues = diff --git a/core/test/audits/dobetterweb/doctype-test.js b/core/test/audits/dobetterweb/doctype-test.js index de2dfc07f10a..1da64f07f919 100644 --- a/core/test/audits/dobetterweb/doctype-test.js +++ b/core/test/audits/dobetterweb/doctype-test.js @@ -21,6 +21,7 @@ describe('DOBETTERWEB: doctype audit', () => { it('fails when document does not contain a doctype', async () => { const auditResult = await runAudit({ Doctype: null, + traces: {}, }); assert.equal(auditResult.score, 0); expect(auditResult.explanation).toBeDisplayString('Document must contain a doctype'); @@ -35,6 +36,7 @@ describe('DOBETTERWEB: doctype audit', () => { systemId: '', documentCompatMode: 'BackCompat', }, + traces: {}, }); assert.equal(auditResult.score, 0); expect(auditResult.explanation) @@ -85,6 +87,7 @@ describe('DOBETTERWEB: doctype audit', () => { systemId: '', documentCompatMode: 'BackCompat', }, + traces: {}, }); assert.equal(auditResult.score, 0); expect(auditResult.explanation).toBeDisplayString( @@ -99,6 +102,7 @@ describe('DOBETTERWEB: doctype audit', () => { systemId: '', documentCompatMode: 'BackCompat', }, + traces: {}, }); assert.equal(auditResult.score, 0); expect(auditResult.explanation).toBeDisplayString('Expected publicId to be an empty string'); @@ -112,6 +116,7 @@ describe('DOBETTERWEB: doctype audit', () => { systemId: '189655', documentCompatMode: 'BackCompat', }, + traces: {}, }); assert.equal(auditResult.score, 0); expect(auditResult.explanation).toBeDisplayString('Expected systemId to be an empty string'); @@ -125,6 +130,7 @@ describe('DOBETTERWEB: doctype audit', () => { systemId: '', documentCompatMode: 'CSS1Compat', }, + traces: {}, }); assert.equal(auditResult.score, 1); }); @@ -138,6 +144,7 @@ describe('DOBETTERWEB: doctype audit', () => { systemId: 'http://www.w3.org/TR/html4/loose.dtd', documentCompatMode: 'CSS1Compat', }, + traces: {}, }); assert.equal(auditResult.score, 1); });