Skip to content

Commit

Permalink
tests(lantern): remove devtools log from tests
Browse files Browse the repository at this point in the history
  • Loading branch information
connorjclark committed Jun 7, 2024
1 parent a4bd8b7 commit 7b9f4c5
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 20 deletions.
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 @@ -880,7 +880,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 @@ -971,8 +971,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.
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
5 changes: 2 additions & 3 deletions core/test/lib/lantern/metrics/first-contentful-paint-test.js
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

0 comments on commit 7b9f4c5

Please sign in to comment.