Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit bfdf00d

Browse files
committed
tests(lantern): remove devtools log from tests
1 parent 7115c63 commit bfdf00d

File tree

6 files changed

+28
-20
lines changed

6 files changed

+28
-20
lines changed

core/lib/lantern/page-dependency-graph.js

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -880,7 +880,7 @@ class PageDependencyGraph {
880880
/**
881881
* @param {LH.Trace} trace
882882
* @param {LH.Artifacts.TraceEngineResult} traceEngineResult
883-
* @param {LH.Artifacts.URL} URL
883+
* @param {LH.Artifacts.URL=} URL
884884
*/
885885
static async createGraphFromTrace(trace, traceEngineResult, URL) {
886886
const mainThreadEvents = this._collectMainThreadEvents(trace, traceEngineResult);
@@ -971,8 +971,24 @@ class PageDependencyGraph {
971971
// above.
972972
lanternRequests.sort((a, b) => a.rendererStartTime - b.rendererStartTime);
973973

974+
// URL defines the initial request that the Lantern graph starts at (the root node) and the
975+
// main document request. These are equal if there are no redirects.
976+
if (!URL) {
977+
URL = {
978+
requestedUrl: lanternRequests[0].url,
979+
mainDocumentUrl: '',
980+
finalDisplayedUrl: '',
981+
};
982+
983+
let request = lanternRequests[0];
984+
while (request.redirectDestination) {
985+
request = request.redirectDestination;
986+
}
987+
URL.mainDocumentUrl = request.url;
988+
}
989+
974990
const graph = PageDependencyGraph.createGraph(mainThreadEvents, lanternRequests, URL);
975-
return {graph, records: lanternRequests};
991+
return {graph, requests: lanternRequests};
976992
}
977993

978994
/**

core/test/lib/lantern/metrics/first-contentful-paint-test.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,10 @@ import {readJson} from '../../../test-utils.js';
1111
import {getComputationDataFromFixture} from './metric-test-utils.js';
1212

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

1615
describe('Metrics: Lantern FCP', () => {
1716
it('should compute predicted value', async () => {
18-
const data = await getComputationDataFromFixture({trace, devtoolsLog});
17+
const data = await getComputationDataFromFixture({trace});
1918
const result = await FirstContentfulPaint.compute(data);
2019

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

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

core/test/lib/lantern/metrics/interactive-test.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,11 @@ import {getComputationDataFromFixture} from './metric-test-utils.js';
1313
import {readJson} from '../../../test-utils.js';
1414

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

2018
describe('Metrics: Lantern TTI', () => {
2119
it('should compute predicted value', async () => {
22-
const data = await getComputationDataFromFixture({trace, devtoolsLog});
20+
const data = await getComputationDataFromFixture({trace});
2321
const result = await Interactive.compute(data, {
2422
lcpResult: await LargestContentfulPaint.compute(data, {
2523
fcpResult: await FirstContentfulPaint.compute(data),
@@ -40,7 +38,6 @@ describe('Metrics: Lantern TTI', () => {
4038
it('should compute predicted value on iframes with substantial layout', async () => {
4139
const data = await getComputationDataFromFixture({
4240
trace: iframeTrace,
43-
devtoolsLog: iframeDevtoolsLog,
4441
});
4542
const result = await Interactive.compute(data, {
4643
lcpResult: await LargestContentfulPaint.compute(data, {

core/test/lib/lantern/metrics/lantern-largest-contentful-paint-test.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,10 @@ import {getComputationDataFromFixture} from './metric-test-utils.js';
1212
import {readJson} from '../../../test-utils.js';
1313

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

1716
describe('Metrics: Lantern LCP', () => {
1817
it('should compute predicted value', async () => {
19-
const data = await getComputationDataFromFixture({trace, devtoolsLog});
18+
const data = await getComputationDataFromFixture({trace});
2019
const result = await LargestContentfulPaint.compute(data, {
2120
fcpResult: await FirstContentfulPaint.compute(data),
2221
});

core/test/lib/lantern/metrics/metric-test-utils.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,24 @@ import {PageDependencyGraph} from '../../../../lib/lantern/page-dependency-graph
1010
import {NetworkAnalyzer} from '../../../../lib/lantern/simulator/network-analyzer.js';
1111
import {Simulator} from '../../../../lib/lantern/simulator/simulator.js';
1212
import * as Lantern from '../../../../lib/lantern/types/lantern.js';
13-
import {getURLArtifactFromDevtoolsLog} from '../../../test-utils.js';
1413

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

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

1918
/**
20-
* @param {{trace: LH.Trace, devtoolsLog: LH.DevtoolsLog, settings?: LH.Config.Settings, URL?: LH.Artifacts.URL}} opts
19+
* @param {{trace: LH.Trace, settings?: LH.Config.Settings, URL?: LH.Artifacts.URL}} opts
2120
*/
22-
async function getComputationDataFromFixture({trace, devtoolsLog, settings, URL}) {
21+
async function getComputationDataFromFixture({trace, settings, URL}) {
2322
settings = settings ?? /** @type {LH.Config.Settings} */({});
2423
if (!settings.throttlingMethod) settings.throttlingMethod = 'simulate';
25-
if (!URL) URL = getURLArtifactFromDevtoolsLog(devtoolsLog);
2624

2725
const context = {settings, computedCache: new Map()};
2826
const traceEngineResult = await TraceEngineResult.request({trace}, context);
29-
const {graph, records} =
27+
const {graph, requests} =
3028
await PageDependencyGraph.createGraphFromTrace(trace, traceEngineResult, URL);
3129
const processedNavigation = createProcessedNavigation(traceEngineResult);
32-
const networkAnalysis = NetworkAnalyzer.analyze(records);
30+
const networkAnalysis = NetworkAnalyzer.analyze(requests);
3331
const simulator = Simulator.createSimulator({...settings, networkAnalysis});
3432

3533
return {simulator, graph, processedNavigation};

core/test/lib/lantern/metrics/speed-index-test.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,13 @@ import {getComputationDataFromFixture} from './metric-test-utils.js';
1313
import {Speedline} from '../../../../computed/speedline.js';
1414

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

1817
const defaultThrottling = constants.throttling.mobileSlow4G;
1918

2019
describe('Metrics: Lantern Speed Index', () => {
2120
it('should compute predicted value', async () => {
2221
const context = {computedCache: new Map()};
23-
const data = await getComputationDataFromFixture({trace, devtoolsLog});
22+
const data = await getComputationDataFromFixture({trace});
2423
const result = await SpeedIndex.compute(data, {
2524
fcpResult: await FirstContentfulPaint.compute(data),
2625
speedline: await Speedline.request(trace, context),
@@ -42,7 +41,7 @@ Object {
4241
it('should compute predicted value for different settings', async () => {
4342
const settings = {throttlingMethod: 'simulate', throttling: {...defaultThrottling, rttMs: 300}};
4443
const context = {computedCache: new Map()};
45-
const data = await getComputationDataFromFixture({trace, devtoolsLog, settings});
44+
const data = await getComputationDataFromFixture({trace, settings});
4645
const result = await SpeedIndex.compute(data, {
4746
fcpResult: await FirstContentfulPaint.compute(data),
4847
speedline: await Speedline.request(trace, context),

0 commit comments

Comments
 (0)