Skip to content

Commit

Permalink
tests(lantern): remove Speedline from Lantern unit test for now (#16060)
Browse files Browse the repository at this point in the history
  • Loading branch information
connorjclark committed Jun 11, 2024
1 parent 945351c commit d41c7c0
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 9 deletions.
2 changes: 1 addition & 1 deletion core/computed/metrics/lantern-speed-index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class LanternSpeedIndex extends SpeedIndex {
const speedline = await Speedline.request(data.trace, context);
const fcpResult = await LanternFirstContentfulPaint.request(data, context);
return this.computeMetricWithGraphs(data, context, {
speedline,
observedSpeedIndex: speedline.speedIndex,
fcpResult,
});
}
Expand Down
2 changes: 1 addition & 1 deletion core/lib/lantern/metric.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {RESOURCE_TYPES} from '../../lib/network-request.js';
* @property {LH.Artifacts.LanternMetric=} fcpResult
* @property {LH.Artifacts.LanternMetric=} lcpResult
* @property {LH.Artifacts.LanternMetric=} interactiveResult
* @property {{speedIndex: number}=} speedline
* @property {number=} observedSpeedIndex
*/

class Metric {
Expand Down
4 changes: 2 additions & 2 deletions core/lib/lantern/metrics/speed-index.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,11 @@ class SpeedIndex extends Metric {
*/
static getEstimateFromSimulation(simulationResult, extras) {
if (!extras.fcpResult) throw new Error('missing fcpResult');
if (!extras.speedline) throw new Error('missing speedline');
if (extras.observedSpeedIndex === undefined) throw new Error('missing observedSpeedIndex');

const fcpTimeInMs = extras.fcpResult.pessimisticEstimate.timeInMs;
const estimate = extras.optimistic
? extras.speedline.speedIndex
? extras.observedSpeedIndex
: SpeedIndex.computeLayoutBasedSpeedIndex(simulationResult.nodeTimings, fcpTimeInMs);
return {
timeInMs: estimate,
Expand Down
11 changes: 6 additions & 5 deletions core/test/lib/lantern/metrics/speed-index-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,20 @@ import {readJson} from '../../../test-utils.js';
import {SpeedIndex} from '../../../../lib/lantern/metrics/speed-index.js';
import {FirstContentfulPaint} from '../../../../lib/lantern/metrics/first-contentful-paint.js';
import {getComputationDataFromFixture} from './metric-test-utils.js';
import {Speedline} from '../../../../computed/speedline.js';

const trace = readJson('../../../fixtures/artifacts/progressive-app/trace.json', import.meta);

const defaultThrottling = constants.throttling.mobileSlow4G;

describe('Metrics: Lantern Speed Index', () => {
it('should compute predicted value', async () => {
const context = {computedCache: new Map()};
const data = await getComputationDataFromFixture({trace});
// TODO: observedSpeedIndex is from the Speedline library, and is used for optimistic
// mode. At the moment callers must pass the result into Lantern.
const observedSpeedIndex = 379.04474997520487;
const result = await SpeedIndex.compute(data, {
fcpResult: await FirstContentfulPaint.compute(data),
speedline: await Speedline.request(trace, context),
observedSpeedIndex,
});

expect({
Expand All @@ -40,11 +41,11 @@ Object {

it('should compute predicted value for different settings', async () => {
const settings = {throttlingMethod: 'simulate', throttling: {...defaultThrottling, rttMs: 300}};
const context = {computedCache: new Map()};
const data = await getComputationDataFromFixture({trace, settings});
const observedSpeedIndex = 379.04474997520487;
const result = await SpeedIndex.compute(data, {
fcpResult: await FirstContentfulPaint.compute(data),
speedline: await Speedline.request(trace, context),
observedSpeedIndex,
});

expect({
Expand Down

0 comments on commit d41c7c0

Please sign in to comment.