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 squoosh trace #15997

Merged
merged 9 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from 7 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
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.23332411101386594,
"cumulativeLayoutShiftMainFrame": 0.23332411101386594,
"firstContentfulPaint": 1059,
"cumulativeLayoutShift": 0,
"cumulativeLayoutShiftMainFrame": 0,
"firstContentfulPaint": 2294,
"firstContentfulPaintAllFrames": undefined,
"firstContentfulPaintAllFramesTs": undefined,
"firstContentfulPaintTs": undefined,
"firstMeaningfulPaint": 1059,
"firstMeaningfulPaint": 2764,
"firstMeaningfulPaintTs": undefined,
"interactive": 3149,
"interactive": 4607,
"interactiveTs": undefined,
"largestContentfulPaint": 1524,
"largestContentfulPaint": 2764,
"largestContentfulPaintAllFrames": undefined,
"largestContentfulPaintAllFramesTs": undefined,
"largestContentfulPaintTs": undefined,
"lcpLoadEnd": undefined,
"lcpLoadStart": undefined,
"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,
"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,
"observedNavigationStart": 0,
"observedNavigationStartTs": 343577184048,
"observedSpeedIndex": 261,
"observedSpeedIndexTs": 343577445114,
"observedNavigationStartTs": 713037023064,
"observedSpeedIndex": 1393,
"observedSpeedIndexTs": 713038416494,
"observedTimeOrigin": 0,
"observedTimeOriginTs": 343577184048,
"observedTraceEnd": 3479,
"observedTraceEndTs": 343580662857,
"speedIndex": 1059,
"observedTimeOriginTs": 713037023064,
"observedTraceEnd": 7416,
"observedTraceEndTs": 713044439102,
"speedIndex": 3172,
"speedIndexTs": undefined,
"timeToFirstByte": 638,
"timeToFirstByte": 611,
"timeToFirstByteTs": undefined,
"totalBlockingTime": 84,
"totalBlockingTime": 1205,
}
`;

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": 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,
"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,
"roughEstimateOfLCPLoadEnd": undefined,
"roughEstimateOfLCPLoadStart": undefined,
"roughEstimateOfSI": 1059,
"roughEstimateOfTTFB": 638,
"roughEstimateOfTTI": 3149,
"roughEstimateOfSI": 3172,
"roughEstimateOfTTFB": 611,
"roughEstimateOfTTI": 4607,
}
`;
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/artifacts/paul/trace.json', import.meta);
const devtoolsLog = readJson('../../fixtures/artifacts/paul/devtoolslog.json', import.meta);
const trace = readJson('../../fixtures/traces/lcp-m78.json', import.meta);
const devtoolsLog = readJson('../../fixtures/traces/lcp-m78.devtools.log.json', import.meta);
connorjclark marked this conversation as resolved.
Show resolved Hide resolved

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, 160);
assert.equal(result.numericValue, 0);
});

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(`1220`);
expect(result.numericValue).toMatchInlineSnapshot(`440`);

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(`13580`);
expect(result.numericValue).toMatchInlineSnapshot(`5790`);
});

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(1400);
expect(result.details.overallSavingsMs).toEqual(2120);
});

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(40);
expect(result.details.overallSavingsMs).toEqual(30);
});

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/artifacts/paul/trace.json', import.meta);
const lcpDevtoolsLog = readJson('../fixtures/artifacts/paul/devtoolslog.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 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
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/artifacts/paul/trace.json', import.meta);
const acceptableDevToolsLog = readJson('../fixtures/artifacts/paul/devtoolslog.json', import.meta);
const acceptableTrace = readJson('../fixtures/traces/lcp-m78.json', import.meta);
const acceptableDevToolsLog = readJson('../fixtures/traces/lcp-m78.devtools.log.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('3,150 ms');
expect(output.displayValue).toBeDisplayString('4,610 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
2 changes: 1 addition & 1 deletion core/test/computed/main-resource-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe('MainResource computed artifact', () => {
});
});

it('thows when main resource can\'t be found', () => {
it('throws when main resource can\'t be found', () => {
const networkRecords = [
{url: 'https://example.com', resourceType: 'Script'},
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

exports[`Metrics: FCP should compute a simulated value 1`] = `
Object {
"optimistic": 1337,
"pessimistic": 1337,
"timing": 1337,
"optimistic": 1033,
"optimisticNodeTimings": 4,
"pessimistic": 1033,
"pessimisticNodeTimings": 4,
"timing": 1033,
}
`;
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

exports[`Metrics: FMP should compute a simulated value 1`] = `
Object {
"optimistic": 1469,
"pessimistic": 1613,
"timing": 1541,
"optimistic": 1033,
"optimisticNodeTimings": 4,
"pessimistic": 1069,
"pessimisticNodeTimings": 5,
"timing": 1051,
}
`;
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

exports[`Metrics: Max Potential FID should compute a simulated value 1`] = `
Object {
"optimistic": 396,
"pessimistic": 396,
"timing": 396,
"optimistic": 48,
"pessimistic": 48,
"timing": 48,
}
`;
2 changes: 1 addition & 1 deletion core/test/computed/metrics/cumulative-layout-shift-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {readJson} from '../../test-utils.js';
const jumpyClsTrace = readJson('../../fixtures/traces/jumpy-cls-m90.json', import.meta);
const oldMetricsTrace = readJson('../../fixtures/traces/frame-metrics-m89.json', import.meta);
const allFramesMetricsTrace = readJson('../../fixtures/traces/frame-metrics-m90.json', import.meta);
const preClsTrace = readJson('../../fixtures/traces/progressive-app-m60.json', import.meta);
const preClsTrace = readJson('../../fixtures/artifacts/progressive-app/trace.json', import.meta);
connorjclark marked this conversation as resolved.
Show resolved Hide resolved

const childFrameId = 'CAF4634127666E186C9C8B35627DBF0B';

Expand Down
24 changes: 16 additions & 8 deletions core/test/computed/metrics/first-contentful-paint-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import assert from 'assert/strict';
import {FirstContentfulPaint} from '../../../computed/metrics/first-contentful-paint.js'; // eslint-disable-line max-len
import {getURLArtifactFromDevtoolsLog, 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 trace = readJson('../../fixtures/artifacts/progressive-app/trace.json', import.meta);
const devtoolsLog = readJson('../../fixtures/artifacts/progressive-app/devtoolslog.json', import.meta);

const URL = getURLArtifactFromDevtoolsLog(devtoolsLog);

Expand All @@ -28,9 +28,9 @@ describe('Metrics: FCP', () => {
timing: Math.round(result.timing),
optimistic: Math.round(result.optimisticEstimate.timeInMs),
pessimistic: Math.round(result.pessimisticEstimate.timeInMs),
optimisticNodeTimings: result.optimisticEstimate.nodeTimings.size,
pessimisticNodeTimings: result.pessimisticEstimate.nodeTimings.size,
}).toMatchSnapshot();
assert.equal(result.optimisticEstimate.nodeTimings.size, 3);
assert.equal(result.pessimisticEstimate.nodeTimings.size, 3);
assert.ok(result.optimisticGraph, 'should have created optimistic graph');
assert.ok(result.pessimisticGraph, 'should have created pessimistic graph');
});
Expand All @@ -41,8 +41,12 @@ describe('Metrics: FCP', () => {
const result = await FirstContentfulPaint.request({trace, devtoolsLog, gatherContext, settings},
context);

assert.equal(Math.round(result.timing), 499);
assert.equal(result.timestamp, 225414670885);
await expect(result).toMatchInlineSnapshot(`
Object {
"timestamp": 350560322851,
"timing": 167.323,
}
`);
});

it('should compute an observed value (mobile)', async () => {
Expand All @@ -51,7 +55,11 @@ describe('Metrics: FCP', () => {
const result = await FirstContentfulPaint.request(
{gatherContext, trace, devtoolsLog, settings}, context);

assert.equal(Math.round(result.timing), 499);
assert.equal(result.timestamp, 225414670885);
await expect(result).toMatchInlineSnapshot(`
Object {
"timestamp": 350560322851,
"timing": 167.323,
}
`);
});
});
24 changes: 16 additions & 8 deletions core/test/computed/metrics/first-meaningful-paint-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import assert from 'assert/strict';
import {FirstMeaningfulPaint} from '../../../computed/metrics/first-meaningful-paint.js';
import {getURLArtifactFromDevtoolsLog, readJson} from '../../test-utils.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 pwaTrace = readJson('../../fixtures/artifacts/progressive-app/trace.json', import.meta);
const pwaDevtoolsLog = readJson('../../fixtures/artifacts/progressive-app/devtoolslog.json', import.meta);
const badNavStartTrace = readJson('../../fixtures/traces/bad-nav-start-ts.json', import.meta);
const lateTracingStartedTrace = readJson('../../fixtures/traces/tracingstarted-after-navstart.json', import.meta);
const preactTrace = readJson('../../fixtures/traces/preactjs.com_ts_of_undefined.json', import.meta);
Expand Down Expand Up @@ -51,9 +51,9 @@ describe('Metrics: FMP', () => {
timing: Math.round(result.timing),
optimistic: Math.round(result.optimisticEstimate.timeInMs),
pessimistic: Math.round(result.pessimisticEstimate.timeInMs),
optimisticNodeTimings: result.optimisticEstimate.nodeTimings.size,
pessimisticNodeTimings: result.pessimisticEstimate.nodeTimings.size,
}).toMatchSnapshot();
assert.equal(result.optimisticEstimate.nodeTimings.size, 6);
assert.equal(result.pessimisticEstimate.nodeTimings.size, 9);
assert.ok(result.optimisticGraph, 'should have created optimistic graph');
assert.ok(result.pessimisticGraph, 'should have created pessimistic graph');
});
Expand All @@ -64,8 +64,12 @@ describe('Metrics: FMP', () => {
const result = await FirstMeaningfulPaint.request({trace, devtoolsLog, gatherContext, settings},
context);

assert.equal(Math.round(result.timing), 783);
assert.equal(result.timestamp, 225414955343);
await expect(result).toMatchInlineSnapshot(`
Object {
"timestamp": 350560359679,
"timing": 204.151,
}
`);
});

it('should compute an observed value (mobile)', async () => {
Expand All @@ -74,8 +78,12 @@ describe('Metrics: FMP', () => {
const result = await FirstMeaningfulPaint.request({trace, devtoolsLog, gatherContext, settings},
context);

assert.equal(Math.round(result.timing), 783);
assert.equal(result.timestamp, 225414955343);
await expect(result).toMatchInlineSnapshot(`
Object {
"timestamp": 350560359679,
"timing": 204.151,
}
`);
});

it('handles cases when there was a tracingStartedInPage after navStart', async () => {
Expand Down
Loading
Loading