Skip to content

Commit

Permalink
core(test): add generatable trace for paint metrics (#15994)
Browse files Browse the repository at this point in the history
  • Loading branch information
connorjclark authored May 14, 2024
1 parent e5038e4 commit 171ebdf
Show file tree
Hide file tree
Showing 17 changed files with 26,661 additions and 116 deletions.
76 changes: 38 additions & 38 deletions core/test/audits/__snapshots__/metrics-test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -116,58 +116,58 @@ Object {

exports[`Performance: metrics evaluates valid input (with lcp) correctly 1`] = `
Object {
"cumulativeLayoutShift": 0,
"cumulativeLayoutShiftMainFrame": 0,
"firstContentfulPaint": 2294,
"cumulativeLayoutShift": 0.23332411101386594,
"cumulativeLayoutShiftMainFrame": 0.23332411101386594,
"firstContentfulPaint": 1059,
"firstContentfulPaintAllFrames": undefined,
"firstContentfulPaintAllFramesTs": undefined,
"firstContentfulPaintTs": undefined,
"firstMeaningfulPaint": 2764,
"firstMeaningfulPaint": 1059,
"firstMeaningfulPaintTs": undefined,
"interactive": 4607,
"interactive": 3149,
"interactiveTs": undefined,
"largestContentfulPaint": 2764,
"largestContentfulPaint": 1524,
"largestContentfulPaintAllFrames": undefined,
"largestContentfulPaintAllFramesTs": undefined,
"largestContentfulPaintTs": undefined,
"lcpLoadEnd": undefined,
"lcpLoadStart": undefined,
"maxPotentialFID": 1336,
"observedCumulativeLayoutShift": 0,
"observedCumulativeLayoutShiftMainFrame": 0,
"observedDomContentLoaded": 1513,
"observedDomContentLoadedTs": 713038536140,
"observedFirstContentfulPaint": 1122,
"observedFirstContentfulPaintAllFrames": 1122,
"observedFirstContentfulPaintAllFramesTs": 713038144775,
"observedFirstContentfulPaintTs": 713038144775,
"observedFirstMeaningfulPaint": 1122,
"observedFirstMeaningfulPaintTs": 713038144775,
"observedFirstPaint": 1122,
"observedFirstPaintTs": 713038144775,
"observedFirstVisualChange": 1105,
"observedFirstVisualChangeTs": 713038128064,
"observedLargestContentfulPaint": 1122,
"observedLargestContentfulPaintAllFrames": 1122,
"observedLargestContentfulPaintAllFramesTs": 713038144775,
"observedLargestContentfulPaintTs": 713038144775,
"observedLastVisualChange": 1722,
"observedLastVisualChangeTs": 713038745064,
"observedLoad": 2159,
"observedLoadTs": 713039182071,
"maxPotentialFID": 163,
"observedCumulativeLayoutShift": 0.23332411101386594,
"observedCumulativeLayoutShiftMainFrame": 0.23332411101386594,
"observedDomContentLoaded": 331,
"observedDomContentLoadedTs": 343577515428,
"observedFirstContentfulPaint": 292,
"observedFirstContentfulPaintAllFrames": 292,
"observedFirstContentfulPaintAllFramesTs": 343577475882,
"observedFirstContentfulPaintTs": 343577475882,
"observedFirstMeaningfulPaint": 292,
"observedFirstMeaningfulPaintTs": 343577475882,
"observedFirstPaint": 292,
"observedFirstPaintTs": 343577475882,
"observedFirstVisualChange": 207,
"observedFirstVisualChangeTs": 343577391048,
"observedLargestContentfulPaint": 292,
"observedLargestContentfulPaintAllFrames": 292,
"observedLargestContentfulPaintAllFramesTs": 343577475882,
"observedLargestContentfulPaintTs": 343577475882,
"observedLastVisualChange": 391,
"observedLastVisualChangeTs": 343577575048,
"observedLoad": 436,
"observedLoadTs": 343577620312,
"observedNavigationStart": 0,
"observedNavigationStartTs": 713037023064,
"observedSpeedIndex": 1393,
"observedSpeedIndexTs": 713038416494,
"observedNavigationStartTs": 343577184048,
"observedSpeedIndex": 261,
"observedSpeedIndexTs": 343577445114,
"observedTimeOrigin": 0,
"observedTimeOriginTs": 713037023064,
"observedTraceEnd": 7416,
"observedTraceEndTs": 713044439102,
"speedIndex": 3172,
"observedTimeOriginTs": 343577184048,
"observedTraceEnd": 3479,
"observedTraceEndTs": 343580662857,
"speedIndex": 1059,
"speedIndexTs": undefined,
"timeToFirstByte": 611,
"timeToFirstByte": 638,
"timeToFirstByteTs": undefined,
"totalBlockingTime": 1205,
"totalBlockingTime": 84,
}
`;

Expand Down
32 changes: 16 additions & 16 deletions core/test/audits/__snapshots__/predictive-perf-test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@

exports[`Performance: predictive performance audit should compute the predicted values 1`] = `
Object {
"optimisticFCP": 2294,
"optimisticFMP": 2294,
"optimisticLCP": 2294,
"optimisticSI": 1393,
"optimisticTTI": 3795,
"pessimisticFCP": 2294,
"pessimisticFMP": 3233,
"pessimisticLCP": 3233,
"pessimisticSI": 3052,
"pessimisticTTI": 5272,
"roughEstimateOfFCP": 2294,
"roughEstimateOfFMP": 2764,
"roughEstimateOfLCP": 2764,
"optimisticFCP": 1059,
"optimisticFMP": 1059,
"optimisticLCP": 1445,
"optimisticSI": 261,
"optimisticTTI": 2132,
"pessimisticFCP": 1059,
"pessimisticFMP": 1059,
"pessimisticLCP": 1603,
"pessimisticSI": 1109,
"pessimisticTTI": 3981,
"roughEstimateOfFCP": 1059,
"roughEstimateOfFMP": 1059,
"roughEstimateOfLCP": 1524,
"roughEstimateOfLCPLoadEnd": undefined,
"roughEstimateOfLCPLoadStart": undefined,
"roughEstimateOfSI": 3172,
"roughEstimateOfTTFB": 611,
"roughEstimateOfTTI": 4607,
"roughEstimateOfSI": 1059,
"roughEstimateOfTTFB": 638,
"roughEstimateOfTTI": 3149,
}
`;
14 changes: 7 additions & 7 deletions core/test/audits/byte-efficiency/byte-efficiency-audit-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import {networkRecordsToDevtoolsLog} from '../../network-records-to-devtools-log
import {createTestTrace, rootFrame} from '../../create-test-trace.js';
import {defaultSettings} from '../../../config/constants.js';

const trace = readJson('../../fixtures/traces/lcp-m78.json', import.meta);
const devtoolsLog = readJson('../../fixtures/traces/lcp-m78.devtools.log.json', import.meta);
const trace = readJson('../../fixtures/artifacts/paul/trace.json', import.meta);
const devtoolsLog = readJson('../../fixtures/artifacts/paul/devtoolslog.json', import.meta);

describe('Byte efficiency base audit', () => {
let simulator;
Expand Down Expand Up @@ -228,7 +228,7 @@ describe('Byte efficiency base audit', () => {
{computedCache: new Map()}
);

assert.equal(result.numericValue, 0);
assert.equal(result.numericValue, 160);
});

it('should create load simulator with the specified settings', async () => {
Expand All @@ -255,13 +255,13 @@ describe('Byte efficiency base audit', () => {
let result = await MockAudit.audit(artifacts, {settings, computedCache});
// expect modest savings
expect(result.numericValue).toBeLessThan(5000);
expect(result.numericValue).toMatchInlineSnapshot(`440`);
expect(result.numericValue).toMatchInlineSnapshot(`1220`);

settings = {throttlingMethod: 'simulate', throttling: ultraSlowThrottling};
result = await MockAudit.audit(artifacts, {settings, computedCache});
// expect lots of savings
expect(result.numericValue).not.toBeLessThan(5000);
expect(result.numericValue).toMatchInlineSnapshot(`5790`);
expect(result.numericValue).toMatchInlineSnapshot(`13580`);
});

it('should compute savings with throughput in timespan mode', async () => {
Expand All @@ -285,7 +285,7 @@ describe('Byte efficiency base audit', () => {
const modestThrottling = {rttMs: 150, throughputKbps: 1000, cpuSlowdownMultiplier: 2};
const settings = {throttlingMethod: 'simulate', throttling: modestThrottling};
const result = await MockAudit.audit(artifacts, {settings, computedCache});
expect(result.details.overallSavingsMs).toEqual(2120);
expect(result.details.overallSavingsMs).toEqual(1400);
});

it('should return n/a if no network records in timespan mode', async () => {
Expand Down Expand Up @@ -342,7 +342,7 @@ describe('Byte efficiency base audit', () => {
};
const settings = {throttlingMethod: 'devtools', throttling: modestThrottling};
const result = await MockAudit.audit(artifacts, {settings, computedCache});
expect(result.details.overallSavingsMs).toEqual(30);
expect(result.details.overallSavingsMs).toEqual(40);
});

describe('#scoreForWastedMs', () => {
Expand Down
4 changes: 2 additions & 2 deletions core/test/audits/metrics-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import {defaultSettings} from '../../config/constants.js';

const pwaTrace = readJson('../fixtures/traces/progressive-app-m60.json', import.meta);
const pwaDevtoolsLog = readJson('../fixtures/traces/progressive-app-m60.devtools.log.json', import.meta);
const lcpTrace = readJson('../fixtures/traces/lcp-m78.json', import.meta);
const lcpDevtoolsLog = readJson('../fixtures/traces/lcp-m78.devtools.log.json', import.meta);
const lcpTrace = readJson('../fixtures/artifacts/paul/trace.json', import.meta);
const lcpDevtoolsLog = readJson('../fixtures/artifacts/paul/devtoolslog.json', import.meta);
const lcpImageTrace = readJson('../fixtures/traces/amp-m86.trace.json', import.meta);
const lcpImageDevtoolsLog = readJson('../fixtures/traces/amp-m86.devtoolslog.json', import.meta);
const lcpAllFramesTrace = readJson('../fixtures/traces/frame-metrics-m89.json', import.meta);
Expand Down
4 changes: 2 additions & 2 deletions core/test/audits/network-requests-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ describe('Network requests audit', () => {

it('should report if records are from the main frame', async () => {
const records = [
{url: 'https://example.com/'},
{url: 'https://example.com/', frameId: 'main'},
{url: 'https://iframed.local/', frameId: '71D866EC199B90A2E0B2D9CF88DCBC4E'},
];

Expand All @@ -123,7 +123,7 @@ describe('Network requests audit', () => {

it('should not include main frame information outside of navigations', async () => {
const records = [
{url: 'https://example.com/'},
{url: 'https://example.com/', frameId: 'main'},
{url: 'https://iframed.local/', frameId: '71D866EC199B90A2E0B2D9CF88DCBC4E'},
];

Expand Down
6 changes: 3 additions & 3 deletions core/test/audits/predictive-perf-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import PredictivePerf from '../../audits/predictive-perf.js';
import {getURLArtifactFromDevtoolsLog, readJson} from '../test-utils.js';

const acceptableTrace = readJson('../fixtures/traces/lcp-m78.json', import.meta);
const acceptableDevToolsLog = readJson('../fixtures/traces/lcp-m78.devtools.log.json', import.meta);
const acceptableTrace = readJson('../fixtures/artifacts/paul/trace.json', import.meta);
const acceptableDevToolsLog = readJson('../fixtures/artifacts/paul/devtoolslog.json', import.meta);

describe('Performance: predictive performance audit', () => {
it('should compute the predicted values', async () => {
Expand All @@ -25,7 +25,7 @@ describe('Performance: predictive performance audit', () => {
const context = {computedCache: new Map(), settings: {locale: 'en'}};

const output = await PredictivePerf.audit(artifacts, context);
expect(output.displayValue).toBeDisplayString('4,610 ms');
expect(output.displayValue).toBeDisplayString('3,150 ms');
const metrics = output.details.items[0];
for (const [key, value] of Object.entries(metrics)) {
metrics[key] = value === undefined ? value : Math.round(value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import {readJson} from '../../test-utils.js';

const traceAllFrames = readJson('../../fixtures/traces/frame-metrics-m89.json', import.meta);
const devtoolsLogAllFrames = readJson('../../fixtures/traces/frame-metrics-m89.devtools.log.json', import.meta);
const traceMainFrame = readJson('../../fixtures/traces/lcp-m78.json', import.meta);
const devtoolsLogMainFrame = readJson('../../fixtures/traces/lcp-m78.devtools.log.json', import.meta);
const traceMainFrame = readJson('../../fixtures/artifacts/paul/trace.json', import.meta);
const devtoolsLogMainFrame = readJson('../../fixtures/artifacts/paul/devtoolslog.json', import.meta);
const invalidTrace = readJson('../../fixtures/traces/progressive-app-m60.json', import.meta);
const invalidDevtoolsLog = readJson('../../fixtures/traces/progressive-app-m60.devtools.log.json', import.meta);

Expand Down Expand Up @@ -54,9 +54,11 @@ describe('Metrics: LCP from all frames', () => {
{gatherContext, trace: traceMainFrame, devtoolsLog: devtoolsLogMainFrame, settings},
context
);
await expect(result).toEqual({
timestamp: 713038144775,
timing: 1121.711,
});
await expect(result).toMatchInlineSnapshot(`
Object {
"timestamp": 343577475882,
"timing": 291.834,
}
`);
});
});
20 changes: 11 additions & 9 deletions core/test/computed/metrics/largest-contentful-paint-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@
* SPDX-License-Identifier: Apache-2.0
*/

import assert from 'assert/strict';

import {LargestContentfulPaint} from '../../../computed/metrics/largest-contentful-paint.js';
import {getURLArtifactFromDevtoolsLog, readJson} from '../../test-utils.js';

const trace = readJson('../../fixtures/traces/lcp-m78.json', import.meta);
const devtoolsLog = readJson('../../fixtures/traces/lcp-m78.devtools.log.json', import.meta);
const trace = readJson('../../fixtures/artifacts/paul/trace.json', import.meta);
const devtoolsLog = readJson('../../fixtures/artifacts/paul/devtoolslog.json', import.meta);
const invalidTrace = readJson('../../fixtures/traces/progressive-app-m60.json', import.meta);
const invalidDevtoolsLog = readJson('../../fixtures/traces/progressive-app-m60.devtools.log.json', import.meta);

Expand All @@ -30,9 +28,9 @@ describe('Metrics: LCP', () => {
pessimistic: Math.round(result.pessimisticEstimate.timeInMs)}).
toMatchInlineSnapshot(`
Object {
"optimistic": 2294,
"pessimistic": 3233,
"timing": 2764,
"optimistic": 1445,
"pessimistic": 1603,
"timing": 1524,
}
`);
});
Expand All @@ -44,8 +42,12 @@ Object {
const result = await LargestContentfulPaint.request({trace, devtoolsLog, gatherContext,
settings, URL}, context);

assert.equal(Math.round(result.timing), 1122);
assert.equal(result.timestamp, 713038144775);
await expect(result).toMatchInlineSnapshot(`
Object {
"timestamp": 343577475882,
"timing": 291.834,
}
`);
});

['provided', 'simulate'].forEach(throttlingMethod => {
Expand Down
Loading

0 comments on commit 171ebdf

Please sign in to comment.