diff --git a/lighthouse-core/audits/byte-efficiency/byte-efficiency-audit.js b/lighthouse-core/audits/byte-efficiency/byte-efficiency-audit.js index 4c6e17abe53c..fb3bb3cdc002 100644 --- a/lighthouse-core/audits/byte-efficiency/byte-efficiency-audit.js +++ b/lighthouse-core/audits/byte-efficiency/byte-efficiency-audit.js @@ -206,6 +206,8 @@ class UnusedBytes extends Audit { */ static computeWastedMsWithThroughput(wastedBytes, simulator) { const bitsPerSecond = simulator.getOptions().throughput; + // https://github.com/GoogleChrome/lighthouse/pull/13323#issuecomment-962031709 + if (bitsPerSecond === 0) return 0; const wastedBits = wastedBytes * 8; const wastedMs = wastedBits / bitsPerSecond * 1000; return wastedMs; diff --git a/lighthouse-core/test/audits/byte-efficiency/byte-efficiency-audit-test.js b/lighthouse-core/test/audits/byte-efficiency/byte-efficiency-audit-test.js index e29629bd5561..c5353a002a0e 100644 --- a/lighthouse-core/test/audits/byte-efficiency/byte-efficiency-audit-test.js +++ b/lighthouse-core/test/audits/byte-efficiency/byte-efficiency-audit-test.js @@ -364,4 +364,33 @@ describe('Byte efficiency base audit', () => { score: 1, }); }); + + it('should handle 0 download throughput in timespan', async () => { + class MockAudit extends ByteEfficiencyAudit { + static audit_(artifacts, records) { + return { + items: records.map(record => ({url: record.url, wastedBytes: record.transferSize * 0.5})), + headings: [], + }; + } + } + + const artifacts = { + GatherContext: {gatherMode: 'timespan'}, + traces: {defaultPass: trace}, + devtoolsLogs: {defaultPass: devtoolsLog}, + }; + const computedCache = new Map(); + + const modestThrottling = { + rttMs: 150, + requestLatencyMs: 150, + throughputKbps: 1000, + cpuSlowdownMultiplier: 2, + downloadThroughputKbps: 0, + }; + const settings = {throttlingMethod: 'devtools', throttling: modestThrottling}; + const result = await MockAudit.audit(artifacts, {settings, computedCache}); + expect(result.details.overallSavingsMs).toBeCloseTo(0); + }); });