Skip to content

Commit

Permalink
Refactor the browsertime marker tests
Browse files Browse the repository at this point in the history
  • Loading branch information
canova committed Jan 6, 2023
1 parent 4ce0d46 commit 7b58cc0
Showing 1 changed file with 41 additions and 14 deletions.
55 changes: 41 additions & 14 deletions src/test/unit/process-profile.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -666,18 +666,13 @@ describe('profile meta processing', function () {
describe('visualMetrics processing', function () {
function checkVisualMetricsForThread(
thread: Thread,
expectedMetricMarkers?: Array<{|
metrics: Array<{|
name: string,
hasProgressMarker: boolean,
changeMarkerLength: number,
|}>
) {
const metrics = expectedMetricMarkers ?? [
{ name: 'Visual', changeMarkerLength: 7 },
{ name: 'ContentfulSpeedIndex', changeMarkerLength: 6 },
{ name: 'PerceptualSpeedIndex', changeMarkerLength: 6 },
];

for (const { name, changeMarkerLength } of metrics) {
for (const { name, hasProgressMarker, changeMarkerLength } of metrics) {
// Check the visual metric progress markers.
const metricProgressMarkerIndex = thread.stringTable.indexForString(
`${name} Progress`
Expand All @@ -686,7 +681,7 @@ describe('visualMetrics processing', function () {
(name) => name === metricProgressMarkerIndex
);

if (changeMarkerLength > 0) {
if (hasProgressMarker) {
expect(metricProgressMarker).toBeTruthy();
} else {
expect(metricProgressMarker).toBeFalsy();
Expand Down Expand Up @@ -723,7 +718,19 @@ describe('visualMetrics processing', function () {
throw new Error('Could not find the parent process main thread.');
}

checkVisualMetricsForThread(parentProcessMainThread);
checkVisualMetricsForThread(parentProcessMainThread, [
{ name: 'Visual', hasProgressMarker: true, changeMarkerLength: 7 },
{
name: 'ContentfulSpeedIndex',
hasProgressMarker: true,
changeMarkerLength: 6,
},
{
name: 'PerceptualSpeedIndex',
hasProgressMarker: true,
changeMarkerLength: 6,
},
]);
});

it('adds markers to the tab process', function () {
Expand All @@ -745,7 +752,19 @@ describe('visualMetrics processing', function () {
throw new Error('Could not find the tab process main thread.');
}

checkVisualMetricsForThread(tabProcessMainThread);
checkVisualMetricsForThread(tabProcessMainThread, [
{ name: 'Visual', hasProgressMarker: true, changeMarkerLength: 7 },
{
name: 'ContentfulSpeedIndex',
hasProgressMarker: true,
changeMarkerLength: 6,
},
{
name: 'PerceptualSpeedIndex',
hasProgressMarker: true,
changeMarkerLength: 6,
},
]);
});

it('does not add markers to the parent process if metric timestamps are null', function () {
Expand Down Expand Up @@ -781,11 +800,19 @@ describe('visualMetrics processing', function () {
checkVisualMetricsForThread(parentProcessMainThread, [
// Instead of 7, we should have 0 markers for Visual because we made all
// the timestamps null.
{ name: 'Visual', changeMarkerLength: 0 },
{ name: 'Visual', hasProgressMarker: false, changeMarkerLength: 0 },
// Instead of 6, we should have 5 markers for ContentfulSpeedIndex.
{ name: 'ContentfulSpeedIndex', changeMarkerLength: 5 },
{
name: 'ContentfulSpeedIndex',
hasProgressMarker: true,
changeMarkerLength: 5,
},
// We didn't change the PerceptualSpeedIndexProgress, so we should have 6.
{ name: 'PerceptualSpeedIndex', changeMarkerLength: 6 },
{
name: 'PerceptualSpeedIndex',
hasProgressMarker: true,
changeMarkerLength: 6,
},
]);
});
});

0 comments on commit 7b58cc0

Please sign in to comment.