Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests(lantern): remove Speedline from Lantern unit test for now #16060

Merged
merged 2 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: what is the TODO here? Eventually move speedline inside the lantern library if we need it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

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
Loading