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 devtools log from tests #16050

Merged
merged 1 commit into from
Jun 10, 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
20 changes: 18 additions & 2 deletions core/lib/lantern/page-dependency-graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -827,7 +827,7 @@ class PageDependencyGraph {
/**
* @param {LH.Trace} trace
* @param {LH.Artifacts.TraceEngineResult} traceEngineResult
* @param {LH.Artifacts.URL} URL
* @param {LH.Artifacts.URL=} URL
*/
static async createGraphFromTrace(trace, traceEngineResult, URL) {
const mainThreadEvents = this._collectMainThreadEvents(trace, traceEngineResult);
Expand Down Expand Up @@ -918,8 +918,24 @@ class PageDependencyGraph {
// above.
lanternRequests.sort((a, b) => a.rendererStartTime - b.rendererStartTime);

// URL defines the initial request that the Lantern graph starts at (the root node) and the
// main document request. These are equal if there are no redirects.
Copy link
Collaborator Author

@connorjclark connorjclark Jun 7, 2024

Choose a reason for hiding this comment

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

will eventually figure out how to derive these two urls from the trace and remove URL as a param.

right now the fallback code here is not smart enough to detect client redirects (b/c that is not represented in our network model), so it is up to the caller to pass in the right urls

if (!URL) {
URL = {
requestedUrl: lanternRequests[0].url,
mainDocumentUrl: '',
finalDisplayedUrl: '',
};

let request = lanternRequests[0];
while (request.redirectDestination) {
request = request.redirectDestination;
}
URL.mainDocumentUrl = request.url;
}

const graph = PageDependencyGraph.createGraph(mainThreadEvents, lanternRequests, URL);
return {graph, records: lanternRequests};
return {graph, requests: lanternRequests};
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@ import {readJson} from '../../../test-utils.js';
import {getComputationDataFromFixture} from './metric-test-utils.js';

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

describe('Metrics: Lantern FCP', () => {
it('should compute predicted value', async () => {
const data = await getComputationDataFromFixture({trace, devtoolsLog});
const data = await getComputationDataFromFixture({trace});
const result = await FirstContentfulPaint.compute(data);

expect({
Expand All @@ -30,7 +29,7 @@ describe('Metrics: Lantern FCP', () => {
});

it('should handle negative request networkEndTime', async () => {
const data = await getComputationDataFromFixture({trace, devtoolsLog});
const data = await getComputationDataFromFixture({trace});
data.graph.request.networkEndTime = -1;
const result = await FirstContentfulPaint.compute(data);

Expand Down
5 changes: 1 addition & 4 deletions core/test/lib/lantern/metrics/interactive-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,11 @@ import {getComputationDataFromFixture} from './metric-test-utils.js';
import {readJson} from '../../../test-utils.js';

const trace = readJson('../../../fixtures/artifacts/progressive-app/trace.json', import.meta);
const devtoolsLog = readJson('../../../fixtures/artifacts/progressive-app/devtoolslog.json', import.meta);
const iframeTrace = readJson('../../../fixtures/artifacts/iframe/trace.json', import.meta);
const iframeDevtoolsLog = readJson('../../../fixtures/artifacts/iframe/devtoolslog.json', import.meta);

describe('Metrics: Lantern TTI', () => {
it('should compute predicted value', async () => {
const data = await getComputationDataFromFixture({trace, devtoolsLog});
const data = await getComputationDataFromFixture({trace});
const result = await Interactive.compute(data, {
lcpResult: await LargestContentfulPaint.compute(data, {
fcpResult: await FirstContentfulPaint.compute(data),
Expand All @@ -40,7 +38,6 @@ describe('Metrics: Lantern TTI', () => {
it('should compute predicted value on iframes with substantial layout', async () => {
const data = await getComputationDataFromFixture({
trace: iframeTrace,
devtoolsLog: iframeDevtoolsLog,
});
const result = await Interactive.compute(data, {
lcpResult: await LargestContentfulPaint.compute(data, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@ import {getComputationDataFromFixture} from './metric-test-utils.js';
import {readJson} from '../../../test-utils.js';

const trace = readJson('../../../fixtures/artifacts/paul/trace.json', import.meta);
const devtoolsLog = readJson('../../../fixtures/artifacts/paul/devtoolslog.json', import.meta);

describe('Metrics: Lantern LCP', () => {
it('should compute predicted value', async () => {
const data = await getComputationDataFromFixture({trace, devtoolsLog});
const data = await getComputationDataFromFixture({trace});
const result = await LargestContentfulPaint.compute(data, {
fcpResult: await FirstContentfulPaint.compute(data),
});
Expand Down
10 changes: 4 additions & 6 deletions core/test/lib/lantern/metrics/metric-test-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,24 @@ import {PageDependencyGraph} from '../../../../lib/lantern/page-dependency-graph
import {NetworkAnalyzer} from '../../../../lib/lantern/simulator/network-analyzer.js';
import {Simulator} from '../../../../lib/lantern/simulator/simulator.js';
import * as Lantern from '../../../../lib/lantern/types/lantern.js';
import {getURLArtifactFromDevtoolsLog} from '../../../test-utils.js';

/** @typedef {Lantern.NetworkRequest<import('@paulirish/trace_engine/models/trace/types/TraceEvents.js').SyntheticNetworkRequest>} NetworkRequest */

// TODO(15841): remove usage of Lighthouse code to create test data

/**
* @param {{trace: LH.Trace, devtoolsLog: LH.DevtoolsLog, settings?: LH.Config.Settings, URL?: LH.Artifacts.URL}} opts
* @param {{trace: LH.Trace, settings?: LH.Config.Settings, URL?: LH.Artifacts.URL}} opts
*/
async function getComputationDataFromFixture({trace, devtoolsLog, settings, URL}) {
async function getComputationDataFromFixture({trace, settings, URL}) {
settings = settings ?? /** @type {LH.Config.Settings} */({});
if (!settings.throttlingMethod) settings.throttlingMethod = 'simulate';
if (!URL) URL = getURLArtifactFromDevtoolsLog(devtoolsLog);

const context = {settings, computedCache: new Map()};
const traceEngineResult = await TraceEngineResult.request({trace}, context);
const {graph, records} =
const {graph, requests} =
await PageDependencyGraph.createGraphFromTrace(trace, traceEngineResult, URL);
const processedNavigation = createProcessedNavigation(traceEngineResult);
const networkAnalysis = NetworkAnalyzer.analyze(records);
const networkAnalysis = NetworkAnalyzer.analyze(requests);
const simulator = Simulator.createSimulator({...settings, networkAnalysis});

return {simulator, graph, processedNavigation};
Expand Down
5 changes: 2 additions & 3 deletions core/test/lib/lantern/metrics/speed-index-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,13 @@ 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 devtoolsLog = readJson('../../../fixtures/artifacts/progressive-app/devtoolslog.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, devtoolsLog});
const data = await getComputationDataFromFixture({trace});
const result = await SpeedIndex.compute(data, {
fcpResult: await FirstContentfulPaint.compute(data),
speedline: await Speedline.request(trace, context),
Expand All @@ -42,7 +41,7 @@ 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, devtoolsLog, settings});
const data = await getComputationDataFromFixture({trace, settings});
const result = await SpeedIndex.compute(data, {
fcpResult: await FirstContentfulPaint.compute(data),
speedline: await Speedline.request(trace, context),
Expand Down
Loading