From 8cb664d5a1578a3a1ea394c4bee642118c5ad1a9 Mon Sep 17 00:00:00 2001 From: Patrick Hulce Date: Fri, 17 Nov 2017 12:50:19 -0800 Subject: [PATCH] core(speed-index): only compute perceptual speed index --- lighthouse-core/audits/speed-index-metric.js | 4 +--- lighthouse-core/gather/computed/speedline.js | 1 + .../test/audits/speed-index-metric-test.js | 23 +++++++++++++++---- .../test/gather/computed/speedline-test.js | 11 +++++---- package.json | 2 +- yarn.lock | 10 ++++---- 6 files changed, 33 insertions(+), 18 deletions(-) diff --git a/lighthouse-core/audits/speed-index-metric.js b/lighthouse-core/audits/speed-index-metric.js index f74aff1b3319..200164556990 100644 --- a/lighthouse-core/audits/speed-index-metric.js +++ b/lighthouse-core/audits/speed-index-metric.js @@ -43,7 +43,7 @@ class SpeedIndexMetric extends Audit { throw new Error('Trace unable to find visual progress frames.'); } - if (speedline.speedIndex === 0) { + if (speedline.perceptualSpeedIndex === 0) { throw new Error('Error in Speedline calculating Speed Index (speedIndex of 0).'); } @@ -71,14 +71,12 @@ class SpeedIndexMetric extends Audit { firstVisualChange: speedline.first, visuallyReady: visuallyReadyInMs, visuallyComplete: speedline.complete, - speedIndex: speedline.speedIndex, perceptualSpeedIndex: speedline.perceptualSpeedIndex, }, timestamps: { firstVisualChange: (speedline.first + speedline.beginning) * 1000, visuallyReady: (visuallyReadyInMs + speedline.beginning) * 1000, visuallyComplete: (speedline.complete + speedline.beginning) * 1000, - speedIndex: (speedline.speedIndex + speedline.beginning) * 1000, perceptualSpeedIndex: (speedline.perceptualSpeedIndex + speedline.beginning) * 1000, }, frames: speedline.frames.map(frame => { diff --git a/lighthouse-core/gather/computed/speedline.js b/lighthouse-core/gather/computed/speedline.js index 1abe5d2f1abc..2361e29ee504 100644 --- a/lighthouse-core/gather/computed/speedline.js +++ b/lighthouse-core/gather/computed/speedline.js @@ -29,6 +29,7 @@ class Speedline extends ComputedArtifact { return speedline(traceEvents, { timeOrigin: navStart, fastMode: true, + include: 'perceptualSpeedIndex', }); }); } diff --git a/lighthouse-core/test/audits/speed-index-metric-test.js b/lighthouse-core/test/audits/speed-index-metric-test.js index 6df33831c07b..0ee996950028 100644 --- a/lighthouse-core/test/audits/speed-index-metric-test.js +++ b/lighthouse-core/test/audits/speed-index-metric-test.js @@ -9,6 +9,8 @@ const Audit = require('../../audits/speed-index-metric.js'); const assert = require('assert'); +const pwaTrace = require('../fixtures/traces/progressive-app.json'); +const Runner = require('../../runner.js'); const emptyTraceStub = { traces: { @@ -34,6 +36,21 @@ describe('Performance: speed-index-metric audit', () => { }; } + it('works on a real trace', () => { + const artifacts = Object.assign(Runner.instantiateComputedArtifacts(), { + traces: {defaultPass: {traceEvents: pwaTrace}}, + }); + + return Audit.audit(artifacts).then(result => { + assert.equal(result.score, 100); + assert.equal(result.rawValue, 609); + assert.equal(Math.round(result.extendedInfo.value.timings.firstVisualChange), 475); + assert.equal(Math.round(result.extendedInfo.value.timings.visuallyReady), 700); + assert.equal(Math.round(result.extendedInfo.value.timings.visuallyComplete), 1105); + assert.equal(Math.round(result.extendedInfo.value.timings.perceptualSpeedIndex), 609); + }); + }); + it('throws an error if no frames', () => { const artifacts = mockArtifactsWithSpeedlineResult({frames: []}); return Audit.audit(artifacts).then( @@ -44,7 +61,7 @@ describe('Performance: speed-index-metric audit', () => { it('throws an error if speed index of 0', () => { const SpeedlineResult = { frames: [frame(), frame(), frame()], - speedIndex: 0, + perceptualSpeedIndex: 0, }; const artifacts = mockArtifactsWithSpeedlineResult(SpeedlineResult); @@ -53,12 +70,11 @@ describe('Performance: speed-index-metric audit', () => { _ => assert.ok(true)); }); - it('scores speed index of 831 as 100', () => { + it('scores speed index of 845 as 100', () => { const SpeedlineResult = { frames: [frame(), frame(), frame()], first: 630, complete: 930, - speedIndex: 831, perceptualSpeedIndex: 845, }; const artifacts = mockArtifactsWithSpeedlineResult(SpeedlineResult); @@ -67,7 +83,6 @@ describe('Performance: speed-index-metric audit', () => { assert.equal(response.rawValue, 845); assert.equal(response.extendedInfo.value.timings.firstVisualChange, 630); assert.equal(response.extendedInfo.value.timings.visuallyComplete, 930); - assert.equal(response.extendedInfo.value.timings.speedIndex, 831); assert.equal(response.extendedInfo.value.timings.perceptualSpeedIndex, 845); }); }); diff --git a/lighthouse-core/test/gather/computed/speedline-test.js b/lighthouse-core/test/gather/computed/speedline-test.js index 887e792ea926..0e05ca874ea9 100644 --- a/lighthouse-core/test/gather/computed/speedline-test.js +++ b/lighthouse-core/test/gather/computed/speedline-test.js @@ -29,16 +29,17 @@ describe('Speedline gatherer', () => { }); }); - it('measures the pwa.rocks example with speed index of 577', () => { + it('measures the pwa.rocks example', () => { return computedArtifacts.requestSpeedline({traceEvents: pwaTrace}).then(speedline => { - return assert.equal(Math.floor(speedline.speedIndex), 561); + assert.equal(speedline.speedIndex, undefined); + assert.equal(Math.floor(speedline.perceptualSpeedIndex), 609); }); }); it('measures SI of 3 frame trace (blank @1s, content @2s, more content @3s)', () => { return computedArtifacts.requestSpeedline(threeFrameTrace).then(speedline => { - assert.equal(Math.floor(speedline.speedIndex), 2040); - return assert.equal(Math.floor(speedline.perceptualSpeedIndex), 2030); + assert.equal(speedline.speedIndex, undefined); + assert.equal(Math.floor(speedline.perceptualSpeedIndex), 2030); }); }); @@ -59,7 +60,7 @@ describe('Speedline gatherer', () => { assert.ok(Date.now() - start < 50, 'Quick results come from the cache'); assert.equal(firstResult, speedline, 'Cache match matches'); - return assert.equal(Math.floor(speedline.speedIndex), 561); + return assert.equal(Math.floor(speedline.perceptualSpeedIndex), 609); }); }); diff --git a/package.json b/package.json index f10e82401086..26d0ab291825 100644 --- a/package.json +++ b/package.json @@ -88,7 +88,7 @@ "raven": "^2.2.1", "rimraf": "^2.6.1", "semver": "^5.3.0", - "speedline": "1.2.0", + "speedline": "1.3.0", "update-notifier": "^2.1.0", "whatwg-url": "4.0.0", "ws": "1.1.2", diff --git a/yarn.lock b/yarn.lock index 3dcdb2a527da..cf89b1cc9385 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2715,7 +2715,7 @@ loose-envify@^1.0.0: dependencies: js-tokens "^1.0.1" -loud-rejection@^1.0.0, loud-rejection@^1.3.0: +loud-rejection@^1.0.0, loud-rejection@^1.6.0: version "1.6.0" resolved "https://registry.yarnpkg.com/loud-rejection/-/loud-rejection-1.6.0.tgz#5b46f80147edee578870f086d04821cf998e551f" dependencies: @@ -3694,14 +3694,14 @@ spdx-license-ids@^1.0.2: version "1.2.2" resolved "https://registry.yarnpkg.com/spdx-license-ids/-/spdx-license-ids-1.2.2.tgz#c9df7a3424594ade6bd11900d596696dc06bac57" -speedline@1.2.0: - version "1.2.0" - resolved "https://registry.yarnpkg.com/speedline/-/speedline-1.2.0.tgz#f5828dcf8e9b96a9f6c1da8ab298538820c6668d" +speedline@1.3.0: + version "1.3.0" + resolved "https://registry.yarnpkg.com/speedline/-/speedline-1.3.0.tgz#201c458ca7aba2ac847fe5860c1a92966aaed3a9" dependencies: babar "0.0.3" image-ssim "^0.2.0" jpeg-js "^0.1.2" - loud-rejection "^1.3.0" + loud-rejection "^1.6.0" meow "^3.7.0" split2@^2.0.0: