Skip to content

Commit

Permalink
core(test): add generatable squoosh trace (#15997)
Browse files Browse the repository at this point in the history
  • Loading branch information
connorjclark committed May 14, 2024
1 parent 74294b1 commit b6d3301
Show file tree
Hide file tree
Showing 22 changed files with 42,582 additions and 113 deletions.
2 changes: 1 addition & 1 deletion core/test/computed/main-resource-test.js
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
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,
}
`;
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,
}
`;
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,
}
`;
24 changes: 16 additions & 8 deletions core/test/computed/metrics/first-contentful-paint-test.js
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
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
12 changes: 7 additions & 5 deletions core/test/computed/metrics/max-potential-fid-test.js
Expand Up @@ -4,13 +4,11 @@
* SPDX-License-Identifier: Apache-2.0
*/

import assert from 'assert/strict';

import {MaxPotentialFID} from '../../../computed/metrics/max-potential-fid.js';
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 @@ -36,6 +34,10 @@ describe('Metrics: Max Potential FID', () => {
const result = await MaxPotentialFID.request({trace, devtoolsLog, gatherContext, settings, URL},
context);

assert.equal(Math.round(result.timing), 198);
await expect(result).toMatchInlineSnapshot(`
Object {
"timing": 18.22,
}
`);
});
});
37 changes: 21 additions & 16 deletions core/test/computed/metrics/speed-index-test.js
Expand Up @@ -4,13 +4,11 @@
* SPDX-License-Identifier: Apache-2.0
*/

import assert from 'assert/strict';

import {SpeedIndex} from '../../../computed/metrics/speed-index.js';
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 trace1msLayout = readJson('../../fixtures/traces/speedindex-1ms-layout-m84.trace.json', import.meta);
const devtoolsLog1msLayout = readJson('../../fixtures/traces/speedindex-1ms-layout-m84.devtoolslog.json', import.meta); // eslint-disable-line max-len

Expand All @@ -27,14 +25,13 @@ describe('Metrics: Speed Index', () => {
expect({
timing: Math.round(result.timing),
optimistic: Math.round(result.optimisticEstimate.timeInMs),
pessimistic: Math.round(result.pessimisticEstimate.timeInMs),
}).toMatchInlineSnapshot(`
Object {
"optimistic": 605,
"pessimistic": 1661,
"timing": 1511,
}
`);
pessimistic: Math.round(result.pessimisticEstimate.timeInMs)}).toMatchInlineSnapshot(`
Object {
"optimistic": 307,
"pessimistic": 1076,
"timing": 1033,
}
`);
});

it('should compute a simulated value on a trace on desktop with 1ms durations', async () => {
Expand Down Expand Up @@ -80,8 +77,12 @@ describe('Metrics: Speed Index', () => {
const result = await SpeedIndex.request({trace, devtoolsLog, gatherContext, settings, URL},
context);

assert.equal(result.timing, 605);
assert.equal(result.timestamp, 225414777015);
await expect(result).toMatchInlineSnapshot(`
Object {
"timestamp": 350560462528,
"timing": 307,
}
`);
});

it('should compute an observed value (mobile)', async () => {
Expand All @@ -91,7 +92,11 @@ describe('Metrics: Speed Index', () => {
const result = await SpeedIndex.request({trace, devtoolsLog, gatherContext, settings, URL},
context);

assert.equal(result.timing, 605);
assert.equal(result.timestamp, 225414777015);
await expect(result).toMatchInlineSnapshot(`
Object {
"timestamp": 350560462528,
"timing": 307,
}
`);
});
});
31 changes: 17 additions & 14 deletions core/test/computed/processed-trace-test.js
Expand Up @@ -7,15 +7,15 @@
import {ProcessedTrace} from '../../computed/processed-trace.js';
import {readJson} from '../test-utils.js';

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

describe('ProcessedTrace', () => {
it('computes the artifact', async () => {
const context = {computedCache: new Map()};
const processedTrace = await ProcessedTrace.request(pwaTrace, context);

expect(processedTrace.processEvents.length).toEqual(12865);
expect(processedTrace.mainThreadEvents.length).toEqual(7629);
expect(processedTrace.processEvents.length).toEqual(30050);
expect(processedTrace.mainThreadEvents.length).toEqual(14970);

delete processedTrace.processEvents;
delete processedTrace.mainThreadEvents;
Expand All @@ -25,29 +25,32 @@ describe('ProcessedTrace', () => {

expect(processedTrace).toMatchObject({
mainFrameInfo: {
frameId: '0x25a638821e30',
startingPid: 44277,
frameId: 'B252105E12E98AFD5BC5DCC4D6F4813F',
startingPid: 13956,
},
timeOriginEvt: {
args: {
frame: '0x25a638821e30',
frame: 'B252105E12E98AFD5BC5DCC4D6F4813F',
},
cat: 'blink.user_timing',
name: 'navigationStart',
ph: 'R',
pid: 44277,
tid: 775,
ts: 225414172015,
tts: 455539,
pid: 13958,
tid: 259,
ts: 350560155528,
tts: 34613,
},
frames: [],
frames: [{
id: 'B252105E12E98AFD5BC5DCC4D6F4813F',
url: 'https://squoosh.app/',
}],
timestamps: {
timeOrigin: 225414172015,
traceEnd: 225426711887,
timeOrigin: 350560155528,
traceEnd: 350562869197,
},
timings: {
timeOrigin: 0,
traceEnd: 12539.872,
traceEnd: 2713.669,
},
});
});
Expand Down

0 comments on commit b6d3301

Please sign in to comment.