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

core(test): add generatable iframe trace #15995

Merged
merged 3 commits into from
May 14, 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: 9 additions & 11 deletions core/test/computed/page-dependency-graph-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,22 @@ import {PageDependencyGraph} from '../../computed/page-dependency-graph.js';
import {BaseNode} from '../../lib/lantern/base-node.js';
import {getURLArtifactFromDevtoolsLog, readJson} from '../test-utils.js';

const sampleTrace = readJson('../fixtures/traces/iframe-m79.trace.json', import.meta);
const sampleDevtoolsLog = readJson('../fixtures/traces/iframe-m79.devtoolslog.json', import.meta);
const sampleTrace = readJson('../fixtures/artifacts/iframe/trace.json', import.meta);
const sampleDevtoolsLog = readJson('../fixtures/artifacts/iframe/devtoolslog.json', import.meta);

describe('PageDependencyGraph computed artifact', () => {
describe('#compute_', () => {
it('should compute the dependency graph', () => {
it('should compute the dependency graph', async () => {
const context = {computedCache: new Map()};
return PageDependencyGraph.request({
const output = await PageDependencyGraph.request({
trace: sampleTrace,
devtoolsLog: sampleDevtoolsLog,
URL: getURLArtifactFromDevtoolsLog(sampleDevtoolsLog),
}, context).then(output => {
assert.ok(output instanceof BaseNode, 'did not return a graph');

const dependents = output.getDependents();
const nodeWithNestedDependents = dependents.find(node => node.getDependents().length);
assert.ok(nodeWithNestedDependents, 'did not link initiators');
});
}, context);
assert.ok(output instanceof BaseNode, 'did not return a graph');
const dependents = output.getDependents();
const nodeWithNestedDependents = dependents.find(node => node.getDependents().length);
assert.ok(nodeWithNestedDependents, 'did not link initiators');
});
});
});
60 changes: 60 additions & 0 deletions core/test/fixtures/artifacts/iframe/devtoolslog.json

Large diffs are not rendered by default.

45 changes: 45 additions & 0 deletions core/test/fixtures/artifacts/iframe/regenerate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/**
* @license
* Copyright 2024 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/

import {startFlow} from '../../../../index.js';
import {updateTestFixture} from '../update-test-fixture.js';

/**
* @param {import('puppeteer').Page} page
* @param {number} port
*/
async function runUserFlow(page, port) {
const flow = await startFlow(page, {
flags: {
throttlingMethod: 'provided',
},
});

await flow.navigate(`http://localhost:${port}/perf/frame-metrics.html`);

return flow;
}

/**
* @param {LH.Artifacts} artifacts
*/
function verify(artifacts) {
const {traceEvents} = artifacts.Trace;

if (!traceEvents.find(e =>
e.name === 'LayoutInvalidationTracking' && e.args.data.nodeName.startsWith('IFRAME '))) {
throw new Error('no layout invalidation found inside iframe');
}
}

await updateTestFixture({
name: 'iframe',
about: 'Page with an iframe performing a lot of layout',
saveTrace: true,
saveDevtoolsLog: true,
runUserFlow,
verify,
});
6,993 changes: 6,993 additions & 0 deletions core/test/fixtures/artifacts/iframe/trace.json

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion core/test/fixtures/artifacts/update-test-fixture.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

// https://docs.google.com/spreadsheets/d/1AaYzpzWnpXQ4JB5IZzOkTO9Zf5Sm0I8dsp7MhBgthMg/edit?usp=sharing

import fs from 'fs';

import * as puppeteer from 'puppeteer';
import {getChromePath} from 'chrome-launcher';

Expand Down Expand Up @@ -34,7 +36,9 @@ export async function updateTestFixture(collectMeta) {
});
const server = new Server(0);
const dir = `${LH_ROOT}/core/test/fixtures/artifacts/${collectMeta.name}`;
server.baseDir = `${dir}/page`;
if (fs.existsSync(`${dir}/page`)) {
server.baseDir = `${dir}/page`;
}
await server.listen(0, 'localhost');
const port = server.getPort();

Expand Down
66 changes: 0 additions & 66 deletions core/test/fixtures/traces/iframe-m79.devtoolslog.json

This file was deleted.

263 changes: 0 additions & 263 deletions core/test/fixtures/traces/iframe-m79.trace.json

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ Object {

exports[`Metrics: Lantern TTI should compute predicted value on iframes with substantial layout 1`] = `
Object {
"optimistic": 6207,
"pessimistic": 6242,
"timing": 6226,
"optimistic": 2372,
"pessimistic": 2386,
"timing": 2379,
}
`;
4 changes: 2 additions & 2 deletions core/test/lib/lantern/metrics/interactive-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import {readJson} from '../../../test-utils.js';

const trace = readJson('../../../fixtures/traces/progressive-app-m60.json', import.meta);
const devtoolsLog = readJson('../../../fixtures/traces/progressive-app-m60.devtools.log.json', import.meta);
const iframeTrace = readJson('../../../fixtures/traces/iframe-m79.trace.json', import.meta);
const iframeDevtoolsLog = readJson('../../../fixtures/traces/iframe-m79.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 () => {
Expand Down
Loading