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 usage of computed PageDependencyGraph #16063

Merged
merged 1 commit 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
8 changes: 7 additions & 1 deletion core/test/lib/lantern/metrics/metric-test-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import * as TraceEngine from '@paulirish/trace_engine';
import {NetworkAnalyzer} from '../../../../lib/lantern/simulator/network-analyzer.js';
import {Simulator} from '../../../../lib/lantern/simulator/simulator.js';
import * as TraceEngineComputationData from '../../../../lib/lantern/trace-engine-computation-data.js';
import {polyfillDOMRect} from '../../../../lib/polyfill-dom-rect.js';

polyfillDOMRect();
Copy link
Member

Choose a reason for hiding this comment

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

What's the purpose of this? Why wasn't it necessary before?

Copy link
Collaborator Author

@connorjclark connorjclark Jun 11, 2024

Choose a reason for hiding this comment

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

trace engines uses browser globals

before something was importing computed trace engine artifact which calls this

this thing shouldn't last long will get removed inside trace engine migration


/**
* @param {TraceEngine.Types.TraceEvents.TraceEventData[]} traceEvents
Expand Down Expand Up @@ -39,4 +42,7 @@ async function getComputationDataFromFixture({trace, settings, URL}) {
};
}

export {getComputationDataFromFixture};
export {
runTraceEngine,
getComputationDataFromFixture,
};
20 changes: 15 additions & 5 deletions core/test/lib/lantern/simulator/simulator-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,32 @@

import assert from 'assert/strict';

import * as Lantern from '../../../../lib/lantern/metric.js';
import {NetworkNode} from '../../../../lib/lantern/network-node.js';
import {CPUNode} from '../../../../lib/lantern/cpu-node.js';
import {Simulator} from '../../../../lib/lantern/simulator/simulator.js';
import {DNSCache} from '../../../../lib/lantern/simulator/dns-cache.js';
import {PageDependencyGraph} from '../../../../computed/page-dependency-graph.js';
import {getURLArtifactFromDevtoolsLog, readJson} from '../../../test-utils.js';
import {NetworkRequest} from '../../../../lib/network-request.js';
import * as TraceEngineComputationData from '../../../../lib/lantern/trace-engine-computation-data.js';
import {runTraceEngine} from '../metrics/metric-test-utils.js';

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

let nextRequestId = 1;
let nextTid = 1;

/**
* @param {Lantern.Trace} trace
* @param {Lantern.Simulation.URL} URL
*/
async function createGraph(trace, URL) {
const traceEngineData = await runTraceEngine(trace.traceEvents);
const requests = TraceEngineComputationData.createNetworkRequests(trace, traceEngineData);
return TraceEngineComputationData.createGraph(requests, trace, traceEngineData, URL);
}

function request(opts) {
const scheme = opts.scheme || 'http';
const url = `${scheme}://example.com`;
Expand Down Expand Up @@ -386,16 +398,14 @@ describe('DependencyGraph/Simulator', () => {
const URL = getURLArtifactFromDevtoolsLog(devtoolsLog);

it('should compute a timeInMs', async () => {
const computedCache = new Map();
const graph = await PageDependencyGraph.request({trace, devtoolsLog, URL}, {computedCache});
const graph = await createGraph(trace, URL);
const simulator = new Simulator({serverResponseTimeByOrigin});
const result = simulator.simulate(graph);
expect(result.timeInMs).toBeGreaterThan(100);
});

it('should sort the task event times', async () => {
const computedCache = new Map();
const graph = await PageDependencyGraph.request({trace, devtoolsLog, URL}, {computedCache});
const graph = await createGraph(trace, URL);
const simulator = new Simulator({serverResponseTimeByOrigin});
const result = simulator.simulate(graph);
const nodeTimings = Array.from(result.nodeTimings.entries());
Expand Down
Loading